[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Adding local variables to lua functions, called from C.
- From: "Danilo Tuler" <tuler@...>
- Date: Fri, 12 Mar 2004 12:30:05 -0300
Dan,
I'm not sure what you mean either.
This may be a stupid question, but can't you pass a parameter? It behaves
like a local variable.
function f(a, b, c)
print(a, b, c)
end
lua_getglobal(L,"f");
lua_pushnumber(L, 1);
lua_pushnumber(L, 2);
lua_pushnumber(L, 3);
lua_call(L, 3, 0);
-- Danilo
> >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
>