lua-users home
lua-l archive

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


>From lua-l@tecgraf.puc-rio.br Sun Aug  8 05:37:28 1999
>From: Ken Rawlings <krawling@shooter.bluemarble.net>

>   BTW, Global variables that are set to nil have the same behavior --
>   setting  a global to nil removes that variable binding completely. Much
>   of Lua didn't make sense to me until I discovered this. In fact, it
>   still seems strange that a reference to a variable with a value of nil
>   and a reference to a variable that does not exist are equivalent.

Why strange? May be because you're thinking about languages with declarations.
What would you do with a variable with a value of nil that would be different
for a variable that did not "exist"?

A simple, but overlooked, technique is to wrap tables around values,
so that nil means "does not exist" (yet) and {nil} means value nil.
See the FAQ for examples of this technique.

>   BTW, on a slightly different subject -- has anyone ever written a
>   tutorial for writing simple Lua libraries? 

No, but it surely will be part of the book on Lua that Roberto is writting.
In the meantime, read lmathlib.c, which is the simplest library.
--lhf