I’m getting “attempt to call nil value” errors when I try to use the colon operator on libraries. Eg:
local a = {}
a:insert("something")
Is this a known deviation from Lua?
I’m getting “attempt to call nil value” errors when I try to use the colon operator on libraries. Eg:
local a = {}
a:insert("something")
Is this a known deviation from Lua?
The reason
local a = "hello"
print(a:sub(1, 2))
works is because in vanilla Lua strings have a metatable whose __index
field points to the string
library. For security reasons Roblox locks the string metatable, but if you do
print(getmetatable("").__index == string)
on say Lua: demo you will get true
in the output. Tables by default don’t have a metatable, so if you really want this then do
local a = setmetatable({ }, { __index = table })
Ah, thanks very much.
Lua is a very strange language to me. The Lua: demo is very useful, thanks.