From 138d3f4d3d6e2aaf5ba34f89af15ef85ea074357 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 8 Nov 2021 09:23:38 +0800 Subject: *misc --- Runtime/Lua/LuaBind/LuaBindInvoker.cpp | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Runtime/Lua/LuaBind/LuaBindInvoker.cpp (limited to 'Runtime/Lua/LuaBind/LuaBindInvoker.cpp') 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); + } + +} -- cgit v1.1-26-g67d0