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/LuaBindInvoker.cpp | |
parent | efce5b6bd5c9d4f8214a71e0f7a7c35751710a4c (diff) |
*misc
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindInvoker.cpp')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
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); + } + +} |