[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: Peter Cawley <lua@...>
- Date: Tue, 31 Mar 2009 16:18:15 +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.