1281 posts
Posted 22 March 2014 - 12:58 AM
After a few hours of debugging my own program, i've come to the conclusion that the __len metamethod defined in the
Lua wiki does not work.
Running the following code
test = setmetatable({},{__len = function(t) return "Invoked __len function on "..tostring(t) end})
return #test
In the online
lua demo returns as expected
"Invoked __len function on table blah blah"
However, executing the same piece of code on computercraft returns
0
Meaning the __len function isn't invoked at all.
Edited on 22 March 2014 - 07:21 AM
226 posts
Location
Earth
Posted 22 March 2014 - 03:43 AM
Just create a function called length…
I think this is only for lua 5.2… and CC is 5.1.
Easy to solve though…
7508 posts
Location
Australia
Posted 22 March 2014 - 03:48 AM
Just create a function called length…
not the point that was trying to be made,
__len is to add the support for the
# character
226 posts
Location
Earth
Posted 22 March 2014 - 08:12 AM
Just create a function called length…
not the point that was trying to be made,
__len is to add the support for the
# character
I know but (someone really needs to confirm this, im 99.627 percent sure..) in lua 5.1 you cant. Only 5.2.
1281 posts
Posted 22 March 2014 - 08:25 AM
I thought as much myself originally, but it's listed in the 5.1 manual
http://www.lua.org/manual/5.1/manual.html#2.8Edit: looking closer at it, it would seem it's only invoked on variables that are not tables or strings. How stupid…
Edited on 22 March 2014 - 07:27 AM
1522 posts
Location
The Netherlands
Posted 22 March 2014 - 03:28 PM
I thought as much myself originally, but it's listed in the 5.1 manual
http://www.lua.org/m...manual.html#2.8Edit: looking closer at it, it would seem it's only invoked on variables that are not tables or strings. How stupid…
in Lua 5.2 it is invoked on those iirc. It was a bummer for myself when a friend of mine discovered thi either
226 posts
Location
Earth
Posted 22 March 2014 - 05:05 PM
Yes, it is very unfortunate. The ability to override __len would be really nice…