ソースを参照

Simplify Lua event handler, keep it has same behavior as AngleScript and C++.

aster2013 11 年 前
コミット
b6e413e49d

+ 5 - 39
Source/Urho3D/LuaScript/LuaScript.cpp

@@ -182,43 +182,9 @@ void LuaScript::AddEventHandler(Object* sender, const String& eventName, const S
         eventInvoker_->AddEventHandler(sender, eventName, function);
 }
 
-void LuaScript::RemoveEventHandler(const String& eventName, int functionIndex)
-{
-    WeakPtr<LuaFunction> function = GetFunction(functionIndex);
-    if (function)
-        eventInvoker_->RemoveEventHandler(0, eventName, function);
-}
-
-void LuaScript::RemoveEventHandler(const String& eventName, const String& functionName)
-{
-    WeakPtr<LuaFunction> function = GetFunction(functionName);
-    if (function)
-        eventInvoker_->RemoveEventHandler(0, eventName, function);
-}
-
 void LuaScript::RemoveEventHandler(const String& eventName)
 {
-    eventInvoker_->RemoveEventHandler(0, eventName, WeakPtr<LuaFunction>());
-}
-
-void LuaScript::RemoveEventHandler(Object* sender, const String& eventName, int functionIndex)
-{
-    if (!sender)
-        return;
-
-    WeakPtr<LuaFunction> function = GetFunction(functionIndex);
-    if (function)
-        eventInvoker_->RemoveEventHandler(sender, eventName, function);
-}
-
-void LuaScript::RemoveEventHandler(Object* sender, const String& eventName, const String& functionName)
-{
-    if (!sender)
-        return;
-
-    WeakPtr<LuaFunction> function = GetFunction(functionName);
-    if (function)
-        eventInvoker_->RemoveEventHandler(sender, eventName, function);
+    eventInvoker_->UnsubscribeFromEvent(eventName);
 }
 
 void LuaScript::RemoveEventHandler(Object* sender, const String& eventName)
@@ -226,7 +192,7 @@ void LuaScript::RemoveEventHandler(Object* sender, const String& eventName)
     if (!sender)
         return;
 
-    eventInvoker_->RemoveEventHandler(sender, eventName, WeakPtr<LuaFunction>());
+    eventInvoker_->UnsubscribeFromEvent(sender, eventName);
 }
 
 void LuaScript::RemoveEventHandlers(Object* sender)
@@ -234,12 +200,12 @@ void LuaScript::RemoveEventHandlers(Object* sender)
     if (!sender)
         return;
 
-    eventInvoker_->RemoveAllEventHandlers(sender);
+    eventInvoker_->UnsubscribeFromEvents(sender);
 }
 
 void LuaScript::RemoveAllEventHandlers()
 {
-    eventInvoker_->RemoveAllEventHandlers(0);
+    eventInvoker_->UnsubscribeFromAllEvents();
 }
 
 void LuaScript::RemoveEventHandlersExcept(const Vector<String>& exceptionNames)
@@ -248,7 +214,7 @@ void LuaScript::RemoveEventHandlersExcept(const Vector<String>& exceptionNames)
     for (unsigned i = 0; i < exceptionTypes.Size(); ++i)
         exceptionTypes[i] = StringHash(exceptionNames[i]);
 
-    eventInvoker_->RemoveEventHandlersExcept(exceptionTypes);
+    eventInvoker_->UnsubscribeFromAllEventsExcept(exceptionTypes, true);
 }
 
 bool LuaScript::ExecuteFile(const String& fileName)

+ 0 - 8
Source/Urho3D/LuaScript/LuaScript.h

@@ -56,16 +56,8 @@ public:
     virtual void AddEventHandler(Object* sender, const String& eventName, int functionIndex);
     /// Add a scripted event handler by function name for a specific sender.
     virtual void AddEventHandler(Object* sender, const String& eventName, const String& functionName);
-    /// Remove a scripted event handler by function.
-    virtual void RemoveEventHandler(const String& eventName, int functionIndex);
-    /// Remove a scripted event handler by function name.
-    virtual void RemoveEventHandler(const String& eventName, const String& functionName);
     /// Remove a scripted event handler.
     virtual void RemoveEventHandler(const String& eventName);
