[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: metatable indirection limit. Why?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 8 Mar 2012 21:47:46 -0300
> Doing an experiment on chaining metatables I came up with this test code:
>
> http://pastie.org/3551948
>
> the pattern is:
>
> Obj1 = { test = function() print("ok") end }
> Obj2 = {}
> setmetatable(Obj2, { __index = Obj1 })
> Obj3 = {}
> setmetatable(Obj3, { __index = Obj2 })
> Obj3.test()
>
> etc...
>
> Interestingly, both lua and luajit halt when the number of
> "indirections" is > 99, and I was wondering why.
Try this pattern:
Obj1 = { test = function() print("ok") end }
Obj2 = {}
setmetatable(Obj2, { __index = Obj1 })
setmetatable(Obj1, { __index = Obj2 })
-- Roberto