lua-users home
lua-l archive

RE: global

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


> Personnaly, I'd love to do this if I need only one function in a file,
> but with your proposal it's impossible :
>
> foo = {}
> do
> global in foo
> dofile("foo.lua")
> end
> bar = foo.bar
> foo = nil
this wouldn't work - global in foo is not effecting the execution of
dofile("foo.lua") (except that the variable "dofile" is looked up in foo,
where it isnt found - i guess you didnt mean to do this)
what you want is this: (this already works with lua 4.0)
foo = {}
do
 local t = globals(foo) -- use foo instead of the old globals table. store
old globals table in t
 t.dofile("foo.lua")
 t.globals(t)
end
bar = foo.bar
foo = nil
Cheers,
Peter

AltStyle によって変換されたページ (->オリジナル) /