-    /// Remove a scripted event handler for a specific sender by function.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, int functionIndex);
-    /// Remove a scripted event handler for a specific sender by function name.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, const String& functionName);
     /// Remove a scripted event handler for a specific sender.
     virtual void RemoveEventHandler(Object* sender, const String& eventName);
     /// Remove all scripted event handlers for a specific sender.

+ 18 - 201
Source/Urho3D/LuaScript/LuaScriptEventInvoker.cpp

@@ -29,59 +29,14 @@
 namespace Urho3D
 {
 
-class EventHandlerCommand
-{
-public:
-    EventHandlerCommand(int type) : type_(type) { }
-    virtual ~EventHandlerCommand() { }
-    int type_;
-};
-
-struct AddOrRemoveEventHandlerCommand : public EventHandlerCommand
-{
-    enum { Type = 1 };
-    AddOrRemoveEventHandlerCommand(bool add, Object* sender, const StringHash& eventType, WeakPtr<LuaFunction> function) : 
-        EventHandlerCommand(Type), add_(add), sender_(sender), eventType_(eventType), function_(function)
-    {
-    }
-
-    bool add_;
-    Object* sender_;
-    StringHash eventType_;
-    WeakPtr<LuaFunction> function_;
-};
-
-struct RemoveAllEventHandlersCommand : public EventHandlerCommand
-{    
-    enum { Type = 2 };
-    RemoveAllEventHandlersCommand(Object* sender) : EventHandlerCommand(Type), sender_(sender)
-    {
-    }
-
-    Object* sender_;
-};
-
-struct RemoveEventHandlersExceptCommand : public EventHandlerCommand
-{
-
-    enum { Type = 3 };
-    RemoveEventHandlersExceptCommand(const PODVector<StringHash>& exceptionTypes) : EventHandlerCommand(Type), exceptionTypes_(exceptionTypes)
-    {
-    }
-    PODVector<StringHash> exceptionTypes_;
-};
-
 LuaScriptEventInvoker::LuaScriptEventInvoker(Context* context) : 
-    Object(context), 
-    instance_(0),
-    invoking_(false)
+    Object(context)
 {
 }
 
 LuaScriptEventInvoker::LuaScriptEventInvoker(LuaScriptInstance* instance) : 
     Object(instance->GetContext()), 
-    instance_(instance),
-    invoking_(false)
+    instance_(instance)
 {
 }
 
@@ -89,181 +44,43 @@ LuaScriptEventInvoker::~LuaScriptEventInvoker()
 {
 }
 
-void LuaScriptEventInvoker::AddEventHandler(Object* sender, const StringHash& eventType, WeakPtr<LuaFunction> function)
+void LuaScriptEventInvoker::AddEventHandler(Object* sender, const StringHash& eventType, LuaFunction* function)
 {
-    if (invoking_)
-    {
-        eventHandlerCommands_.Push(new AddOrRemoveEventHandlerCommand(true, sender, eventType, function));
+    if (!function)
         return;
-    }
 
-    EventTypeToLuaFunctionVectorMap& eventTypeToFunctionVectorMap = GetEventTypeToLuaFunctionVectorMap(sender);
-    EventTypeToLuaFunctionVectorMap::Iterator i = eventTypeToFunctionVectorMap.Find(eventType);
-
-    if (i == eventTypeToFunctionVectorMap.End())
-    {
-        eventTypeToFunctionVectorMap[eventType].Push(function);
-        
-        if (!sender)
-            SubscribeToEvent(eventType, HANDLER(LuaScriptEventInvoker, HandleLuaScriptEvent));
-        else
-            SubscribeToEvent(sender, eventType, HANDLER(LuaScriptEventInvoker, HandleLuaScriptEvent));
-    }
+    if (sender)
+        SubscribeToEvent(sender, eventType, HANDLER_USERDATA(LuaScriptEventInvoker, HandleLuaScriptEvent, function));
     else
-    {
-        if (!i->second_.Contains(function))
-            i->second_.Push(function);
-    }
-}
-
-void LuaScriptEventInvoker::RemoveEventHandler(Object* sender, const StringHash& eventType, WeakPtr<LuaFunction> function)
-{
-    if (invoking_)
-    {
-        eventHandlerCommands_.Push(new AddOrRemoveEventHandlerCommand(false, sender, eventType, function));
-        return;
-    }
-
-    EventTypeToLuaFunctionVectorMap& eventTypeToLuaFunctionVectorMap = GetEventTypeToLuaFunctionVectorMap(sender);
-    EventTypeToLuaFunctionVectorMap::Iterator i = eventTypeToLuaFunctionVectorMap.Find(eventType);
-    if (i == eventTypeToLuaFunctionVectorMap.End())
-        return;
-
-    if (function)
-        i->second_.Remove(function);
-    else
-        i->second_.Clear();
-    
-    if (i->second_.Empty())
-    {
-        eventTypeToLuaFunctionVectorMap.Erase(i);
-
-        if (!sender)
-            UnsubscribeFromEvent(eventType);
-        else
-            UnsubscribeFromEvent(sender, eventType);
-    }
-}
-
-void LuaScriptEventInvoker::RemoveAllEventHandlers(Object* sender)
-{
-    if (invoking_)
-    {
-        eventHandlerCommands_.Push(new RemoveAllEventHandlersCommand(sender));
-        return;
-    }
-
-    if (!sender)
-    {
-        UnsubscribeFromAllEvents();
-        eventTypeToLuaFunctionVectorMap.Clear();
-        senderEventTypeToLuaFunctionVectorMap.Clear();
-    }
-    else
-    {
-        UnsubscribeFromEvents(sender);
-        senderEventTypeToLuaFunctionVectorMap.Erase(sender);
-    }
-}
-
-void LuaScriptEventInvoker::RemoveEventHandlersExcept(const PODVector<StringHash>& exceptionTypes)
-{
-    if (invoking_)
-    {
-        eventHandlerCommands_.Push(new RemoveEventHandlersExceptCommand(exceptionTypes));
-        return;
-    }
-
-    for (unsigned i = 0; i < exceptionTypes.Size(); ++i)
-        eventTypeToLuaFunctionVectorMap.Erase(exceptionTypes[i]);
-
-    UnsubscribeFromAllEventsExcept(exceptionTypes, false);
+        SubscribeToEvent(eventType, HANDLER_USERDATA(LuaScriptEventInvoker, HandleLuaScriptEvent, function));
 }
 
 void LuaScriptEventInvoker::HandleLuaScriptEvent(StringHash eventType, VariantMap& eventData)
 {
-    Object* sender = GetEventHandler()->GetSender();
-    EventTypeToLuaFunctionVectorMap& eventTypeToLuaFunctionVectorMap = GetEventTypeToLuaFunctionVectorMap(sender);
-    EventTypeToLuaFunctionVectorMap::Iterator i = eventTypeToLuaFunctionVectorMap.Find(eventType);
-    if (i == eventTypeToLuaFunctionVectorMap.End())
+    LuaFunction* function = static_cast<LuaFunction*>(GetEventHandler()->GetUserData());
+    if (!function)
         return;
 
+    // Keep instance alive during invoking
     SharedPtr<LuaScriptInstance> instance(instance_);
-    
-    invoking_ = true;
-    
-    LuaFunctionVector& luaFunctionVector = i->second_;
     if (instance)
     {
-        for (unsigned i = 0; i < luaFunctionVector.Size(); ++i)
+        if (function->BeginCall(instance))
         {
-            WeakPtr<LuaFunction>& function = luaFunctionVector[i];
-            if (function && function->BeginCall(instance))
-            {
-                function->PushUserType(eventType, "StringHash");
-                function->PushUserType(eventData, "VariantMap");
-                function->EndCall();
-            }
+            function->PushUserType(eventType, "StringHash");
+            function->PushUserType(eventData, "VariantMap");
+            function->EndCall();
         }
     }
     else
     {
-        for (unsigned i = 0; i < luaFunctionVector.Size(); ++i)
-        {
-            WeakPtr<LuaFunction>& function = luaFunctionVector[i];
-            if (function && function->BeginCall())
-            {
-                function->PushUserType(eventType, "StringHash");
-                function->PushUserType(eventData, "VariantMap");
-                function->EndCall();
-            }
-        }
-    }
-
-    invoking_ = false;
-
-    if (!eventHandlerCommands_.Empty())
-    {
-        for (unsigned i = 0; i < eventHandlerCommands_.Size(); ++i)
-            ExecuteThenDestroyCommand(eventHandlerCommands_[i]);
-
-        eventHandlerCommands_.Clear();
-    }
-}
-
-void LuaScriptEventInvoker::ExecuteThenDestroyCommand(EventHandlerCommand* command)
-{
-    if (!command)
-        return;
-
-    switch (command->type_)
-    {
-    case AddOrRemoveEventHandlerCommand::Type:
-        {
-            AddOrRemoveEventHandlerCommand* theCommand = (AddOrRemoveEventHandlerCommand*)command;
-            if (theCommand->add_)
-                AddEventHandler(theCommand->sender_, theCommand->eventType_, theCommand->function_);
-            else
-                RemoveEventHandler(theCommand->sender_, theCommand->eventType_, theCommand->function_);
-        }
-        break;
-
-    case RemoveAllEventHandlersCommand::Type:
+        if (function->BeginCall())
         {
-            RemoveAllEventHandlersCommand* theCommand = (RemoveAllEventHandlersCommand*)command;
-            RemoveAllEventHandlers(theCommand->sender_);
+            function->PushUserType(eventType, "StringHash");
+            function->PushUserType(eventData, "VariantMap");
+            function->EndCall();
         }
-        break;
-
-    case RemoveEventHandlersExceptCommand::Type:
-        {
-            RemoveEventHandlersExceptCommand* theCommand = (RemoveEventHandlersExceptCommand*)command;
-            RemoveEventHandlersExcept(theCommand->exceptionTypes_);
-        }
-        break;
     }
-
-    delete command;
 }
 
 }

