diff options
author | chai <chaifix@163.com> | 2021-11-08 09:23:38 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-08 09:23:38 +0800 |
commit | 138d3f4d3d6e2aaf5ba34f89af15ef85ea074357 (patch) | |
tree | 31ca6e8ea6d2e960e8d35f801bd92555942822e2 /Runtime/Lua/LuaBind | |
parent | efce5b6bd5c9d4f8214a71e0f7a7c35751710a4c (diff) |
*misc
Diffstat (limited to 'Runtime/Lua/LuaBind')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBind.h | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindClass.hpp | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.cpp | 105 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.h | 77 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindMemberRef.h | 1 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.cpp | 5 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindTable.h | 15 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindUtility.h | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/signal/bind.h | 510 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/signal/remove_from_container.h | 32 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/signal/signal.h | 451 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/signal/slot.h | 203 |
13 files changed, 209 insertions, 1198 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBind.h b/Runtime/Lua/LuaBind/LuaBind.h index e12c4b9..b6c5870 100644 --- a/Runtime/Lua/LuaBind/LuaBind.h +++ b/Runtime/Lua/LuaBind/LuaBind.h @@ -10,5 +10,7 @@ #include "LuaBindMemberRef.h" #include "LuaBindClass.inc" #include "LuaBindState.inc" +#include "LuaBindInvoker.h" +#include "LuaBindTable.h" #endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindClass.hpp b/Runtime/Lua/LuaBind/LuaBindClass.hpp index 3a407d2..a5ac978 100644 --- a/Runtime/Lua/LuaBind/LuaBindClass.hpp +++ b/Runtime/Lua/LuaBind/LuaBindClass.hpp @@ -87,7 +87,7 @@ namespace LuaBind NativeClass(LuaBind::VM* vm); virtual ~NativeClass(); - VM* GetVM() { return mOwner; } + LuaBind::VM* GetVM() { return mOwner; } // 成员引用管理,在实例的ref table里。设置、取、清除 void SetMemberRef(State& state, MemberRef& memRef, int idx); diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp new file mode 100644 index 0000000..debebf8 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp @@ -0,0 +1,105 @@ +#include "LuaBindInvoker.h" + +namespace LuaBind +{ + + void GlobalInvoker::AddInt(int n) + { + state.Push(n); + ++argc; + } + + void GlobalInvoker::AddFloat(float n) + { + state.Push(n); + ++argc; + } + + void GlobalInvoker::AddNil() + { + state.PushNil(); + ++argc; + } + + void GlobalInvoker::AddBool(bool b) + { + state.Push(b); + ++argc; + } + + void GlobalInvoker::AddString(const char* str) + { + state.Push(str); + ++argc; + } + + void GlobalInvoker::AddTable(INativeTable& tb) + { + tb.CastToTable(state); + ++argc; + } + + void GlobalInvoker::Invoke(int nReturns) + { + method.PushRef(state); + state.Call(argc, nReturns, onErrorOccured); + } + + + void MemberInvoker::AddInt(int n) + { + state.Push(n); + ++argc; + } + + void MemberInvoker::AddFloat(float n) + { + state.Push(n); + ++argc; + } + + void MemberInvoker::AddNil() + { + state.PushNil(); + ++argc; + } + + void MemberInvoker::AddBool(bool b) + { + state.Push(b); + ++argc; + } + + void MemberInvoker::AddString(const char* str) + { + state.Push(str); + ++argc; + } + + void MemberInvoker::AddTable(INativeTable& tb) + { + tb.CastToTable(state); + ++argc; + } + + void MemberInvoker::AddMember(MemberRef member) + { + owner->PushMemberRef(state, member); + ++argc; + } + + void MemberInvoker::Invoke(int nReturns) + { + owner->PushMemberRef(state, member); + state.GetField(-1, method); + if (!state.IsType(-1, LUA_TFUNCTION)) + { + state.Pop(2); + return; + } + lua_replace(state, -2); + lua_insert(state, -1 - argc); + state.Call(argc, nReturns, onErrorOccured); + } + +} diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h new file mode 100644 index 0000000..8ea57a2 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h @@ -0,0 +1,77 @@ +#ifndef LUA_BIND_INVOKER_H +#define LUA_BIND_INVOKER_H + +#include "LuaBindRef.h" +#include "LuaBindTable.h" +#include "LuaBindClass.hpp" + +namespace LuaBind +{ + + // 调用全局lua方法 + struct GlobalInvoker + { + GlobalInvoker(lua_State* st) + : state(st) + { + argc = 0; + } + UniversalRef method; + + void AddInt(int n); + void AddFloat(float n); + void AddNil(); + void AddBool(bool b); + void AddString(const char* str); + void AddTable(INativeTable& tb); + template<class T> + void AddUserdata(NativeClass<T>& udata) { + udata.PushUserdata(state); + ++argc; + } + + void Invoke(int nReturns); + + private: + State state; + int argc; + }; + + // 调用成员的方法 + struct MemberInvoker + { + MemberRef member; + const char* method; + + MemberInvoker(lua_State* st, LuaBind::Object* owner) + : state(st) + { + argc = 0; + this->owner = owner; + } + + void AddMember(MemberRef member); + void AddInt(int n); + void AddFloat(float n); + void AddNil(); + void AddBool(bool b); + void AddString(const char* str); + void AddTable(INativeTable& tb); + template<class T> + void AddUserdata(NativeClass<T>& udata) { + udata.PushUserdata(state); + ++argc; + } + + void Invoke(int nReturns); + + private: + LuaBind::Object* owner; + State state; + int argc; + + }; + +} + +#endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindMemberRef.h b/Runtime/Lua/LuaBind/LuaBindMemberRef.h index ecc50f5..37fe413 100644 --- a/Runtime/Lua/LuaBind/LuaBindMemberRef.h +++ b/Runtime/Lua/LuaBind/LuaBindMemberRef.h @@ -8,6 +8,7 @@ namespace LuaBind // 实例的ref table保存的member ref。由luax class做具体的管理。实例的ref table是强引用,用来管理里面member的生命周期。 // 用来在lua和native之间进行数据沟通。 + // 不会由于循环引用而内存泄露,因为lua的GC是tracing GC class MemberRef { public: diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp index 384cba2..676c19c 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.cpp +++ b/Runtime/Lua/LuaBind/LuaBindState.cpp @@ -196,6 +196,11 @@ namespace LuaBind } } + void State::PushTable(INativeTable& tb) + { + tb.CastToTable(*this); + } + void State::PushNil() { lua_pushnil(mState); diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index e639d4d..24bd092 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -6,6 +6,7 @@ #include "LuaBindConfig.h" #include "LuaBindRefTable.h" #include "LuaBindGlobalState.h" +#include "LuaBindTable.h" namespace LuaBind { @@ -100,6 +101,7 @@ namespace LuaBind bool HasField(int idx, int name, int type); bool HasKeys(int idx); + void PushTable(INativeTable& tb); void PushNil(); void Push(bool value); void Push(cc8* value); diff --git a/Runtime/Lua/LuaBind/LuaBindTable.h b/Runtime/Lua/LuaBind/LuaBindTable.h new file mode 100644 index 0000000..3a6ec6c --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindTable.h @@ -0,0 +1,15 @@ +#pragma once + +namespace LuaBind +{ + + class State; + + // 需要作为table传给lua的结构实现这个接口 + struct INativeTable + { + // 将结构转换为table并留在栈顶 + virtual void CastToTable(State& state) = 0; + }; + +}
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindUtility.h b/Runtime/Lua/LuaBind/LuaBindUtility.h index e88dd68..e47a326 100644 --- a/Runtime/Lua/LuaBind/LuaBindUtility.h +++ b/Runtime/Lua/LuaBind/LuaBindUtility.h @@ -34,7 +34,7 @@ }while(0) #define LUA_BIND_REGISTER_ENUM(state, name, ...) \ do{ \ - ::Enum __e[] = {__VA_ARGS__,{0, 0}}; \ + LuaBind::Enum __e[] = {__VA_ARGS__,{0, 0}}; \ state.RegisterEnum(name, __e); \ }while(0) diff --git a/Runtime/Lua/LuaBind/signal/bind.h b/Runtime/Lua/LuaBind/signal/bind.h deleted file mode 100644 index e29896b..0000000 --- a/Runtime/Lua/LuaBind/signal/bind.h +++ /dev/null @@ -1,510 +0,0 @@ -// Aseprite Base Library -// Copyright (c) 2001-2013 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -#ifndef BASE_BIND_H_INCLUDED -#define BASE_BIND_H_INCLUDED -#pragma once - -// BindAdapter0_fun -template<typename R, typename F> -class BindAdapter0_fun -{ - F f; -public: - BindAdapter0_fun(const F& f) : f(f) { } - - R operator()() { return f(); } - - template<typename A1> - R operator()(const A1& a1) { return f(); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(); } -}; - -template<typename F> -class BindAdapter0_fun<void, F> -{ - F f; -public: - BindAdapter0_fun(const F& f) : f(f) { } - - void operator()() { f(); } - - template<typename A1> - void operator()(const A1& a1) { f(); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(); } -}; - -template<typename R, typename F> -BindAdapter0_fun<R, F> -Bind(const F& f) -{ - return BindAdapter0_fun<R, F>(f); -} - -// BindAdapter0_mem -template<typename R, typename T> -class BindAdapter0_mem -{ - R (T::*m)(); - T* t; -public: - template<typename T2> - BindAdapter0_mem(R (T::*m)(), T2* t) : m(m), t(t) { } - - R operator()() { return (t->*m)(); } - - template <typename A1> - R operator()(const A1& a1) { return (t->*m)(); } - - template <typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(); } - - template <typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(); } - - template <typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(); } -}; - -template<typename T> -class BindAdapter0_mem<void, T> -{ - void (T::*m)(); - T* t; -public: - template<typename T2> - BindAdapter0_mem(void (T::*m)(), T2* t) : m(m), t(t) { } - - void operator()() { (t->*m)(); } - - template <typename A1> - void operator()(const A1& a1) { (t->*m)(); } - - template <typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(); } - - template <typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(); } - - template <typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(); } -}; - -template<typename R, typename T, typename T2> -BindAdapter0_mem<R, T> -Bind(R (T::*m)(), T2* t) -{ - return BindAdapter0_mem<R, T>(m, t); -} - -// BindAdapter1_fun -template<typename R, typename F, - typename X1> -class BindAdapter1_fun -{ - F f; - X1 x1; -public: - BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } - - R operator()() { return f(x1); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1); } -}; - -template<typename F, - typename X1> -class BindAdapter1_fun<void, F, X1> -{ - F f; - X1 x1; -public: - BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } - - void operator()() { f(x1); } - - template<typename A1> - void operator()(const A1& a1) { f(x1); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1); } -}; - -template<typename R, typename F, - typename X1> -BindAdapter1_fun<R, F, X1> -Bind(const F& f, X1 x1) -{ - return BindAdapter1_fun<R, F, X1>(f, x1); -} - -// BindAdapter1_mem -template<typename R, typename T, - typename B1, - typename X1> -class BindAdapter1_mem -{ - R (T::*m)(B1); - T* t; - X1 x1; -public: - template<typename T2> - BindAdapter1_mem(R (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } - - R operator()() { return (t->*m)(x1); } - - template <typename A1> - R operator()(const A1& a1) { return (t->*m)(x1); } - - template <typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1); } - - template <typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1); } - - template <typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1); } -}; - -template<typename T, - typename B1, - typename X1> -class BindAdapter1_mem<void, T, B1, X1> -{ - void (T::*m)(B1); - T* t; - X1 x1; -public: - template<typename T2> - BindAdapter1_mem(void (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } - - void operator()() { (t->*m)(x1); } - - template <typename A1> - void operator()(const A1& a1) { (t->*m)(x1); } - - template <typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1); } - - template <typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1); } - - template <typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1); } -}; - -template<typename R, typename T, typename T2, - typename B1, typename X1> -BindAdapter1_mem<R, T, B1, X1> -Bind(R (T::*m)(B1), T2* t, X1 x1) -{ - return BindAdapter1_mem<R, T, B1, X1>(m, t, x1); -} - -// BindAdapter2_fun -template<typename R, typename F, - typename X1, typename X2> -class BindAdapter2_fun -{ - F f; - X1 x1; - X2 x2; -public: - BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } - - R operator()() { return f(x1, x2); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1, x2); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1, x2); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2); } -}; - -template<typename F, - typename X1, typename X2> -class BindAdapter2_fun<void, F, X1, X2> -{ - F f; - X1 x1; - X2 x2; -public: - BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } - - void operator()() { f(x1, x2); } - - template<typename A1> - void operator()(const A1& a1) { f(x1, x2); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1, x2); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2); } -}; - -template<typename R, typename F, - typename X1, typename X2> -BindAdapter2_fun<R, F, X1, X2> -Bind(const F& f, X1 x1, X2 x2) -{ - return BindAdapter2_fun<R, F, X1, X2>(f, x1, x2); -} - -// BindAdapter2_mem -template<typename R, typename T, - typename B1, typename B2, - typename X1, typename X2> -class BindAdapter2_mem -{ - R (T::*m)(B1, B2); - T* t; - X1 x1; - X2 x2; -public: - template<typename T2> - BindAdapter2_mem(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - R operator()() { return (t->*m)(x1, x2); } - - template<typename A1> - R operator()(const A1& a1) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2); } -}; - -template<typename T, - typename B1, typename B2, - typename X1, typename X2> -class BindAdapter2_mem<void, T, B1, B2, X1, X2> -{ - void (T::*m)(B1, B2); - T* t; - X1 x1; - X2 x2; -public: - template<typename T2> - BindAdapter2_mem(void (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - void operator()() { (t->*m)(x1, x2); } - - template<typename A1> - void operator()(const A1& a1) { (t->*m)(x1, x2); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2); } -}; - -template<typename R, typename T, typename T2, typename B1, typename B2, typename X1, typename X2> -BindAdapter2_mem<R, T, B1, B2, X1, X2> -Bind(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) -{ - return BindAdapter2_mem<R, T, B1, B2, X1, X2>(m, t, x1, x2); -} - -// BindAdapter3_fun -template<typename R, typename F, - typename X1, typename X2, typename X3> -class BindAdapter3_fun -{ - F f; - X1 x1; - X2 x2; - X3 x3; -public: - BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } - - R operator()() { return f(x1, x2, x3); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1, x2, x3); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2, x3); } -}; - -template<typename F, - typename X1, typename X2, typename X3> -class BindAdapter3_fun<void, F, X1, X2, X3> -{ - F f; - X1 x1; - X2 x2; - X3 x3; -public: - BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } - - void operator()() { f(x1, x2, x3); } - - template<typename A1> - void operator()(const A1& a1) { f(x1, x2, x3); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2, x3); } -}; - -template<typename R, typename F, - typename X1, typename X2, typename X3> -BindAdapter3_fun<R, F, X1, X2, X3> -Bind(const F& f, X1 x1, X2 x2, X3 x3) -{ - return BindAdapter3_fun<R, F, X1, X2, X3>(f, x1, x2, x3); -} - -// BindAdapter3_mem -template<typename R, typename T, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -class BindAdapter3_mem -{ - R (T::*m)(B1, B2, B3); - T* t; - X1 x1; - X2 x2; - X3 x3; -public: - template<typename T2> - BindAdapter3_mem(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2, X3 x3) : m(m), t(t), x1(x1), x2(x2), x3(x3) { } - - R operator()() { return (t->*m)(x1, x2, x3); } - - template<typename A1> - R operator()(const A1& a1) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2, x3); } -}; - -template<typename T, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -class BindAdapter3_mem<void, T, B1, B2, B3, X1, X2, X3> -{ - void (T::*m)(B1, B2, B3); - T* t; - X1 x1; - X2 x2; - X3 x3; -public: - template<typename T2> - BindAdapter3_mem(void (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - void operator()() { (t->*m)(x1, x2, x3); } - - template<typename A1> - void operator()(const A1& a1) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2, x3); } -}; - -template<typename R, typename T, typename T2, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3> -Bind(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) -{ - return BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>(m, t, x1, x2); -} - -// Helper class to holds references as pointers (to avoid copying the -// original object). -template<class T> -class RefWrapper -{ - T* ptr; -public: - RefWrapper(T& ref) : ptr(&ref) { } - operator T&() const { return *ptr; } -}; - -// Creates RefWrappers, useful to wrap arguments that have to be -// passed as a reference when you use Bind. -template<class T> -RefWrapper<T> Ref(T& ref) -{ - return RefWrapper<T>(ref); -} - -#endif diff --git a/Runtime/Lua/LuaBind/signal/remove_from_container.h b/Runtime/Lua/LuaBind/signal/remove_from_container.h deleted file mode 100644 index 9fdc442..0000000 --- a/Runtime/Lua/LuaBind/signal/remove_from_container.h +++ /dev/null @@ -1,32 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
-#define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
-#pragma once
-
-namespace base {
-
-// Removes all ocurrences of the specified element from the STL container.
-template<typename ContainerType>
-void remove_from_container(ContainerType& container,
- typename ContainerType::const_reference element)
-{
- for (typename ContainerType::iterator
- it = container.begin(),
- end = container.end(); it != end; ) {
- if (*it == element) {
- it = container.erase(it);
- end = container.end();
- }
- else
- ++it;
- }
-}
-
-}
-
-#endif
diff --git a/Runtime/Lua/LuaBind/signal/signal.h b/Runtime/Lua/LuaBind/signal/signal.h deleted file mode 100644 index 97882c6..0000000 --- a/Runtime/Lua/LuaBind/signal/signal.h +++ /dev/null @@ -1,451 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_SIGNAL_H_INCLUDED
-#define BASE_SIGNAL_H_INCLUDED
-#pragma once
-
-//#include "base/slot.h"
-//#include "base/remove_from_container.h"
-
-#include "./slot.h"
-#include "./remove_from_container.h"
-
-#include <vector>
-
-// Signal0_base<R> - Base class to delegate responsibility to
-// functions of zero arguments.
-template<typename R>
-class Signal0_base
-{
-public:
- typedef R ReturnType;
- typedef Slot0<R> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal0_base() { }
- Signal0_base(const Signal0_base<R>& s)
- {
- copy(s);
- }
- ~Signal0_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot0_fun<R, F>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(), T* t)
- {
- return addSlot(new Slot0_mem<R, T>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal0_base& operator=(const Signal0_base<R>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal0_base<R>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal0<R>
-template<typename R>
-class Signal0 : public Signal0_base<R>
-{
-public:
- Signal0() { }
-
- Signal0(const Signal0<R>& s)
- : Signal0_base<R>(s) { }
-
- R operator()(R default_result = R())
- {
- R result(default_result);
- typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
- for (typename Signal0_base<R>::SlotList::iterator
- it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
- typename Signal0_base<R>::SlotType* slot = *it;
- result = (*slot)();
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
- for (typename Signal0_base<R>::SlotList::iterator
- it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
- typename Signal0_base<R>::SlotType* slot = *it;
- result = merger(result, (*slot)());
- }
- return result;
- }
-
-};
-
-// Signal0<void>
-template<>
-class Signal0<void> : public Signal0_base<void>
-{
-public:
- Signal0() { }
-
- Signal0(const Signal0<void>& s)
- : Signal0_base<void>(s) { }
-
- void operator()()
- {
- SlotList::iterator end = m_slots.end();
- for (SlotList::iterator
- it = m_slots.begin(); it != end; ++it) {
- SlotType* slot = *it;
- (*slot)();
- }
- }
-
-};
-
-// Signal1_base<R, A1> - Base class to delegate responsibility to
-// functions of one argument.
-template<typename R, typename A1>
-class Signal1_base
-{
-public:
- typedef R ReturnType;
- typedef Slot1<R, A1> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal1_base() { }
- Signal1_base(const Signal1_base<R, A1>& s)
- {
- copy(s);
- }
- ~Signal1_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot1_fun<R, F, A1>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(A1), T* t)
- {
- return addSlot(new Slot1_mem<R, T, A1>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal1_base& operator=(const Signal1_base<R, A1>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal1_base<R, A1>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal1<R, A1>
-template<typename R, typename A1>
-class Signal1 : public Signal1_base<R, A1>
-{
-public:
- Signal1() { }
-
- Signal1(const Signal1<R, A1>& s)
- : Signal1_base<R, A1>(s) { }
-
- R operator()(A1 a1, R default_result = R())
- {
- R result(default_result);
- typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
- for (typename Signal1_base<R, A1>::SlotList::iterator
- it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<R, A1>::SlotType* slot = *it;
- result = (*slot)(a1);
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(A1 a1, R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
- for (typename Signal1_base<R, A1>::SlotList::iterator
- it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<R, A1>::SlotType* slot = *it;
- result = merger(result, (*slot)(a1));
- }
- return result;
- }
-
-};
-
-// Signal1<void, A1>
-template<typename A1>
-class Signal1<void, A1> : public Signal1_base<void, A1>
-{
-public:
- Signal1() { }
-
- Signal1(const Signal1<void, A1>& s)
- : Signal1_base<void, A1>(s) { }
-
- void operator()(A1 a1)
- {
- typename Signal1_base<void, A1>::SlotList::iterator end = Signal1_base<void, A1>::m_slots.end();
- for (typename Signal1_base<void, A1>::SlotList::iterator
- it = Signal1_base<void, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<void, A1>::SlotType* slot = *it;
- (*slot)(a1);
- }
- }
-
-};
-
-// Signal2_base<R, A1, A2> - Base class to delegate responsibility to
-// functions of two arguments.
-template<typename R, typename A1, typename A2>
-class Signal2_base
-{
-public:
- typedef R ReturnType;
- typedef Slot2<R, A1, A2> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal2_base() { }
- Signal2_base(const Signal2_base<R, A1, A2>& s)
- {
- copy(s);
- }
- ~Signal2_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot2_fun<R, F, A1, A2>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(A1, A2), T* t)
- {
- return addSlot(new Slot2_mem<R, T, A1, A2>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal2_base& operator=(const Signal2_base<R, A1, A2>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal2_base<R, A1, A2>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal2<R, A1>
-template<typename R, typename A1, typename A2>
-class Signal2 : public Signal2_base<R, A1, A2>
-{
-public:
- Signal2() { }
-
- Signal2(const Signal2<R, A1, A2>& s)
- : Signal2_base<R, A1, A2>(s) { }
-
- R operator()(A1 a1, A2 a2, R default_result = R())
- {
- R result(default_result);
- typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
- for (typename Signal2_base<R, A1, A2>::SlotList::iterator
- it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
- result = (*slot)(a1, a2);
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(A1 a1, A2 a2, R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
- for (typename Signal2_base<R, A1, A2>::SlotList::iterator
- it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
- result = merger(result, (*slot)(a1, a2));
- }
- return result;
- }
-
-};
-
-// Signal2<void, A1>
-template<typename A1, typename A2>
-class Signal2<void, A1, A2> : public Signal2_base<void, A1, A2>
-{
-public:
- Signal2() { }
-
- Signal2(const Signal2<void, A1, A2>& s)
- : Signal2_base<void, A1, A2>(s) { }
-
- void operator()(A1 a1, A2 a2)
- {
- typename Signal2_base<void, A1, A2>::SlotList::iterator end = Signal2_base<void, A1, A2>::m_slots.end();
- for (typename Signal2_base<void, A1, A2>::SlotList::iterator
- it = Signal2_base<void, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<void, A1, A2>::SlotType* slot = *it;
- (*slot)(a1, a2);
- }
- }
-
-};
-
-#endif
diff --git a/Runtime/Lua/LuaBind/signal/slot.h b/Runtime/Lua/LuaBind/signal/slot.h deleted file mode 100644 index 226d382..0000000 --- a/Runtime/Lua/LuaBind/signal/slot.h +++ /dev/null @@ -1,203 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_SLOT_H_INCLUDED
-#define BASE_SLOT_H_INCLUDED
-#pragma once
-
-// Slot0 - Base class for delegates of zero arguments.
-template<typename R>
-class Slot0
-{
-public:
- Slot0() { }
- Slot0(const Slot0& s) { (void)s; }
- virtual ~Slot0() { }
- virtual R operator()() = 0;
- virtual Slot0* clone() const = 0;
-};
-
-// Slot0_fun - hold a F instance and use the function call operator
-template<typename R, typename F>
-class Slot0_fun : public Slot0<R>
-{
- F f;
-public:
- Slot0_fun(const F& f) : f(f) { }
- Slot0_fun(const Slot0_fun& s) : Slot0<R>(s), f(s.f) { }
- ~Slot0_fun() { }
- R operator()() { return f(); }
- Slot0_fun* clone() const { return new Slot0_fun(*this); }
-};
-
-template<typename F>
-class Slot0_fun<void, F> : public Slot0<void>
-{
- F f;
-public:
- Slot0_fun(const F& f) : f(f) { }
- Slot0_fun(const Slot0_fun& s) : Slot0<void>(s), f(s.f) { }
- ~Slot0_fun() { }
- void operator()() { f(); }
- Slot0_fun* clone() const { return new Slot0_fun(*this); }
-};
-
-// Slot0_mem - pointer to a member function of the T class
-template<typename R, class T>
-class Slot0_mem : public Slot0<R>
-{
- R (T::*m)();
- T* t;
-public:
- Slot0_mem(R (T::*m)(), T* t) : m(m), t(t) { }
- Slot0_mem(const Slot0_mem& s) : Slot0<R>(s), m(s.m), t(s.t) { }
- ~Slot0_mem() { }
- R operator()() { return (t->*m)(); }
- Slot0_mem* clone() const { return new Slot0_mem(*this); }
-};
-
-template<class T>
-class Slot0_mem<void, T> : public Slot0<void>
-{
- void (T::*m)();
- T* t;
-public:
- Slot0_mem(void (T::*m)(), T* t) : m(m), t(t) { }
- Slot0_mem(const Slot0_mem& s) : Slot0<void>(s), m(s.m), t(s.t) { }
- ~Slot0_mem() { }
- void operator()() { (t->*m)(); }
- Slot0_mem* clone() const { return new Slot0_mem(*this); }
-};
-
-// Slot1 - Base class for delegates of one argument.
-template<typename R, typename A1>
-class Slot1
-{
-public:
- Slot1() { }
- Slot1(const Slot1& s) { (void)s; }
- virtual ~Slot1() { }
- virtual R operator()(A1 a1) = 0;
- virtual Slot1* clone() const = 0;
-};
-
-// Slot1_fun - hold a F instance and use the function call operator
-template<typename R, typename F, typename A1>
-class Slot1_fun : public Slot1<R, A1>
-{
- F f;
-public:
- Slot1_fun(const F& f) : f(f) { }
- Slot1_fun(const Slot1_fun& s) : Slot1<R, A1>(s), f(s.f) { }
- ~Slot1_fun() { }
- R operator()(A1 a1) { return f(a1); }
- Slot1_fun* clone() const { return new Slot1_fun(*this); }
-};
-
-template<typename F, typename A1>
-class Slot1_fun<void, F, A1> : public Slot1<void, A1>
-{
- F f;
-public:
- Slot1_fun(const F& f) : f(f) { }
- Slot1_fun(const Slot1_fun& s) : Slot1<void, A1>(s), f(s.f) { }
- ~Slot1_fun() { }
- void operator()(A1 a1) { f(a1); }
- Slot1_fun* clone() const { return new Slot1_fun(*this); }
-};
-
-// Slot1_mem - pointer to a member function of the T class
-template<typename R, class T, typename A1>
-class Slot1_mem : public Slot1<R, A1>
-{
- R (T::*m)(A1);
- T* t;
-public:
- Slot1_mem(R (T::*m)(A1), T* t) : m(m), t(t) { }
- Slot1_mem(const Slot1_mem& s) : Slot1<R, A1>(s), m(s.m), t(s.t) { }
- ~Slot1_mem() { }
- R operator()(A1 a1) { return (t->*m)(a1); }
- Slot1_mem* clone() const { return new Slot1_mem(*this); }
-};
-
-template<class T, typename A1>
-class Slot1_mem<void, T, A1> : public Slot1<void, A1>
-{
- void (T::*m)(A1);
- T* t;
-public:
- Slot1_mem(void (T::*m)(A1), T* t) : m(m), t(t) { }
- Slot1_mem(const Slot1_mem& s) : Slot1<void, A1>(s), m(s.m), t(s.t) { }
- ~Slot1_mem() { }
- void operator()(A1 a1) { (t->*m)(a1); }
- Slot1_mem* clone() const { return new Slot1_mem(*this); }
-};
-
-// Slot2 - Base class for delegates of two arguments.
-template<typename R, typename A1, typename A2>
-class Slot2
-{
-public:
- Slot2() { }
- Slot2(const Slot2& s) { (void)s; }
- virtual ~Slot2() { }
- virtual R operator()(A1 a1, A2 a2) = 0;
- virtual Slot2* clone() const = 0;
-};
-
-// Slot2_fun - hold a F instance and use the function call operator
-template<typename R, typename F, typename A1, typename A2>
-class Slot2_fun : public Slot2<R, A1, A2>
-{
- F f;
-public:
- Slot2_fun(const F& f) : f(f) { }
- Slot2_fun(const Slot2_fun& s) : Slot2<R, A1, A2>(s), f(s.f) { }
- ~Slot2_fun() { }
- R operator()(A1 a1, A2 a2) { return f(a1, a2); }
- Slot2_fun* clone() const { return new Slot2_fun(*this); }
-};
-
-template<typename F, typename A1, typename A2>
-class Slot2_fun<void, F, A1, A2> : public Slot2<void, A1, A2>
-{
- F f;
-public:
- Slot2_fun(const F& f) : f(f) { }
- Slot2_fun(const Slot2_fun& s) : Slot2<void, A1, A2>(s), f(s.f) { }
- ~Slot2_fun() { }
- void operator()(A1 a1, A2 a2) { f(a1, a2); }
- Slot2_fun* clone() const { return new Slot2_fun(*this); }
-};
-
-// Slot2_mem - pointer to a member function of the T class
-template<typename R, class T, typename A1, typename A2>
-class Slot2_mem : public Slot2<R, A1, A2>
-{
- R (T::*m)(A1, A2);
- T* t;
-public:
- Slot2_mem(R (T::*m)(A1, A2), T* t) : m(m), t(t) { }
- Slot2_mem(const Slot2_mem& s) : Slot2<R, A1, A2>(s), m(s.m), t(s.t) { }
- ~Slot2_mem() { }
- R operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
- Slot2_mem* clone() const { return new Slot2_mem(*this); }
-};
-
-template<class T, typename A1, typename A2>
-class Slot2_mem<void, T, A1, A2> : public Slot2<void, A1, A2>
-{
- void (T::*m)(A1, A2);
- T* t;
-public:
- Slot2_mem(void (T::*m)(A1, A2), T* t) : m(m), t(t) { }
- Slot2_mem(const Slot2_mem& s) : Slot2<void, A1, A2>(s), m(s.m), t(s.t) { }
- ~Slot2_mem() { }
- void operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
- Slot2_mem* clone() const { return new Slot2_mem(*this); }
-};
-
-#endif
|