[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Getting Lua functions from stack
- From: Antero Vipunen <antero@...>
- Date: Wed, 5 Nov 2003 20:52:56 +0600
Hello All,
Is there a way to get from and push to stack lua functions?
I mean smth like lua_tofunction, lua_pushfunction.
I want to do the following:
-- Test.c
LuaFunc *table[100];
.....
static int AddToTable(lua_State *L)
{
....
table[lua_tonumber(L,1)] = lua_tofunction(L,2);
....
}
static int CallFromTable(lua_State *L)
{
...
lua_pushfunction(table[lua_tonumber(L,1)]);
lua_call(L,0,0);
...
}
....
lua_State *L = lua_open();
....
lua_dofile(L,"test.lua");
....
-- test.lua
function TestF1()
print("This Is F1!");
end
function TestF2()
print("This Is F2!");
end
AddToTable(1,TestF1);
AddToTable(2,TestF2);
CallFromTable(2);
CallFromTable(1);
-- Output
This is T2!
This is T1!
--
Best regards,
Antero Vipunen