lua-users home
lua-l archive

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

On Tue, Mar 31, 2009 at 4:15 PM, Tom Miles <> wrote:
> Urm, how to put this another way...
> When I create a state, I load an associated script file.  I want to add
> some variables into the state the script is running in that are only
> visible to that script.  I can add globals using lua_setglobal(L,
> "myvar"), or even lua_setfield(L, LUA_GLOBALSINDEX, "myvar"), but there
> doesn't seem to be an equivelant for locals.

Use a custom loader to prepend "local A,B,C,D,E = ...;" to the input
(where A through E are the names of the locals you want), then before
doing a pcall on the script, push the values of the locals onto the
stack and adjust the nargs value of the pcall.