lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Jul 24, 2013, at 1:09 PM, Leo Romanoff <romixlev@yahoo.com> wrote:

The only drawback I would expect is that I need an additional table access every time when I need to access a Lua object. Therefore I'm not sure about the "efficient" part of my requirement.
My original idea was to store real references to Lua objects somewhere inside the UD. Since Lua would not know where to find those pointers inside UD,  it would need to use the __trace method from a UD metatable.

The trouble with this approach is the contract between Lua and C regarding memory management becomes very complex, and any issues with any C code inevitably lead to nasty hard to find crashes in Lua. Python uses something akin to your request, and suffers badly as a result (the API is a horror to work with imho). The Lua stack model isn't perfect, but it provides a good level of protection while enabling pretty much any user scenario, though at a modest execution cost.

--Tim