lua-users home
lua-l archive

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


> On Sep 30, 2015, at 11:53 AM, Soni L. <fakedme@gmail.com> wrote:
> 
> 
>> It may be useless to YOU, but it’s very useful to others. We have several major applications which would be enormously hard to realize without it.
>> 
>> Example: You call a C API, passing it an argument (Lua value) which you want to later re-surface (as a passed argument) when a different C API calls a Lua function. We do this all the time in several of our apps.
>> 
>> Question: In C code, where do you store that argument so that you can later pass it back to Lua? Sure, if it’s a number or a string, you can allocate memory and store it on the C heap. What if its a table? Or a coroutine? Where does the C code store it, if not in the registry? (And no, you can’t put it in an upvalue.)
>> 
>> Declaring something as “useless” because you personally cannot see a use for it is saying “I can’t see a use for it so there isn’t one”, which seems to me somewhat arrogant.
>> 
>> —Tim
>> 
>> 
>> 
> The same way you'd do it in Lua: Your module table. Or the metatable.
> 

The C code isn't in a module, so that wont work. What metatable are you referring to?

As LHF noted, Lua is often used embedded, which means it’s driven by Lua code that wraps the Lua state(s) as it needs. Sometimes this code needs to manipulate Lua values and state not visible to Lua code. That’s what the registry is for, unless you can suggest a better alternative?

—Tim