lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

I would like to ask how to do the parameter passing from Lua to C++ 
in a correct place. I did the following code by using Lua 4.0... 
please take a look!! ^^....

in the C++ constructor
m_player = player;
m_pluaStack = lua_open(0);
lua_register(m_pluaStack, "SetHP", testluafunc);

in the destructor
if (m_player != NULL)
	m_player = NULL;
lua_close(m_pluaStack);

in the function run
lua_pushuserdata(m_pluaStack, (void*)m_player);
lua_setglobal(m_pluaStack, "Player");
lua_pushcclosure(m_pluaStack, testluafunc, 1);
lua_dofile(m_pluaStack, "test.lua");

in the function testluafunc
int parameter = (int)lua_tonumber(L, 1);
lua_getglobal(L, "Player");
TestPlayer* t1 = (TestPlayer*)lua_touserdata(L, 2);
	t1->m_HP -= parameter;

in lua
SetHP(20)

Could someone point out what I did wrong?? thx very much!!



regard,
Teran