From d4aff474c29d3d9b1a524cfcd5fca925dab79c5b Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 21 Aug 2016 11:03:10 +0200 Subject: cLuaState: Added template to push multiple values in a single call. (#3331) --- src/Bindings/LuaState.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/Bindings/LuaState.h') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4def2c663..60ae840b0 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -12,11 +12,12 @@ If owning a state, trying to attach a state will automatically close the previou Calling a Lua function is done internally by pushing the function using PushFunction(), then pushing the arguments and finally executing CallFunction(). cLuaState automatically keeps track of the number of arguments and the name of the function (for logging purposes). After the call the return values are read from -the stack using GetStackValue(). All of this is wrapped in a templated function overloads cLuaState::Call(), -which is generated automatically by gen_LuaState_Call.lua script file into the LuaState_Call.inc file. +the stack using GetStackValue(). All of this is wrapped in a templated function overloads cLuaState::Call(). Reference management is provided by the cLuaState::cRef class. This is used when you need to hold a reference to -any Lua object across several function calls. The class is RAII-like, with automatic resource management. +any Lua object across several function calls. The class is RAII-like, with automatic resource management. Note +that the cRef object is not inherently thread-safe and is not notified when its cLuaState is closed. For those +purposes, cTrackedRef can be used. Callbacks management is provided by the cLuaState::cCallback class. Use a GetStackValue() with cCallbackPtr parameter to store the callback, and then at any time you can use the cCallback's Call() templated function @@ -462,6 +463,14 @@ public: /** Returns true if a_FunctionName is a valid Lua function that can be called */ bool HasFunction(const char * a_FunctionName); + /** Pushes multiple arguments onto the Lua stack. */ + template + void Push(Arg1 && a_Arg1, Arg2 && a_Arg2, Args &&... a_Args) + { + Push(std::forward(a_Arg1)); + Push(std::forward(a_Arg2), std::forward(a_Args)...); + } + void PushNil(void); // Push a const value onto the stack (keep alpha-sorted): -- cgit v1.2.3