|
|
@@ -35,16 +35,32 @@ LuaEventListener::LuaEventListener(const String& code, Element* element) : Event
|
|
|
lua_pop(L,1); //pop the EVENTLISTENERFUNCTIONS table
|
|
|
|
|
|
attached = element;
|
|
|
- parent = element->GetOwnerDocument();
|
|
|
+ if(element)
|
|
|
+ parent = element->GetOwnerDocument();
|
|
|
+ else
|
|
|
+ parent = NULL;
|
|
|
strFunc = function;
|
|
|
}
|
|
|
|
|
|
-//if it is created from a Lua Element
|
|
|
-LuaEventListener::LuaEventListener(int ref, Element* element)
|
|
|
+//if it is passed in a Lua function
|
|
|
+LuaEventListener::LuaEventListener(lua_State* L, int narg, Element* element)
|
|
|
{
|
|
|
- luaFuncRef = ref;
|
|
|
- attached = element;
|
|
|
- parent = element->GetOwnerDocument();
|
|
|
+ lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
+ if(lua_isnoneornil(L,-1))
|
|
|
+ {
|
|
|
+ lua_newtable(L);
|
|
|
+ lua_setglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
+ lua_pop(L,1); //pop the unsucessful getglobal
|
|
|
+ lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
+ }
|
|
|
+ lua_pushvalue(L,narg);
|
|
|
+ luaFuncRef = luaL_ref(L,-2); //put the funtion as a ref in to that table
|
|
|
+ lua_pop(L,1); //pop the EVENTLISTENERFUNCTIONS table
|
|
|
+ attached = element;
|
|
|
+ if(element)
|
|
|
+ parent = element->GetOwnerDocument();
|
|
|
+ else
|
|
|
+ parent = NULL;
|
|
|
}
|
|
|
|
|
|
LuaEventListener::~LuaEventListener()
|
|
|
@@ -61,19 +77,15 @@ void LuaEventListener::ProcessEvent(Event& event)
|
|
|
//not sure if this is the right place to do this, but if the element we are attached to isn't a document, then
|
|
|
//the 'parent' variable will be NULL, because element->ower_document hasn't been set on the construction. We should
|
|
|
//correct that
|
|
|
- if(!parent) parent = attached->GetOwnerDocument();
|
|
|
+ if(!parent && attached) parent = attached->GetOwnerDocument();
|
|
|
lua_State* L = Interpreter::GetLuaState();
|
|
|
- String strtype;
|
|
|
int top = lua_gettop(L);
|
|
|
//push the arguments
|
|
|
lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
- int table = lua_gettop(L); //needed for lua_remove
|
|
|
- strtype = lua_typename(L,lua_type(L,table));
|
|
|
- lua_rawgeti(L,table,luaFuncRef);
|
|
|
- strtype = lua_typename(L,lua_type(L,-1));
|
|
|
- strtype = lua_typename(L,lua_type(L,LuaType<Event>::push(L,&event,false)));
|
|
|
- strtype = lua_typename(L,lua_type(L,LuaType<Element>::push(L,attached,false)));
|
|
|
- strtype = lua_typename(L,lua_type(L,LuaType<Document>::push(L,parent,false)));
|
|
|
+ lua_rawgeti(L,-1,luaFuncRef);
|
|
|
+ LuaType<Event>::push(L,&event,false);
|
|
|
+ LuaType<Element>::push(L,attached,false);
|
|
|
+ LuaType<Document>::push(L,parent,false);
|
|
|
|
|
|
Interpreter::ExecuteCall(3,0); //call the function at the top of the stack with 3 arguments
|
|
|
|