hum... ok, thanks a lot! I tried looking at toLua and LuaBind, but I didn't understood how they really work. Right now, I just moved my functions to Main.cpp. I know it's a bad idea, but at least it worked...
(...)
Ok, now I have another problem... Here's what happens: I have a function AddTerrain(...) being called from my lua script. the registered function is l_AddTerrain:
int l_AddTerrain(lua_State* luaVM) // int index,float maxspeed,float aceleration,float negaceleration,float aderence{ MessageBox (NULL,"start adding...","AKA",MB_OK); int index; float maxspeed; float aceleration; float negaceleration; float aderence; index = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1 ); maxspeed = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); aceleration = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); negaceleration = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); aderence = lua_tonumber(luaVM, 1); GameHold.MainTrack.AddTerrain(index, maxspeed, aceleration, negaceleration, aderence); //MessageBox (NULL,"What the hell?? I get an critical error if I take this message box out of here!!!","AKA",MB_OK);}
Now, if I run this function passing 4 or less parameters (ex. AddTerrain() or AddTerrain(7, 8) ) It will work out fine, but if there are more then 5, I will get my program shutdown by windows ("this program caused an ilegal operation and will be closed..."). The weird part is... if I add a MessageBox in the end of the function, everyting will work fine. I checked the GameHols.MainTRack.AddTerrain function, it is working fine, the problem is in some lua function. Oh, and another function I'm calling from lua is DoStuff(...) wich takes to l_DoStuff:
int l_DoStuff(lua_State* luaVM){ float a, b, c, d; a = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1 ); b = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); c = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); d = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); d = lua_tonumber(luaVM, 1); lua_remove( luaVM, 1); d = lua_tonumber(luaVM, 1); char buffer[10]; itoa((int)(a + b + c + d), buffer, 10); //MessageBox(NULL,buffer,"ERROR",MB_OK|MB_ICONEXCLAMATION); return 1;}
Now, DoStuff will work even with the MessageBox comented out, and with any number of arguments I send to the function!
Hum... I don't want to waste people's time here because I'm trying to do something I obviulsly didn't understood how it works, but if anyone spot an obvius error in here or some thing like that, please point me out. Thanks!