
It seems like in computercraft setmetatable(new, meta) converts the __index from a table to a function in the returned new. Any idea why this is?
Posted 08 July 2013 - 05:28 PM

Posted 08 July 2013 - 07:09 PM
Posted 08 July 2013 - 07:13 PM
Posted 08 July 2013 - 07:28 PM
local nativesetmetatable = setmetatable
function setmetatable( _o, _t )
if _t and type(_t) == "table" then
local idx = rawget( _t, "__index" )
if idx and type( idx ) == "table" then
rawset( _t, "__index", function( t, k ) return idx[k] end )
end
local newidx = rawget( _t, "__newindex" )
if newidx and type( newidx ) == "table" then
rawset( _t, "__newindex", function( t, k, v ) newidx[k] = v end )
end
end
return nativesetmetatable( _o, _t )
end
I don't know why this is done, but there must be a reason why they added it.
Posted 09 July 2013 - 12:31 AM
Lyqyd, on 08 July 2013 - 07:09 PM, said:
function OBJDEF:encode(value, etc)
if type(self) ~= 'table' or self.__index ~= OBJDEF then
OBJDEF:onEncodeError("JSON:encode must be called in method format", etc)
end
The second condition fails in computercraft.json:encode(tabletoencode)But you could call it accidentally with
json.encode(tabletoencode)
Posted 09 July 2013 - 12:40 AM
Posted 09 July 2013 - 01:00 AM
0 members, 1 guests, 0 anonymous users