+ 3 - 30
Source/Urho3D/LuaScript/LuaScriptEventInvoker.h

@@ -27,7 +27,6 @@
 namespace Urho3D
 {
 
-class EventHandlerCommand;
 class LuaFunction;
 class LuaScriptInstance;
 
@@ -44,40 +43,14 @@ public:
     virtual ~LuaScriptEventInvoker();
 
     /// Add a scripted event handler.
-    void AddEventHandler(Object* sender, const StringHash& eventType, WeakPtr<LuaFunction> function);
-    /// Remove a scripted event handler.
-    void RemoveEventHandler(Object* sender, const StringHash& eventType, WeakPtr<LuaFunction> function);
-    /// Remove all scripted event handlers.
-    void RemoveAllEventHandlers(Object* sender);
-    /// Remove all scripted event handlers, except those listed.
-    void RemoveEventHandlersExcept(const PODVector<StringHash>& exceptionTypes);
+    void AddEventHandler(Object* sender, const StringHash& eventType, LuaFunction* function);
 
 private:
     /// Handle script event in Lua script.
     void HandleLuaScriptEvent(StringHash eventType, VariantMap& eventData);
-    typedef Vector<WeakPtr<LuaFunction> > LuaFunctionVector;
-    typedef HashMap<StringHash, LuaFunctionVector> EventTypeToLuaFunctionVectorMap;
-    /// Return event type to Lua function vector map.
-    EventTypeToLuaFunctionVectorMap& GetEventTypeToLuaFunctionVectorMap(Object* sender)
-    {
-        if (!sender)
-            return eventTypeToLuaFunctionVectorMap;
-
-        return senderEventTypeToLuaFunctionVectorMap[sender];
-    }
-    /// Execute then destory command.
-    void ExecuteThenDestroyCommand(EventHandlerCommand* command);
-
+    
     /// Lua script instance.
-    LuaScriptInstance* instance_;
-    /// Invoking.
-    bool invoking_;
-    /// Event handler commands.
-    PODVector<EventHandlerCommand*> eventHandlerCommands_;
-    /// Event type to Lua function vector map.
-    EventTypeToLuaFunctionVectorMap eventTypeToLuaFunctionVectorMap;
-    /// Event type to Lua function vector map for specific sender.
-    HashMap<Object*, EventTypeToLuaFunctionVectorMap> senderEventTypeToLuaFunctionVectorMap;
+    WeakPtr<LuaScriptInstance> instance_;
 };
 
 }

