[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: calling table:function from c/c++
- From: "pion1013" <pion@...>
- Date: Mon, 31 Mar 2003 19:33:32 -0000
Hi,
I wrote a short lua program like this:
-- test.lua
test = {}
function test:fn (num1, num2)
return num1 + num2
end
now, I wanted to call this function from c/c++,
lua_State *L = lua_open(0);
lua_baselibopen(L);
lua_dofile (L, "test.lua");
lua_getglobal(L, "test:fn");
lua_pushnumber(L, 100);
lua_pushnumber(L, 200);
lua_call(L, 2, 1);
printf("result : %d\n", (int)lua_tonumber(L, -1));
lua_close(L);
which doesn't work. The program complains about calling nil function.
My rough guess is that the function "test:fn" belongs to the
table "test", and not globally known. But, I don't know how to
correct it.
Can anyone help me, please?
Pion
p.s. I'm using Lua-4.0.1