[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: How do I add a "local" using the c api
- From: "Tom Miles" <Tom@...>
- Date: Tue, 31 Mar 2009 16:34:25 +0100
>
> On Tue, Mar 31, 2009 at 4:15 PM, Tom Miles <Tom@creative-
> assembly.co.uk> 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!