+ 0 - 8
Source/Urho3D/LuaScript/LuaScriptEventListener.h

@@ -42,16 +42,8 @@ public:
     virtual void AddEventHandler(Object* sender, const String& eventName, int functionIndex) = 0;
     /// Add a scripted event handler by function name for a specific sender.
     virtual void AddEventHandler(Object* sender, const String& eventName, const String& functionName) = 0;
-    /// Remove a scripted event handler by function.
-    virtual void RemoveEventHandler(const String& eventName, int functionIndex) = 0;
-    /// Remove a scripted event handler by function name.
-    virtual void RemoveEventHandler(const String& eventName, const String& functionName) = 0;
     /// Remove a scripted event handler.
     virtual void RemoveEventHandler(const String& eventName) = 0;
-    /// Remove a scripted event handler for a specific sender by function.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, int functionIndex) = 0;
-    /// Remove a scripted event handler for a specific sender by function name.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, const String& functionName) = 0;
     /// Remove a scripted event handler for a specific sender.
     virtual void RemoveEventHandler(Object* sender, const String& eventName) = 0;
     /// Remove all scripted event handlers for a specific sender.

+ 6 - 41
Source/Urho3D/LuaScript/LuaScriptInstance.cpp

@@ -324,45 +324,9 @@ void LuaScriptInstance::AddEventHandler(Object* sender, const String& eventName,
         eventInvoker_->AddEventHandler(sender, eventName, function);
 }
 
