Go to the documentation of this file.
23 #ifndef LUAINTERFACE_H
24 #define LUAINTERFACE_H
46 void registerClass(
const std::string& className,
const std::string& baseClass =
"LuaObject");
49 const std::string& functionName,
53 const std::string& functionName,
57 const std::string& field,
65 template<
class C,
class B = LuaObject>
67 registerClass(stdext::demangle_class<C>(), stdext::demangle_class<B>());
88 template<
class C,
typename F>
90 template<
class C,
typename F>
91 void bindSingletonFunction(
const std::string& className,
const std::string& functionName, F C::*
function, C *instance);
93 template<
class C,
typename F>
98 template<
class C,
typename F,
class FC>
100 template<
class C,
typename F,
class FC>
103 template<
class C,
typename F1,
typename F2,
class FC>
104 void bindClassMemberField(
const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction);
105 template<
class C,
typename F1,
typename F2,
class FC>
106 void bindClassMemberField(
const std::string& className,
const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction);
108 template<
class C,
typename F,
class FC>
110 template<
class C,
typename F,
class FC>
113 template<
class C,
typename F,
class FC>
115 template<
class C,
typename F,
class FC>
140 void runScript(
const std::string& fileName);
144 void runBuffer(
const std::string& buffer,
const std::string& source);
152 void loadFunction(
const std::string& buffer,
const std::string& source =
"lua function buffer");
156 void evaluateExpression(
const std::string& expression,
const std::string& source =
"lua expression");
162 std::string
traceback(
const std::string& errorMessage =
"",
int level = 0);
177 int safeCall(
int numArgs = 0,
int numRets = -1);
183 int signalCall(
int numArgs = 0,
int numRets = -1);
191 template<
typename... T>
192 int luaCallGlobalField(
const std::string& global,
const std::string& field,
const T&... args);
194 template<
typename... T>
195 void callGlobalField(
const std::string& global,
const std::string& field,
const T&... args);
197 template<
typename R,
typename... T>
198 R
callGlobalField(
const std::string& global,
const std::string& field,
const T&... args);
204 static int luaScriptLoader(lua_State* L);
206 static int lua_dofile(lua_State* L);
208 static int lua_dofiles(lua_State* L);
210 static int lua_loadfile(lua_State* L);
212 static int luaErrorHandler(lua_State* L);
214 static int luaCppFunctionCallback(lua_State* L);
216 static int luaCollectCppFunction(lua_State* L);
224 void loadBuffer(
const std::string& buffer,
const std::string& source);
226 int pcall(
int numArgs = 0,
int numRets = 0,
int errorFuncIndex = 0);
227 void call(
int numArgs = 0,
int numRets = 0);
235 const char*
typeName(
int index = -1);
240 bool next(
int index = -2);
255 void getField(
const char* key,
int index = -1);
256 void getField(
const std::string& key,
int index = -1) {
return getField(key.c_str(), index); }
257 void setField(
const char* key,
int index = -2);
258 void setField(
const std::string& key,
int index = -2) {
return setField(key.c_str(), index); }
264 void getEnv(
int index = -1);
265 void setEnv(
int index = -2);
268 void getGlobalField(
const std::string& globalKey,
const std::string& fieldKey);
271 void rawGet(
int index = -1);
272 void rawGeti(
int n,
int index = -1);
273 void rawSet(
int index = -3);
274 void rawSeti(
int n,
int index = -2);
302 bool isNil(
int index = -1);
316 std::string
toString(
int index = -1);
323 bool hasIndex(
int index) {
return (
stackSize() >= (index < 0 ? -index : index) && index != 0); }
325 void loadFiles(std::string directory,
bool recursive =
false, std::string contains =
"");
328 template<
typename T,
typename... Args>
344 int m_cppCallbackDepth;
357 template<
typename T,
typename... Args>
365 template<
class C,
typename F>
370 template<
class C,
typename F>
375 template<
class C,
typename F>
384 template<
class C,
typename F,
class FC>
386 registerClassMemberFunction<C>(functionName, luabinder::bind_mem_fun<C>(
function));
388 template<
class C,
typename F,
class FC>
393 template<
class C,
typename F1,
typename F2,
class FC>
395 registerClassMemberField<C>(fieldName, luabinder::bind_mem_fun<C>(getFunction), luabinder::bind_mem_fun<C>(setFunction));
397 template<
class C,
typename F1,
typename F2,
class FC>
399 registerClassMemberField(className, fieldName, luabinder::bind_mem_fun<C>(getFunction), luabinder::bind_mem_fun<C>(setFunction));
402 template<
class C,
typename F,
class FC>
404 registerClassMemberField<C>(fieldName, luabinder::bind_mem_fun<C>(getFunction),
LuaCppFunction());
406 template<
class C,
typename F,
class FC>
411 template<
class C,
typename F,
class FC>
413 registerClassMemberField<C>(fieldName,
LuaCppFunction(), luabinder::bind_mem_fun<C>(setFunction));
415 template<
class C,
typename F,
class FC>
433 template<
typename... T>
444 template<
typename... T>
451 template<
typename R,
typename... T>
void getField(const std::string &key, int index=-1)
int push_luavalue(const Outfit &outfit)
void rawSeti(int n, int index=-2)
std::function< int(LuaInterface *)> LuaCppFunction
void * newUserdata(int size)
void setGlobal(const std::string &key)
bool isString(int index=-1)
bool isLuaFunction(int index=-1)
void bindClassStaticFunction(const std::string &functionName, const F &function)
std::string toString(int index=-1)
LuaCppFunction bind_singleton_mem_fun(Ret(FC::*f)(Args...), C *instance)
Bind singleton member functions.
void call(int numArgs=0, int numRets=0)
bool isNumber(int index=-1)
void registerClassMemberFunction(const std::string &className, const std::string &functionName, const LuaCppFunction &function)
LuaObjectPtr toObject(int index=-1)
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
bool luavalue_cast(int index, Outfit &outfit)
bool isCFunction(int index=-1)
void * popUpvalueUserdata()
void registerSingletonClass(const std::string &className)
void getGlobal(const std::string &key)
void setGlobalEnvironment(int env)
bool isFunction(int index=-1)
void loadScript(const std::string &fileName)
std::string traceback(const std::string &errorMessage="", int level=0)
void throwError(const std::string &message)
void clearTable(int index=-1)
void registerClassMemberField(const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction)
void getField(const char *key, int index=-1)
void bindClassMemberSetField(const std::string &fieldName, F FC::*setFunction)
void getTable(int index=-2)
int polymorphicPush(const T &v, const Args &... args)
Pushes any type onto the stack.
bool safeRunScript(const std::string &fileName)
Loads and runs a script, any errors are printed to stdout and returns false.
void pushNumber(double v)
void * toUserdata(int index=-1)
void createTable(int narr, int nrec)
void bindClassMemberFunction(const std::string &functionName, F FC::*function)
void bindClassMemberField(const std::string &fieldName, F1 FC::*getFunction, F2 FC::*setFunction)
int newSandboxEnv()
Creates a new environment table The new environment table is redirected to the global environment (ak...
void setEnv(int index=-2)
void rawGeti(int n, int index=-1)
void getEnv(int index=-1)
void runBuffer(const std::string &buffer, const std::string &source)
const char * typeName(int index=-1)
T polymorphicPop()
Same as castValue but also pops.
void getMetatable(int index=-1)
void pushCString(const char *v)
void pushObject(const LuaObjectPtr &obj)
int(* LuaCFunction)(lua_State *L)
void registerClassStaticFunction(const std::string &functionName, const LuaCppFunction &function)
void getGlobalField(const std::string &globalKey, const std::string &fieldKey)
void setMetatable(int index=-2)
Class that manages LUA stuff.
void loadBuffer(const std::string &buffer, const std::string &source)
void pushString(const std::string &v)
void pushValue(int index=-1)
void bindGlobalFunction(const std::string &functionName, const F &function)
std::string getCurrentSourcePath(int level=0)
Searches for the source of the current running function.
void registerClassStaticFunction(const std::string &className, const std::string &functionName, const LuaCppFunction &function)
T castValue(int index=-1)
std::string functionSourcePath()
void setField(const std::string &key, int index=-2)
void pushCppFunction(const LuaCppFunction &func)
const char * toCString(int index=-1)
void resetGlobalEnvironment()
int signalCall(int numArgs=0, int numRets=-1)
bool isTable(int index=-1)
void registerClassMemberFunction(const std::string &functionName, const LuaCppFunction &function)
void loadFiles(std::string directory, bool recursive=false, std::string contains="")
LuaCppFunction bind_fun(const std::function< int(LuaInterface *)> &f)
Bind a customized function.
void setField(const char *key, int index=-2)
bool isUserdata(int index=-1)
void registerGlobalFunction(const std::string &functionName, const LuaCppFunction &function)
int luaCallGlobalField(const std::string &global, const std::string &field, const T &... args)
void runScript(const std::string &fileName)
int pcall(int numArgs=0, int numRets=0, int errorFuncIndex=0)
int getGlobalEnvironment()
void setTable(int index=-3)
void getWeakRef(int weakRef)
void pushCFunction(LuaCFunction func, int n=0)
void loadFunction(const std::string &buffer, const std::string &source="lua function buffer")
void pushLightUserdata(void *p)
void bindSingletonFunction(const std::string &functionName, F C::*function, C *instance)
void registerFunctions()
Register core script functions.
bool toBoolean(int index=-1)
void getStackFunction(int level=0)
bool isBoolean(int index=-1)
void bindClassMemberGetField(const std::string &fieldName, F FC::*getFunction)
void rawSet(int index=-3)
int toInteger(int index=-1)
void evaluateExpression(const std::string &expression, const std::string &source="lua expression")
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 ...
void registerClassMemberField(const std::string &className, const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction)
void rawGet(int index=-1)
double toNumber(int index=-1)