lua-users home
lua-l archive

Re: Environment variables

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


Szabolcs Szasz:
> I need to support a simple config file written
> consisting purely of
> variable = "value"
(snip)
> I thought of using a tagmethod for setglobal, but
> that did not seem to be allowed. Also, the globals
> table is of not much help now (I guess).
Globals table should be fine in Lua4 (it's Lua5 that has a new way of doing
things that may take a bit of thinking).
I would expect the following would work fine:
 function f(configfile)
 -- as locals these become immune to changing the global table.
 local dofile = dofile
 local globals = globals
 -- New empty global table (store old globals in glob).
 local glob = globals({}) 
 -- Load the new globals with the config data.
 dofile(configfile)
 -- Reset to the old globals, the new data is safe in glob.
 glob = globals(glob)
 -- Return the config data.
 return glob
 end
*cheers*
Peter Hill.

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