-void LuaScriptInstance::RemoveEventHandler(const String& eventName, int functionIndex)
-{
-    WeakPtr<LuaFunction> function = luaScript_->GetFunction(functionIndex);
-    if (function)
-        eventInvoker_->RemoveEventHandler(0, eventName, function);
-}
-
-void LuaScriptInstance::RemoveEventHandler(const String& eventName, const String& functionName)
-{
-    String realFunctionName = functionName.Replaced(":", ".");
-    WeakPtr<LuaFunction> function = luaScript_->GetFunction(realFunctionName);
-    if (function)
-        eventInvoker_->RemoveEventHandler(0, eventName, function);
-}
-
 void LuaScriptInstance::RemoveEventHandler(const String& eventName)
 {
-    eventInvoker_->RemoveEventHandler(0, eventName, WeakPtr<LuaFunction>());
-}
-
-void LuaScriptInstance::RemoveEventHandler(Object* sender, const String& eventName, int functionIndex)
-{
-    if (!sender)
-        return;
-
-    WeakPtr<LuaFunction> function = luaScript_->GetFunction(functionIndex);
-    if (function)
-        eventInvoker_->RemoveEventHandler(sender, eventName, function);
-}
-
-void LuaScriptInstance::RemoveEventHandler(Object* sender, const String& eventName, const String& functionName)
-{
-    if (!sender)
-        return;
-
-    String realFunctionName = functionName.Replaced(":", ".");
-    WeakPtr<LuaFunction> function = luaScript_->GetFunction(realFunctionName);
-    if (function)
-        eventInvoker_->RemoveEventHandler(sender, eventName, function);
+    eventInvoker_->UnsubscribeFromEvent(eventName);
 }
 
 void LuaScriptInstance::RemoveEventHandler(Object* sender, const String& eventName)
@@ -370,19 +334,20 @@ void LuaScriptInstance::RemoveEventHandler(Object* sender, const String& eventNa
     if (!sender)
         return;
 
-    eventInvoker_->RemoveEventHandler(sender, eventName, WeakPtr<LuaFunction>());
+    eventInvoker_->UnsubscribeFromEvent(sender, eventName);
 }
+
 void LuaScriptInstance::RemoveEventHandlers(Object* sender)
 {
     if (!sender)
         return;
 
-    eventInvoker_->RemoveAllEventHandlers(sender);
+    eventInvoker_->UnsubscribeFromEvents(sender);
 }
 
 void LuaScriptInstance::RemoveAllEventHandlers()
 {
-    eventInvoker_->RemoveAllEventHandlers(0);
+    eventInvoker_->UnsubscribeFromAllEvents();
 }
 
 void LuaScriptInstance::RemoveEventHandlersExcept(const Vector<String>& exceptionNames)
