[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Speed comparison
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 4 Jun 1999 11:41:02 -0300 (EST)
>From DASWorks1@aol.com Fri Jun 4 11:16:01 1999
>
>lhf wrote:
>
>>there's a game you can play with the set/getglobal tag methods and with
>>the callhook so that global variables seem local to a chunk.
>
>Would you elaborate on how this can be done? Thanks...
Use the call hook to see when a chunk starts and end.
A chunk starts when line==0. It ends when file=="(return)".
(Since line==0 when a chunk ends, you should test file first.)
See etc/trace.c in the distribution.
Now, when a chunk starts, set the setglobal and the getglobal tag methods
for nil to use a table to store values. Something similar is described in
the FAQ: 3.3 - How do I create read-only variables?. See also some code in
test/trace.lua.
When a chunk ends, simply restore the defaults set/getglobal tag methods.
All this can be written in Lua 3.2 (which includes ldeblib).
In Lua 3.1, you have to write the hook part in C.
--lhf