This class represents the state of a script: the underlying Lua state, pending coroutines, metatables for C++ class hierarchies, etc. More...
#include "UniScriptState.hpp"
Public Member Functions | |
UniScriptStateT () | |
The constructor. More... | |
~UniScriptStateT () | |
The destructor. More... | |
bool | DoString (const char *s, const char *Signature="",...) |
Loads the given string as a Lua chunk, then runs it. More... | |
bool | DoFile (const char *FileName, const char *Signature="",...) |
Loads the given file as a Lua chunk, then runs it. More... | |
bool | Call (const char *FuncName, const char *Signature="",...) |
Calls the global script function with the given name. More... | |
template<class T > | |
bool | CallMethod (T Object, const std::string &MethodName, const char *Signature="",...) |
Calls a method with the given name of the given object. More... | |
template<class T > | |
bool | CallMethod_Impl (T Object, const std::string &MethodName, int NumExtraArgs, const char *Signature, va_list vl) |
Like CallMethod() above, but the arguments and results are passed via vl rather than "...", and if any extra arguments have been pushed on the stack, their number must be given. More... | |
void | RunPendingCoroutines (float FrameTime) |
Runs the pending coroutines. More... | |
lua_State * | GetLuaState () |
Returns the Lua state that implements this script state. More... | |
This class represents the state of a script: the underlying Lua state, pending coroutines, metatables for C++ class hierarchies, etc.
Its main features are:
UniScriptStateT::UniScriptStateT | ( | ) |
The constructor.
UniScriptStateT::~UniScriptStateT | ( | ) |
The destructor.
bool UniScriptStateT::Call | ( | const char * | FuncName, |
const char * | Signature = "" , |
||
... | |||
) |
Calls the global script function with the given name.
FuncName | The name of the global script function to be called. |
Signature | Describes the arguments to and results from the Lua function. See below for more details. |
... | The arguments to the Lua function and the variables that receive its results as described by the Signature parameter. |
The Signature parameter is a string of individual letters, where each letter represents a variable and its type. The letters 'b' for bool, 'i' for int, 'f' for float, 'd' for double and 's' for const char* (string) can be used. A '>' separates the arguments from the results, and is optional if the function returns no results. For the results, additionally to the other letters, 'S' can be used for (address of) std::string.
|
inline |
Calls a method with the given name of the given object.
Object | The object whose script method is to be called. |
MethodName | The name of the method to be called. |
Signature | Describes the arguments to and results from the Lua method. |
... | The arguments to the Lua method and the variables that receive its results as described by the Signature parameter. |
For more details about the parameters and return value, see Call().
Example: If the variable Obj is bound to Object, then CallMethod(Object, "OnTrigger", "f", 1.0); calls the script method Obj:OnTrigger(value) where value is a number with value 1.0.
|
inline |
Like CallMethod() above, but the arguments and results are passed via vl rather than "...", and if any extra arguments have been pushed on the stack, their number must be given.
Note that the "extra arguments" are a work-around that was not necessary if we could use variadic templates for the implementation of CallMethod().
bool UniScriptStateT::DoFile | ( | const char * | FileName, |
const char * | Signature = "" , |
||
... | |||
) |
Loads the given file as a Lua chunk, then runs it.
bool UniScriptStateT::DoString | ( | const char * | s, |
const char * | Signature = "" , |
||
... | |||
) |
Loads the given string as a Lua chunk, then runs it.
(This acts very much like the stand-alone Lua interpreter.)
|
inline |
Returns the Lua state that implements this script state.
void UniScriptStateT::RunPendingCoroutines | ( | float | FrameTime | ) |
Runs the pending coroutines.