|
@@ -10,10 +10,12 @@ typedef Rocket::Core::ElementDocument Document;
|
|
|
|
|
|
|
|
LuaEventListener::LuaEventListener(const String& code, Element* element) : EventListener()
|
|
LuaEventListener::LuaEventListener(const String& code, Element* element) : EventListener()
|
|
|
{
|
|
{
|
|
|
|
|
+ //compose function
|
|
|
String function = "return function (event,element,document) ";
|
|
String function = "return function (event,element,document) ";
|
|
|
function.Append(code);
|
|
function.Append(code);
|
|
|
function.Append(" end");
|
|
function.Append(" end");
|
|
|
|
|
|
|
|
|
|
+ //make sure there is an area to save the function
|
|
|
lua_State* L = Interpreter::GetLuaState();
|
|
lua_State* L = Interpreter::GetLuaState();
|
|
|
lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
if(lua_isnoneornil(L,-1))
|
|
if(lua_isnoneornil(L,-1))
|
|
@@ -24,14 +26,14 @@ LuaEventListener::LuaEventListener(const String& code, Element* element) : Event
|
|
|
lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
lua_getglobal(L,"EVENTLISTENERFUNCTIONS");
|
|
|
}
|
|
}
|
|
|
int tbl = lua_gettop(L);
|
|
int tbl = lua_gettop(L);
|
|
|
- strFunc = lua_typename(L,lua_type(L,tbl));
|
|
|
|
|
|
|
|
|
|
- luaL_loadstring(L,function.CString()); //pushes the compiled string to the top of the stack
|
|
|
|
|
|
|
+ //compile,execute,and save the function
|
|
|
|
|
+ luaL_loadstring(L,function.CString());
|
|
|
if(lua_pcall(L,0,1,0) != 0)
|
|
if(lua_pcall(L,0,1,0) != 0)
|
|
|
Interpreter::Report();
|
|
Interpreter::Report();
|
|
|
- strFunc = lua_typename(L,lua_type(L,-1));
|
|
|
|
|
luaFuncRef = luaL_ref(L,tbl); //creates a reference to the item at the top of the stack in to the table we just created
|
|
luaFuncRef = luaL_ref(L,tbl); //creates a reference to the item at the top of the stack in to the table we just created
|
|
|
lua_pop(L,1); //pop the EVENTLISTENERFUNCTIONS table
|
|
lua_pop(L,1); //pop the EVENTLISTENERFUNCTIONS table
|
|
|
|
|
+
|
|
|
attached = element;
|
|
attached = element;
|
|
|
parent = element->GetOwnerDocument();
|
|
parent = element->GetOwnerDocument();
|
|
|
strFunc = function;
|
|
strFunc = function;
|
|
@@ -45,9 +47,21 @@ LuaEventListener::LuaEventListener(int ref, Element* element)
|
|
|
parent = element->GetOwnerDocument();
|
|
parent = element->GetOwnerDocument();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+LuaEventListener::~LuaEventListener()
|
|
|
|
|
+{
|
|
|
|
|
+ if(attached)
|
|
|
|
|
+ attached->RemoveReference();
|
|
|
|
|
+ if(parent)
|
|
|
|
|
+ parent->RemoveReference();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// Process the incoming Event
|
|
/// Process the incoming Event
|
|
|
void LuaEventListener::ProcessEvent(Event& event)
|
|
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();
|
|
|
lua_State* L = Interpreter::GetLuaState();
|
|
lua_State* L = Interpreter::GetLuaState();
|
|
|
String strtype;
|
|
String strtype;
|
|
|
int top = lua_gettop(L);
|
|
int top = lua_gettop(L);
|