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:34 PM, Tom Miles <> wrote:
> On Tue, Mar 31, 2009 at 4:15 PM, Tom Miles <Tom@creative-
>> 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.

Wow! That's, urm, creative :)

I'm not sure how it would fit into our framework, especially as I am planning an update to our system with a variable number of locals added by default, but it's food for thought!

If things are going to vary a lot, it might be easier to only pass in a single table parameter populated with the variables as key/value pairs.