lua-users home
lua-l archive

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


Lol sorry u need the other way to call into lua *g*

here


//------ create functiontable and func IDoff -------
lua_newtable (m_pState);m_iThisRef = luaL_ref(m_pState, LUA_REGISTRYINDEX);
lua_rawgeti (m_pState, LUA_REGISTRYINDEX, m_iThisRef);
lua_pushlightuserdata (m_pState, (void *) this);
lua_rawseti (m_pState, -2, 0);´
lua_setglobal (m_pState, "this");


//test if an function exist btw. u need only one function to call
//named  OnEvent(string)    //load,close,refresh,info and so on
//u can make an register event so the user can choise the msg
//u should to send

this.OnEvent(this,event)  <---let show so
if event==load then
 do anything
elseif event==save
 dont load
end
end
//Check for OnEvent exists in script
bool CLuaScript::IsFunction(char * pFname)
{
lua_rawgeti (m_pState, LUA_REGISTRYINDEX, m_iThisRef);
lua_pushstring (m_pState, pFname);
lua_rawget (m_pState, -2);
lua_remove (m_pState, -2);
lua_rawgeti (m_pState, LUA_REGISTRYINDEX, m_iThisRef);

if (!lua_isfunction (m_pState, -2))
{
lua_pop (m_pState, 2);
return false;
}

return true;
}



OnEvent("load")  and so on fastest way

//let call lua the OnEvent  Message handler in luascript :-)
bool CLuaScript::OnEvent(char *strEvent)
{
if(!m_pState) return false;
lua_rawgeti (m_pState, LUA_REGISTRYINDEX, m_iThisRef);
lua_pushstring (m_pState, "OnEvent");
lua_rawget (m_pState, -2);
lua_remove (m_pState, -2);
lua_rawgeti (m_pState, LUA_REGISTRYINDEX, m_iThisRef);
lua_pushstring(m_pState,strEvent);
int iErr = lua_pcall(m_pState, 2,-1, 0);
if(iErr) return LuaErr(iErr);
return true;
}




----- Original Message ----- From: "Noel Frankinet" <nfr@gistek.net>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Monday, March 13, 2006 11:31 AM
Subject: passing object to lua


Hello,
This is my first post on the list,

I'm writing a GUI framework for windows using lua.
I use Luna binding between C++ classes and lua, everything works fine.
Now I want to call back from C++ to lua, passing back the C++ object (eg a "Dialog") in order to be able the use class qulaified method inside the callback
How do I do that ?

Thank you.

--
Noël Frankinet
Gistek Software SA
http://www.gistek.net