lua-users home
lua-l archive

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


> On Sep 30, 2015, at 11:05 AM, Soni L. <fakedme@gmail.com> wrote:
> 
> 
> 
> On 30/09/15 03:04 PM, Sean Conner wrote:
>> It was thus said that the Great Soni L. once stated:
>>> 
>>> On 30/09/15 01:34 PM, Luiz Henrique de Figueiredo wrote:
>>>>> If Lua doesn't need a registry then neither does C.
>>>> That's not true. Lua is an embedded language and C code may need to
>>>> store things in a Lua state that Lua scripts cannot have access to
>>>> because of security. Not everything that can be done to Lua in C should
>>>> be exposed to Lua scripts.
>>>> 
>>> function f()
>>> local i = 3
>>> return function() print(i) end
>>> end
>>> 
>>> Does another script have access to i?
>>   Only if the debug module is available.  But then again, if the debug
>> module is available, so is the registry.
>> 
>>   -spc
>> 
>> 
> Precisely. The registry is useless.
> 
> -- 

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