lua-users home
lua-l archive

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


Isn't there a simple 'includefile' method out there that, ala #include, just inserts the relevent text? It strikes me that this would do exactly what Thomas is looking for, without requiring poisoning of his global tables.
-G

At 09:23 PM 4/19/2002 +0200, you wrote:
> 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