[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Metatables
- From: "James Hearn" <james.hearn@...>
- Date: Wed, 27 Feb 2002 18:18:03 -0600
> >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
If I understand, this is a way to "delay" deciding what the value of 'a' is
until it's used in an expression? I've done a similar thing in the past with
NebLUA. It worked pretty well within the scope of that project.
--James Hearn