I think I got it to work, finally, I feel It didnt even worth thou, so much time spent on hat .__.
I did it like that:
Inside my agent class:
[source lang="cpp"] //------------------------------------------------------------------------ // Lua Binding Stuff //------------------------------------------------------------------------ static const char className[]; static Lunar<LuaAIAgent>::RegType methods[]; static LuaAIAgent* currentAgent; static int push_object (lua_State* L){ Lunar<LuaAIAgent>::push(L, currentAgent, true); return 1; }[/source]
And then, on the constructor of my class I init the static pointer to the this pointer:
[source lang="cpp"] //------------------------------------------------------------------------ // ctor //------------------------------------------------------------------------ LuaAIAgent( const char image_p, COLOR color_p, const Coord & pos_p ) : BulletAIAgent(image_p, color_p, pos_p){ ... currentAgent = this; }[/source]
Then theres this method:
[source lang="cpp"]void InitLuaScript( const char * szLuaScriptFilename_p ){ m_szLuaScriptFilename = szLuaScriptFilename_p; // create a Lua state and register the exposed methods m_pLua = lua_open(); luaL_openlibs(m_pLua); Lunar<LuaAIAgent>::Register( m_pLua ); lua_pushcfunction(m_pLua, push_object); lua_setglobal(m_pLua, "push_object"); // compile script if( luaL_loadfile( m_pLua, m_szLuaScriptFilename ) != 0 ){ throw std::exception( "problem loading Lua script" ); } // execute the file int err = lua_pcall( m_pLua, 0, 0, 0 ); if( err != 0 ){ // 2 = runtime error // 4 = mem alloc error throw std::exception( "problem running Lua script" ); }...[/source]
And on the lua script:
[source lang="cpp"]b = push_object()printf(b:Lua_GetHP())[/source]
Its lame, cause I can have only one agent, but its the only solution I got after uninterrupted 48 hours of researching and crying for help everywhere ( I dont know how I could store a bunch of static pointers and init them properly with the agents...naming the function differently would be easy and convenient (GetAGentSmith, GetAgentDumb..) )
Edited by Icebone1000, 12 November 2012 - 07:39 AM.