lua-users home
lua-l archive

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


>I'm using Lua to replace a scripting language (which I'll call FOO) 

Perhaps FOO == awk ?

>My problem is that I can't have both.

Yes, you can, but it's not so simple.
Try this: define the index method for globals to return a special kind
of proxy table, one for which methods are defined to handle arithmetic and
indexing. When you create these proxy tables in the index method for the
global table, store the name of the variable. Later, when the value is used
as a number, the variable becomes an ordinary global variable with a number
value (you do this in the getglobal method for globals, and looking at the
metatable of the value to see whether it is a proxy table). Similarly when
the value is used as a table, but in this case it is easier because you
only have to use the index method for the proxy. Again, you can then "convert"
the proxy into a true value. Or you might keep both options (and then you'll
be cloning the behaviour of awk, which allows a=0 and a[0]=1 simultaneously).

Sorry for the long, text-only explanation, and no code...
Anyway, I hope it helps.
--lhf