[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "import"?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 2 Oct 2000 11:26:30 -0200 (EDT)
>> I should have put the extra requirement that I need this in 3.2.
>
>You can do something similar, but instead of changing the table of globals,
>you will have to copy all globals to a new table, and then erase all globals.
Or you can set up a "setglobal" tag method to redirect global definitions to
a table. Something like
function import(f)
local t={}
local g=settagmethod(tag(nil),"setglobal",function (n,o,v) %t[n]=v end)
dofile(f..".lua")
settagmethod(tag(nil),"setglobal",g)
return t
end
If your module use (=read) global variables defined in the module, then you
must also set up a "getglobal" tag method to read first from t and then fro
the real globals (with rawgetglobal).
--lhf