@@ -391,7 +356,7 @@ void LuaScriptInstance::RemoveEventHandlersExcept(const Vector<String>& exceptio
     for (unsigned i = 0; i < exceptionTypes.Size(); ++i)
         exceptionTypes[i] = StringHash(exceptionNames[i]);
 
-    eventInvoker_->RemoveEventHandlersExcept(exceptionTypes);
+    eventInvoker_->UnsubscribeFromAllEventsExcept(exceptionTypes, true);
 }
 
 bool LuaScriptInstance::CreateObject(const String& scriptObjectType)

+ 0 - 8
Source/Urho3D/LuaScript/LuaScriptInstance.h

@@ -85,16 +85,8 @@ public:
     virtual void AddEventHandler(Object* sender, const String& eventName, int functionIndex);
     /// Add a scripted event handler by function name for a specific sender.
     virtual void AddEventHandler(Object* sender, const String& eventName, const String& functionName);
-    /// Remove a scripted event handler by function.
-    virtual void RemoveEventHandler(const String& eventName, int functionIndex);
-    /// Remove a scripted event handler by function name.
-    virtual void RemoveEventHandler(const String& eventName, const String& functionName);
     /// Remove a scripted event handler.
     virtual void RemoveEventHandler(const String& eventName);
-    /// Remove a scripted event handler for a specific sender by function.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, int functionIndex);
-    /// Remove a scripted event handler for a specific sender by function name.
-    virtual void RemoveEventHandler(Object* sender, const String& eventName, const String& functionName);
     /// Remove a scripted event handler for a specific sender.
     virtual void RemoveEventHandler(Object* sender, const String& eventName);
     /// Remove all scripted event handlers for a specific sender.

+ 3 - 63
Source/Urho3D/LuaScript/pkgs/LuaScript/LuaScript.pkg

@@ -3,10 +3,7 @@ $#include "LuaScript/LuaScript.h"
 void LuaScriptAddEventHandler @ SubscribeToEvent(const String eventName, void* functionOrFunctionName);
 void LuaScriptAddEventHandler @ SubscribeToEvent(void* sender, const String eventName, void* functionOrFunctionName);
 
-void LuaScriptRemoveEventHandler @ UnsubscribeFromEvent(const String eventName, void* functionOrFunctionName);
 void LuaScriptRemoveEventHandler @ UnsubscribeFromEvent(const String eventName);
-
-void LuaScriptRemoveEventHandler @ UnsubscribeFromEvent(Object* sender, const String eventName, void* functionOrFunctionName);
 void LuaScriptRemoveEventHandler @ UnsubscribeFromEvent(Object* sender, const String eventName);
 
 void LuaScriptRemoveEventHandlers @ UnsubscribeFromEvents(Object* sender);
@@ -123,28 +120,10 @@ static int tolua_LuaScriptLuaAPI_UnsubscribeFromEvent(lua_State* tolua_S)
     }
     else if (args == 2)
     {
-        // UnsubscribeFromEvent(const String eventName, void* functionOrFunctionName);
-        if (tolua_isurho3dstring(tolua_S,1,0,&tolua_err))
-        {
-            if (!tolua_isfunctionorurho3dstring(tolua_S,2,0,&tolua_err))
-                goto tolua_lerror;
-        }
         // UnsubscribeFromEvent(Object* sender, const String eventName);
-        else if (tolua_isuserdata(tolua_S,1,0,&tolua_err))
-        {
-            if (!tolua_isurho3dstring(tolua_S,2,0,&tolua_err))
-                goto tolua_lerror;
-        }
-        else
-            goto tolua_lerror;
-    }
-    else if (args == 3)
-    {
-        // UnsubscribeFromEvent(Object* sender, const String eventName, void* functionOrFunctionName);
         if (!tolua_isuserdata(tolua_S,1,0,&tolua_err) ||
-            !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
-            !tolua_isfunctionorurho3dstring(tolua_S,3,0,&tolua_err))
-            goto tolua_lerror;
+            !tolua_isurho3dstring(tolua_S,2,0,&tolua_err))
+                goto tolua_lerror;
     }
     else
         goto tolua_lerror;
