From de46b91a524c5f2c8e72b379f2900afe34ccb815 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 11 Nov 2021 10:29:17 +0800 Subject: *misc --- Runtime/Lua/LuaBind/LuaBindLFunction.cpp | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Runtime/Lua/LuaBind/LuaBindLFunction.cpp (limited to 'Runtime/Lua/LuaBind/LuaBindLFunction.cpp') diff --git a/Runtime/Lua/LuaBind/LuaBindLFunction.cpp b/Runtime/Lua/LuaBind/LuaBindLFunction.cpp new file mode 100644 index 0000000..b468897 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindLFunction.cpp @@ -0,0 +1,63 @@ +#include "LuaBindLFunction.h" +#include "LuaBindHelper.h" + +namespace LuaBind +{ + + LuaFunction::LuaFunction(const char* func) + { + method = func; + } + + void LuaFunction::operator = (const char* func) + { + method = func; + } + + void LuaFunction::AddInt(State& state, int n) + { + state.Push(n); + ++argc; + } + + void LuaFunction::AddFloat(State& state, float n) + { + state.Push(n); + ++argc; + } + + void LuaFunction::AddNil(State& state) + { + state.PushNil(); + ++argc; + } + + void LuaFunction::AddBool(State& state, bool b) + { + state.Push(b); + ++argc; + } + + void LuaFunction::AddString(State& state, const char* str) + { + state.Push(str); + ++argc; + } + + void LuaFunction::AddTable(State& state, INativeTable& tb) + { + tb.CastToTable(state); + ++argc; + } + + void LuaFunction::Invoke(State& state, int nReturns) + { + if (state.GetGlobalField(method)) + { + int funcIdx = -1 - argc; + lua_replace(state, funcIdx); + state.Call(argc, nReturns); + } + } + +} \ No newline at end of file -- cgit v1.1-26-g67d0