lua-users home
lua-l archive

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


Dear all,

I am new to Lua. But I read many documents about Lua in this few days 
and found out that Lua is a good script. ^^

I successfully read the value from a table in Lua to C++.. however I 
cannot figure out what I miss in manipulating a C++ struct in Lua...I 
have read many posting from this news group, but still not work fine. 
Pls help me out..

currently I am using Lua 4.0 since I think it will be more stable.

//In my C++
//global
struct Player {
	char* name;
	int IQ;
	int EQ;
};

Player* p_Player = NULL;

//main
int main(...
{
lua_State *lua_open();

p_Player = new Player;
p_Player->name = "Newbie";
p_Player->IQ = 100;
p_Player->EQ = 1000;

Script script;
script.Register("PrintNumber", Script_PrintNumber);
script.Register("PassNewbie", Script_PassPlayer);
	
script.DoFile("Test.lua");
}

//print number works fine... so I will not post the src here

//pass newbie is like the following
static int Script_PassPlayer(lua_State* state)
{
Script script(state);

int Ntag = script.NewTag();
	
script.PushUserTag((void*)p_Player, Ntag);
script.SetGlobal("h");
script.GetTable(1);

return 1;
}

//In Lua
PrintNumber(30 + 20)

PassPlayer()

PrintNumber(h.IQ)


Actually... I am not quite sure I understand about gettable and 
settable....... I will read some more doucments and manuel again. Pls 
help me ... thx

Newbie