@@ -158,38 +137,10 @@ static int tolua_LuaScriptLuaAPI_UnsubscribeFromEvent(lua_State* tolua_S)
     }
     else if (args == 2)
     {
-        // UnsubscribeFromEvent(const String eventName, void* functionOrFunctionName);
-        if (tolua_isurho3dstring(tolua_S,1,0,&tolua_err))
-        {
-            const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,1,0));
-            if (lua_isfunction(tolua_S, 2))
-                LuaScriptRemoveEventHandler(eventName, 2);
-            else
-            {
-                const String functionName = (const String)tolua_tourho3dstring(tolua_S,2,0);
-                LuaScriptRemoveEventHandler(eventName, functionName);
-            }
-        }
         // UnsubscribeFromEvent(Object* sender, const String eventName);
-        else if (tolua_isuserdata(tolua_S,1,0,&tolua_err))
-        {
-            Object* sender = ((Object*)  tolua_touserdata(tolua_S,1,0));
-            const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-            LuaScriptRemoveEventHandler(sender, eventName);
-        }
-    }
-    else if (args == 3)
-    {
-        // UnsubscribeFromEvent(Object* sender, const String eventName, void* functionOrFunctionName);
         Object* sender = ((Object*)  tolua_touserdata(tolua_S,1,0));
         const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-        if (lua_isfunction(tolua_S,3))
-            LuaScriptRemoveEventHandler(sender,eventName,3);
-        else
-        {
-            const String functionName = (const String)tolua_tourho3dstring(tolua_S,3,0);
-            LuaScriptRemoveEventHandler(sender,eventName,functionName);
-        }
+        LuaScriptRemoveEventHandler(sender, eventName);
     }
 
     return 0;
@@ -213,15 +164,4 @@ static int tolua_LuaScriptLuaAPI_UnsubscribeFromEvent01(lua_State* tolua_S)
     return tolua_LuaScriptLuaAPI_UnsubscribeFromEvent(tolua_S);
 }
 
-#define TOLUA_DISABLE_tolua_LuaScriptLuaAPI_UnsubscribeFromEvent02
-static int tolua_LuaScriptLuaAPI_UnsubscribeFromEvent02(lua_State* tolua_S)
-{
-    return tolua_LuaScriptLuaAPI_UnsubscribeFromEvent(tolua_S);
-}
-
-#define TOLUA_DISABLE_tolua_LuaScriptLuaAPI_UnsubscribeFromEvent03
-static int tolua_LuaScriptLuaAPI_UnsubscribeFromEvent03(lua_State* tolua_S)
-{
-    return tolua_LuaScriptLuaAPI_UnsubscribeFromEvent(tolua_S);
-}
 $}

+ 7 - 72
Source/Urho3D/LuaScript/pkgs/LuaScript/LuaScriptInstance.pkg

@@ -9,9 +9,7 @@ class LuaScriptInstance : public Component
 
     void AddEventHandler @ SubscribeToEvent(const String eventName, void* functionOrFunctionName);
     void AddEventHandler @ SubscribeToEvent(void* sender, const String eventName, void* functionOrFunctionName);
-    void RemoveEventHandler @ UnsubscribeFromEvent(const String eventName, void* functionOrFunctionName);
     void RemoveEventHandler @ UnsubscribeFromEvent(const String eventName);
-    void RemoveEventHandler @ UnsubscribeFromEvent(Object* sender, const String eventName, void* functionOrFunctionName);
     void RemoveEventHandler @ UnsubscribeFromEvent(Object* sender, const String eventName);
     void RemoveEventHandlers @ UnsubscribeFromEvents(Object* sender);
     void RemoveAllEventHandlers @ UnsubscribeFromAllEvents();
@@ -50,7 +48,7 @@ function LuaScriptObject:SubscribeToEvent(param1, param2, param3)
     end
 end
 
-function LuaScriptObject:UnsubscribeFromEvent(param1, param2, param3)
+function LuaScriptObject:UnsubscribeFromEvent(param1, param2)
     local instance = self.instance
     if instance == nil then
         return
@@ -58,10 +56,8 @@ function LuaScriptObject:UnsubscribeFromEvent(param1, param2, param3)
 
     if param2 == nil then
         instance:UnsubscribeFromEvent(param1)
-    elseif param3 == nil then
-        instance:UnsubscribeFromEvent(param1, param2)
     else
