Otclient
14/8/2020
|
Class that manages LUA stuff. More...
#include <luainterface.h>
Public Member Functions | |
LuaInterface () | |
~LuaInterface () | |
void | init () |
void | terminate () |
void | registerFunctions () |
Register core script functions. More... | |
void | registerSingletonClass (const std::string &className) |
void | registerClass (const std::string &className, const std::string &baseClass="LuaObject") |
void | registerClassStaticFunction (const std::string &className, const std::string &functionName, const LuaCppFunction &function) |
void | registerClassMemberFunction (const std::string &className, const std::string &functionName, const LuaCppFunction &function) |
void | registerClassMemberField (const std::string &className, const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction) |
void | registerGlobalFunction (const std::string &functionName, const LuaCppFunction &function) |
template<class C , class B = LuaObject> | |
void | registerClass () |
template<class C > | |
void | registerClassStaticFunction (const std::string &functionName, const LuaCppFunction &function) |
template<class C > | |
void | registerClassMemberFunction (const std::string &functionName, const LuaCppFunction &function) |
template<class C > | |
void | registerClassMemberField (const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction) |
template<class C , typename F > | |
void | bindSingletonFunction (const std::string &functionName, F C::*function, C *instance) |
template<class C , typename F > | |
void | bindSingletonFunction (const std::string &className, const std::string &functionName, F C::*function, C *instance) |
template<class C , typename F > | |
void | bindClassStaticFunction (const std::string &functionName, const F &function) |
template<typename F > | |
void | bindClassStaticFunction (const std::string &className, const std::string &functionName, const F &function) |
template<class C , typename F , class FC > | |
void | bindClassMemberFunction (const std::string &functionName, F FC::*function) |
template<class C , typename F , class FC > | |
void | bindClassMemberFunction (const std::string &className, const std::string &functionName, F FC::*function) |
template<class C , typename F1 , typename F2 , class FC > | |
void | bindClassMemberField (const std::string &fieldName, F1 FC::*getFunction, F2 FC::*setFunction) |
template<class C , typename F1 , typename F2 , class FC > | |
void | bindClassMemberField (const std::string &className, const std::string &fieldName, F1 FC::*getFunction, F2 FC::*setFunction) |
template<class C , typename F , class FC > | |
void | bindClassMemberGetField (const std::string &fieldName, F FC::*getFunction) |
template<class C , typename F , class FC > | |
void | bindClassMemberGetField (const std::string &className, const std::string &fieldName, F FC::*getFunction) |
template<class C , typename F , class FC > | |
void | bindClassMemberSetField (const std::string &fieldName, F FC::*setFunction) |
template<class C , typename F , class FC > | |
void | bindClassMemberSetField (const std::string &className, const std::string &fieldName, F FC::*setFunction) |
template<typename F > | |
void | bindGlobalFunction (const std::string &functionName, const F &function) |
bool | safeRunScript (const std::string &fileName) |
Loads and runs a script, any errors are printed to stdout and returns false. More... | |
void | runScript (const std::string &fileName) |
void | runBuffer (const std::string &buffer, const std::string &source) |
void | loadScript (const std::string &fileName) |
void | loadFunction (const std::string &buffer, const std::string &source="lua function buffer") |
void | evaluateExpression (const std::string &expression, const std::string &source="lua expression") |
std::string | traceback (const std::string &errorMessage="", int level=0) |
void | throwError (const std::string &message) |
std::string | getCurrentSourcePath (int level=0) |
Searches for the source of the current running function. More... | |
int | safeCall (int numArgs=0, int numRets=-1) |
Calls a function The function and arguments must be on top of the stack in order, results are pushed onto the stack. More... | |
int | signalCall (int numArgs=0, int numRets=-1) |
int | newSandboxEnv () |
Creates a new environment table The new environment table is redirected to the global environment (aka _G), this allows to access global variables from _G in the new environment and prevents new variables in this new environment to be set on the global environment. More... | |
template<typename... T> | |
int | luaCallGlobalField (const std::string &global, const std::string &field, const T &... args) |
template<typename... T> | |
void | callGlobalField (const std::string &global, const std::string &field, const T &... args) |
template<typename R , typename... T> | |
R | callGlobalField (const std::string &global, const std::string &field, const T &... args) |
bool | isInCppCallback () |
void | createLuaState () |
void | closeLuaState () |
void | collectGarbage () |
void | loadBuffer (const std::string &buffer, const std::string &source) |
int | pcall (int numArgs=0, int numRets=0, int errorFuncIndex=0) |
void | call (int numArgs=0, int numRets=0) |
void | error () |
int | ref () |
int | weakRef () |
void | unref (int ref) |
void | useValue () |
const char * | typeName (int index=-1) |
std::string | functionSourcePath () |
void | insert (int index) |
void | remove (int index) |
bool | next (int index=-2) |
void | checkStack () |
void | getStackFunction (int level=0) |
void | getRef (int ref) |
void | getWeakRef (int weakRef) |
int | getGlobalEnvironment () |
void | setGlobalEnvironment (int env) |
void | resetGlobalEnvironment () |
void | setMetatable (int index=-2) |
void | getMetatable (int index=-1) |
void | getField (const char *key, int index=-1) |
void | getField (const std::string &key, int index=-1) |
void | setField (const char *key, int index=-2) |
void | setField (const std::string &key, int index=-2) |
void | getTable (int index=-2) |
void | setTable (int index=-3) |
void | clearTable (int index=-1) |
void | getEnv (int index=-1) |
void | setEnv (int index=-2) |
void | getGlobal (const std::string &key) |
void | getGlobalField (const std::string &globalKey, const std::string &fieldKey) |
void | setGlobal (const std::string &key) |
void | rawGet (int index=-1) |
void | rawGeti (int n, int index=-1) |
void | rawSet (int index=-3) |
void | rawSeti (int n, int index=-2) |
void | newTable () |
void | createTable (int narr, int nrec) |
void * | newUserdata (int size) |
void | pop (int n=1) |
long | popInteger () |
double | popNumber () |
bool | popBoolean () |
std::string | popString () |
void * | popUserdata () |
void * | popUpvalueUserdata () |
LuaObjectPtr | popObject () |
void | pushNil () |
void | pushInteger (long v) |
void | pushNumber (double v) |
void | pushBoolean (bool v) |
void | pushCString (const char *v) |
void | pushString (const std::string &v) |
void | pushLightUserdata (void *p) |
void | pushThread () |
void | pushValue (int index=-1) |
void | pushObject (const LuaObjectPtr &obj) |
void | pushCFunction (LuaCFunction func, int n=0) |
void | pushCppFunction (const LuaCppFunction &func) |
bool | isNil (int index=-1) |
bool | isBoolean (int index=-1) |
bool | isNumber (int index=-1) |
bool | isString (int index=-1) |
bool | isTable (int index=-1) |
bool | isFunction (int index=-1) |
bool | isCFunction (int index=-1) |
bool | isLuaFunction (int index=-1) |
bool | isUserdata (int index=-1) |
bool | toBoolean (int index=-1) |
int | toInteger (int index=-1) |
double | toNumber (int index=-1) |
const char * | toCString (int index=-1) |
std::string | toString (int index=-1) |
void * | toUserdata (int index=-1) |
LuaObjectPtr | toObject (int index=-1) |
int | getTop () |
int | stackSize () |
void | clearStack () |
bool | hasIndex (int index) |
void | loadFiles (std::string directory, bool recursive=false, std::string contains="") |
template<typename T , typename... Args> | |
int | polymorphicPush (const T &v, const Args &... args) |
Pushes any type onto the stack. More... | |
int | polymorphicPush () |
template<class T > | |
T | castValue (int index=-1) |
template<class T > | |
T | polymorphicPop () |
Same as castValue but also pops. More... | |
Class that manages LUA stuff.
Definition at line 32 of file luainterface.h.
LuaInterface::LuaInterface | ( | ) |
Definition at line 33 of file luainterface.cpp.
LuaInterface::~LuaInterface | ( | ) |
Definition at line 42 of file luainterface.cpp.
void LuaInterface::bindClassMemberField | ( | const std::string & | className, |
const std::string & | fieldName, | ||
F1 FC::* | getFunction, | ||
F2 FC::* | setFunction | ||
) |
void LuaInterface::bindClassMemberField | ( | const std::string & | fieldName, |
F1 FC::* | getFunction, | ||
F2 FC::* | setFunction | ||
) |
Definition at line 394 of file luainterface.h.
void LuaInterface::bindClassMemberFunction | ( | const std::string & | className, |
const std::string & | functionName, | ||
F FC::* | function | ||
) |
void LuaInterface::bindClassMemberFunction | ( | const std::string & | functionName, |
F FC::* | function | ||
) |
void LuaInterface::bindClassMemberGetField | ( | const std::string & | className, |
const std::string & | fieldName, | ||
F FC::* | getFunction | ||
) |
void LuaInterface::bindClassMemberGetField | ( | const std::string & | fieldName, |
F FC::* | getFunction | ||
) |
Definition at line 403 of file luainterface.h.
void LuaInterface::bindClassMemberSetField | ( | const std::string & | className, |
const std::string & | fieldName, | ||
F FC::* | setFunction | ||
) |
void LuaInterface::bindClassMemberSetField | ( | const std::string & | fieldName, |
F FC::* | setFunction | ||
) |
Definition at line 412 of file luainterface.h.
void LuaInterface::bindClassStaticFunction | ( | const std::string & | className, |
const std::string & | functionName, | ||
const F & | function | ||
) |
void LuaInterface::bindClassStaticFunction | ( | const std::string & | functionName, |
const F & | function | ||
) |
Definition at line 376 of file luainterface.h.
void LuaInterface::bindGlobalFunction | ( | const std::string & | functionName, |
const F & | function | ||
) |
Definition at line 421 of file luainterface.h.
void LuaInterface::bindSingletonFunction | ( | const std::string & | className, |
const std::string & | functionName, | ||
F C::* | function, | ||
C * | instance | ||
) |
void LuaInterface::bindSingletonFunction | ( | const std::string & | functionName, |
F C::* | function, | ||
C * | instance | ||
) |
Definition at line 366 of file luainterface.h.
void LuaInterface::call | ( | int | numArgs = 0 , |
int | numRets = 0 |
||
) |
Definition at line 744 of file luainterface.cpp.
void LuaInterface::callGlobalField | ( | const std::string & | global, |
const std::string & | field, | ||
const T &... | args | ||
) |
R LuaInterface::callGlobalField | ( | const std::string & | global, |
const std::string & | field, | ||
const T &... | args | ||
) |
T LuaInterface::castValue | ( | int | index = -1 | ) |
Casts a value from stack to any type
LuaBadValueCastException | thrown if the cast fails |
Definition at line 426 of file luainterface.h.
|
inline |
Definition at line 242 of file luainterface.h.
|
inline |
Definition at line 322 of file luainterface.h.
void LuaInterface::clearTable | ( | int | index = -1 | ) |
Definition at line 918 of file luainterface.cpp.
void LuaInterface::closeLuaState | ( | ) |
void LuaInterface::collectGarbage | ( | ) |
void LuaInterface::createLuaState | ( | ) |
Definition at line 664 of file luainterface.cpp.
void LuaInterface::createTable | ( | int | narr, |
int | nrec | ||
) |
void LuaInterface::error | ( | ) |
Definition at line 750 of file luainterface.cpp.
void LuaInterface::evaluateExpression | ( | const std::string & | expression, |
const std::string & | source = "lua expression" |
||
) |
Evaluates a lua expression and pushes the result value onto the stack
LuaException | is thrown on any lua error |
Definition at line 362 of file luainterface.cpp.
std::string LuaInterface::functionSourcePath | ( | ) |
std::string LuaInterface::getCurrentSourcePath | ( | int | level = 0 | ) |
Searches for the source of the current running function.
Definition at line 405 of file luainterface.cpp.
void LuaInterface::getEnv | ( | int | index = -1 | ) |
Definition at line 894 of file luainterface.cpp.
void LuaInterface::getField | ( | const char * | key, |
int | index = -1 |
||
) |
Definition at line 880 of file luainterface.cpp.
|
inline |
Definition at line 256 of file luainterface.h.
void LuaInterface::getGlobal | ( | const std::string & | key | ) |
|
inline |
void LuaInterface::getGlobalField | ( | const std::string & | globalKey, |
const std::string & | fieldKey | ||
) |
Definition at line 944 of file luainterface.cpp.
void LuaInterface::getMetatable | ( | int | index = -1 | ) |
void LuaInterface::getRef | ( | int | ref | ) |
Definition at line 846 of file luainterface.cpp.
void LuaInterface::getStackFunction | ( | int | level = 0 | ) |
Definition at line 837 of file luainterface.cpp.
void LuaInterface::getTable | ( | int | index = -2 | ) |
int LuaInterface::getTop | ( | ) |
void LuaInterface::getWeakRef | ( | int | weakRef | ) |
Definition at line 851 of file luainterface.cpp.
|
inline |
Definition at line 323 of file luainterface.h.
void LuaInterface::init | ( | ) |
Definition at line 46 of file luainterface.cpp.
void LuaInterface::insert | ( | int | index | ) |
Definition at line 819 of file luainterface.cpp.
bool LuaInterface::isBoolean | ( | int | index = -1 | ) |
Definition at line 1156 of file luainterface.cpp.
bool LuaInterface::isCFunction | ( | int | index = -1 | ) |
Definition at line 1186 of file luainterface.cpp.
bool LuaInterface::isFunction | ( | int | index = -1 | ) |
Definition at line 1180 of file luainterface.cpp.
|
inline |
|
inline |
Definition at line 309 of file luainterface.h.
bool LuaInterface::isNil | ( | int | index = -1 | ) |
Definition at line 1150 of file luainterface.cpp.
bool LuaInterface::isNumber | ( | int | index = -1 | ) |
Definition at line 1162 of file luainterface.cpp.
bool LuaInterface::isString | ( | int | index = -1 | ) |
Definition at line 1168 of file luainterface.cpp.
bool LuaInterface::isTable | ( | int | index = -1 | ) |
Definition at line 1174 of file luainterface.cpp.
bool LuaInterface::isUserdata | ( | int | index = -1 | ) |
Definition at line 1192 of file luainterface.cpp.
void LuaInterface::loadBuffer | ( | const std::string & | buffer, |
const std::string & | source | ||
) |
Definition at line 730 of file luainterface.cpp.
void LuaInterface::loadFiles | ( | std::string | directory, |
bool | recursive = false , |
||
std::string | contains = "" |
||
) |
void LuaInterface::loadFunction | ( | const std::string & | buffer, |
const std::string & | source = "lua function buffer" |
||
) |
Loads a function from buffer and pushes it onto stack,
LuaException | is thrown on any lua error |
Definition at line 338 of file luainterface.cpp.
void LuaInterface::loadScript | ( | const std::string & | fileName | ) |
Loads a script file and pushes it's main function onto stack,
LuaException | is thrown on any lua error |
Definition at line 324 of file luainterface.cpp.
int LuaInterface::luaCallGlobalField | ( | const std::string & | global, |
const std::string & | field, | ||
const T &... | args | ||
) |
Definition at line 434 of file luainterface.h.
int LuaInterface::newSandboxEnv | ( | ) |
Creates a new environment table The new environment table is redirected to the global environment (aka _G), this allows to access global variables from _G in the new environment and prevents new variables in this new environment to be set on the global environment.
Definition at line 536 of file luainterface.cpp.
void LuaInterface::newTable | ( | ) |
void * LuaInterface::newUserdata | ( | int | size | ) |
bool LuaInterface::next | ( | int | index = -2 | ) |
Definition at line 831 of file luainterface.cpp.
int LuaInterface::pcall | ( | int | numArgs = 0 , |
int | numRets = 0 , |
||
int | errorFuncIndex = 0 |
||
) |
Definition at line 738 of file luainterface.cpp.
|
inline |
Same as castValue but also pops.
Definition at line 339 of file luainterface.h.
|
inline |
int LuaInterface::polymorphicPush | ( | const T & | v, |
const Args &... | args | ||
) |
Pushes any type onto the stack.
Definition at line 358 of file luainterface.h.
void LuaInterface::pop | ( | int | n = 1 | ) |
Definition at line 999 of file luainterface.cpp.
bool LuaInterface::popBoolean | ( | ) |
Definition at line 1023 of file luainterface.cpp.
long LuaInterface::popInteger | ( | ) |
Definition at line 1007 of file luainterface.cpp.
double LuaInterface::popNumber | ( | ) |
LuaObjectPtr LuaInterface::popObject | ( | ) |
Definition at line 1047 of file luainterface.cpp.
std::string LuaInterface::popString | ( | ) |
Definition at line 1031 of file luainterface.cpp.
void * LuaInterface::popUpvalueUserdata | ( | ) |
Definition at line 1055 of file luainterface.cpp.
void * LuaInterface::popUserdata | ( | ) |
void LuaInterface::pushBoolean | ( | bool | v | ) |
Definition at line 1078 of file luainterface.cpp.
void LuaInterface::pushCFunction | ( | LuaCFunction | func, |
int | n = 0 |
||
) |
Definition at line 1121 of file luainterface.cpp.
void LuaInterface::pushCppFunction | ( | const LuaCppFunction & | func | ) |
Definition at line 1127 of file luainterface.cpp.
void LuaInterface::pushCString | ( | const char * | v | ) |
Definition at line 1084 of file luainterface.cpp.
void LuaInterface::pushInteger | ( | long | v | ) |
Definition at line 1066 of file luainterface.cpp.
void LuaInterface::pushLightUserdata | ( | void * | p | ) |
void LuaInterface::pushNil | ( | ) |
Definition at line 1060 of file luainterface.cpp.
void LuaInterface::pushNumber | ( | double | v | ) |
Definition at line 1072 of file luainterface.cpp.
void LuaInterface::pushObject | ( | const LuaObjectPtr & | obj | ) |
Definition at line 1109 of file luainterface.cpp.
void LuaInterface::pushString | ( | const std::string & | v | ) |
Definition at line 1091 of file luainterface.cpp.
void LuaInterface::pushThread | ( | ) |
Definition at line 1103 of file luainterface.cpp.
void LuaInterface::pushValue | ( | int | index = -1 | ) |
Definition at line 1143 of file luainterface.cpp.
void LuaInterface::rawGet | ( | int | index = -1 | ) |
void LuaInterface::rawGeti | ( | int | n, |
int | index = -1 |
||
) |
Definition at line 966 of file luainterface.cpp.
void LuaInterface::rawSet | ( | int | index = -3 | ) |
Definition at line 972 of file luainterface.cpp.
void LuaInterface::rawSeti | ( | int | n, |
int | index = -2 |
||
) |
Definition at line 978 of file luainterface.cpp.
int LuaInterface::ref | ( | ) |
|
inline |
Definition at line 66 of file luainterface.h.
void LuaInterface::registerClass | ( | const std::string & | className, |
const std::string & | baseClass = "LuaObject" |
||
) |
Definition at line 87 of file luainterface.cpp.
void LuaInterface::registerClassMemberField | ( | const std::string & | className, |
const std::string & | field, | ||
const LuaCppFunction & | getFunction, | ||
const LuaCppFunction & | setFunction | ||
) |
Definition at line 167 of file luainterface.cpp.
|
inline |
void LuaInterface::registerClassMemberFunction | ( | const std::string & | className, |
const std::string & | functionName, | ||
const LuaCppFunction & | function | ||
) |
Definition at line 157 of file luainterface.cpp.
|
inline |
void LuaInterface::registerClassStaticFunction | ( | const std::string & | className, |
const std::string & | functionName, | ||
const LuaCppFunction & | function | ||
) |
Definition at line 150 of file luainterface.cpp.
|
inline |
void LuaInterface::registerFunctions | ( | ) |
Register core script functions.
void LuaInterface::registerGlobalFunction | ( | const std::string & | functionName, |
const LuaCppFunction & | function | ||
) |
Definition at line 187 of file luainterface.cpp.
void LuaInterface::registerSingletonClass | ( | const std::string & | className | ) |
Definition at line 79 of file luainterface.cpp.
void LuaInterface::remove | ( | int | index | ) |
Definition at line 825 of file luainterface.cpp.
|
inline |
Definition at line 250 of file luainterface.h.
void LuaInterface::runBuffer | ( | const std::string & | buffer, |
const std::string & | source | ||
) |
Loads and runs the script from buffer
LuaException | is thrown on any lua error |
Definition at line 318 of file luainterface.cpp.
void LuaInterface::runScript | ( | const std::string & | fileName | ) |
Loads and runs a script
LuaException | is thrown on any lua error |
Definition at line 312 of file luainterface.cpp.
int LuaInterface::safeCall | ( | int | numArgs = 0 , |
int | numRets = -1 |
||
) |
Calls a function The function and arguments must be on top of the stack in order, results are pushed onto the stack.
LuaException | is thrown on any lua error |
Definition at line 432 of file luainterface.cpp.
bool LuaInterface::safeRunScript | ( | const std::string & | fileName | ) |
Loads and runs a script, any errors are printed to stdout and returns false.
Definition at line 301 of file luainterface.cpp.
void LuaInterface::setEnv | ( | int | index = -2 | ) |
Definition at line 900 of file luainterface.cpp.
void LuaInterface::setField | ( | const char * | key, |
int | index = -2 |
||
) |
Definition at line 887 of file luainterface.cpp.
|
inline |
Definition at line 258 of file luainterface.h.
void LuaInterface::setGlobal | ( | const std::string & | key | ) |
Definition at line 954 of file luainterface.cpp.
void LuaInterface::setGlobalEnvironment | ( | int | env | ) |
Definition at line 859 of file luainterface.cpp.
void LuaInterface::setMetatable | ( | int | index = -2 | ) |
Definition at line 868 of file luainterface.cpp.
void LuaInterface::setTable | ( | int | index = -3 | ) |
int LuaInterface::signalCall | ( | int | numArgs = 0 , |
int | numRets = -1 |
||
) |
Same as safeCall but catches exceptions and can also calls a table of functions, if any error occurs it will be reported to stdout and returns 0 results
requestedResults | is the number of results requested to pushes onto the stack, if supplied, the call will always pushes that number of results, even if it fails |
Definition at line 468 of file luainterface.cpp.
|
inline |
Definition at line 321 of file luainterface.h.
void LuaInterface::terminate | ( | ) |
Definition at line 71 of file luainterface.cpp.
void LuaInterface::throwError | ( | const std::string & | message | ) |
Throw a lua error if inside a lua call or generates an C++ stdext::exception
message | is the error message wich will be displayed before the error traceback |
stdext::exception | is thrown with the error message if the error is not captured by lua |
Definition at line 396 of file luainterface.cpp.
bool LuaInterface::toBoolean | ( | int | index = -1 | ) |
Definition at line 1198 of file luainterface.cpp.
const char * LuaInterface::toCString | ( | int | index = -1 | ) |
int LuaInterface::toInteger | ( | int | index = -1 | ) |
Definition at line 1204 of file luainterface.cpp.
double LuaInterface::toNumber | ( | int | index = -1 | ) |
Definition at line 1210 of file luainterface.cpp.
LuaObjectPtr LuaInterface::toObject | ( | int | index = -1 | ) |
Definition at line 1239 of file luainterface.cpp.
std::string LuaInterface::toString | ( | int | index = -1 | ) |
Definition at line 1222 of file luainterface.cpp.
void * LuaInterface::toUserdata | ( | int | index = -1 | ) |
Definition at line 1233 of file luainterface.cpp.
std::string LuaInterface::traceback | ( | const std::string & | errorMessage = "" , |
int | level = 0 |
||
) |
Generates a traceback message for the current call stack
errorMessage | is an additional error message |
level | is the level of the traceback, 0 means trace from calling function |
Definition at line 380 of file luainterface.cpp.
const char * LuaInterface::typeName | ( | int | index = -1 | ) |
Definition at line 792 of file luainterface.cpp.
void LuaInterface::unref | ( | int | ref | ) |
Definition at line 786 of file luainterface.cpp.
|
inline |
int LuaInterface::weakRef | ( | ) |
Definition at line 764 of file luainterface.cpp.