[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Adding local variables to lua functions, called from C.
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 12 Mar 2004 12:10:23 -0300
>I'm calling a Lua function from C, and wish to set up some local variables
>for that function, pre-calling it.
I'm not sure what you mean here, but you can try using upvalues instead.
Consider this example
do
local a=10
local b=20
local c=30
function f()
print(a,b,c)
end
end
Then in C you can call lua_setupvalue on f to set a,b,c (or any one of
them individually). After that, call f. Try this:
lua_getglobal(L,"f");
lua_pushnumber(L,2004);
lua_setupvalue(L,1,2);
lua_call(L,0,0);
--lhf