-        instance:UnsubscribeFromEvent(param1, param2, param3)
+        instance:UnsubscribeFromEvent(param1, param2)
     end
 end
 
@@ -230,32 +226,11 @@ static int tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent(lua_Stat
     }
     else if (args == 3)
     {
-        // LuaScriptInstance::RemoveEventHandler(const String eventName, void* functionOrFunctionName);
-        if (!tolua_isusertype(tolua_S,1,"LuaScriptInstance",0,&tolua_err))
-            goto tolua_lerror;
-
-        if (tolua_isurho3dstring(tolua_S,2,0,&tolua_err))
-        {
-            if (!tolua_isfunctionorurho3dstring(tolua_S,3,0,&tolua_err))
-                goto tolua_lerror;
-        }
-        // LuaScriptInstance::RemoveEventHandler(Object* sender, const String eventName);
-        else if (tolua_isuserdata(tolua_S,2,0,&tolua_err))
-        {
-            if (!tolua_isurho3dstring(tolua_S,3,0,&tolua_err))
-                goto tolua_lerror;
-        }
-        else
-            goto tolua_lerror;
-    }
-    else if (args == 4)
-    {
-        // LuaScriptInstance::RemoveEventHandler(Object* sender, const String eventName, void* functionOrFunctionName);
+       // LuaScriptInstance::RemoveEventHandler(Object* sender, const String eventName);
         if (!tolua_isusertype(tolua_S,1,"LuaScriptInstance",0,&tolua_err) ||
             !tolua_isuserdata(tolua_S,2,0,&tolua_err) ||
-            !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
-            !tolua_isfunctionorurho3dstring(tolua_S,4,0,&tolua_err))
-            goto tolua_lerror;
+            !tolua_isurho3dstring(tolua_S,3,0,&tolua_err))
+                goto tolua_lerror;
     }
     else
         goto tolua_lerror;
@@ -269,40 +244,12 @@ static int tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent(lua_Stat
         const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
         self->RemoveEventHandler(eventName);
     }
-    else if (args == 2)
+    else if (args == 3)
     {
-        // LuaScriptInstance::RemoveEventHandler(const String eventName, void* functionOrFunctionName);
-        if (tolua_isurho3dstring(tolua_S,2,0,&tolua_err))
-        {
-            const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,2,0));
-            if (lua_isfunction(tolua_S, 3))
-                self->RemoveEventHandler(eventName, 3);
-            else
-            {
-                const String functionName = (const String)tolua_tourho3dstring(tolua_S,3,0);
-                self->RemoveEventHandler(eventName, functionName);
-            }
-        }
         // LuaScriptInstance::RemoveEventHandler(Object* sender, const String eventName);
-        else if (tolua_isuserdata(tolua_S,2,0,&tolua_err))
-        {
-            Object* sender = ((Object*)  tolua_touserdata(tolua_S,2,0));
-            const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,3,0));
-            self->RemoveEventHandler(sender, eventName);
-        }
-    }
-    else if (args == 4)
-    {
-        // LuaScriptInstance::RemoveEventHandler(Object* sender, const String eventName, void* functionOrFunctionName);
         Object* sender = ((Object*)  tolua_touserdata(tolua_S,2,0));
         const String eventName = ((const String)  tolua_tourho3dstring(tolua_S,3,0));
-        if (lua_isfunction(tolua_S,4))
-            self->RemoveEventHandler(sender,eventName,4);
-        else
-        {
-            const String functionName = (const String)tolua_tourho3dstring(tolua_S,4,0);
-            self->RemoveEventHandler(sender,eventName,functionName);
-        }
+        self->RemoveEventHandler(sender, eventName);
     }
 
     return 0;
@@ -326,16 +273,4 @@ static int tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent01(lua_St
     return tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent(tolua_S);
 }
 
-#define TOLUA_DISABLE_tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent02
-static int tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent02(lua_State* tolua_S)
-{
-    return tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent(tolua_S);
-}
-
-#define TOLUA_DISABLE_tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent03
-static int tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent03(lua_State* tolua_S)
-{
-    return tolua_LuaScriptLuaAPI_LuaScriptInstance_UnsubscribeFromEvent(tolua_S);
-}
-
 $}