lua-users home
lua-l archive

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


> On Apr 20, 2015, at 2:11 PM, Jorge <xxopxe@gmail.com> wrote:
> 
> On 04/18/2015 02:45 PM, Hisham wrote:
>>>> I would doubt that using varargs as a Forth stack is the best approach.
>>>> What’s wrong with a Lua array (aka table)?
>>> 
>>> Lua arrays can't do nil, Lua stacks can.
>> 
>> If you're already writing a VM to a different language, you can just
>> map your Forth's nil to a non-nil Lua singleton.
> 
> I'm on the same camp: null-like values that have a meaning in your business logic are not Lua nil. Nil is a language thing, not "something". If your applications has a value that can be stored and is guaranteed to exist only once then is a singleton, something like
> 
> NULL = {}  --accesible globally
> 
> 
> Jorge
> 

For one of our projects, we used a light userdata with a NULL C pointer for this purpose:

lua_pushlightuserdata(L, NULL);
lua_setglobal(L, “NULL”);

This has the advantage (to my mind) of being pass-by-value and can also be persisted reasonably easily. Of course, it needs C code to create the initial value.

—Tim