summaryrefslogtreecommitdiffstats
path: root/source/LuaScript.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-07-29 09:53:47 +0200
committermadmaxoft <github@xoft.cz>2013-07-29 09:53:47 +0200
commit752e57108d300a4e9c4f8dfd3ff9a6f117dd4235 (patch)
tree99b22a3b1d3a65cb2c4d765e58eaee5d83463646 /source/LuaScript.h
parentMerge remote-tracking branch 'origin/master' into hunger (diff)
parentMerge pull request #15 from mc-server/webadmin (diff)
downloadcuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar.gz
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar.bz2
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar.lz
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar.xz
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.tar.zst
cuberite-752e57108d300a4e9c4f8dfd3ff9a6f117dd4235.zip
Diffstat (limited to 'source/LuaScript.h')
-rw-r--r--source/LuaScript.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/LuaScript.h b/source/LuaScript.h
new file mode 100644
index 000000000..cf4806903
--- /dev/null
+++ b/source/LuaScript.h
@@ -0,0 +1,42 @@
+#pragma once
+
+struct lua_State;
+
+struct sLuaUsertype
+{
+ sLuaUsertype(void* a_pObject, const char* a_pClassName) : Object(a_pObject), ClassName(a_pClassName) {}
+ //
+ void* Object;
+ const char* ClassName;
+};
+
+class cLuaScript
+{
+public:
+ cLuaScript();
+ ~cLuaScript();
+
+ /// Prepares a Lua state
+ void Initialize();
+
+ /// Load a Lua script on the given path
+ bool LoadFile(const char* a_FilePath);
+
+ /// Execute the loaded Lua script
+ bool Execute();
+
+ /// Call a function on the Lua script. Put all overloads here
+ bool CallFunction(const char* a_Function, AString& ReturnedString);
+ bool CallFunction(const char* a_Function, const sLuaUsertype& a_UserType, AString& ReturnedString);
+ bool CallFunction(const char* a_Function, const sLuaUsertype& a_UserType1, const sLuaUsertype& a_UserType2, AString& ReturnedString);
+
+protected:
+ /// Reports an error in the log if a_Status is flagged as an error. Returns true when a_Status is flagged as error, returns false when no error occured.
+ bool ReportErrors(int a_Status);
+
+ /// Helper functions for calling functions in Lua
+ bool LuaPushFunction(const char * a_FunctionName, bool a_bLogError = true);
+ bool LuaCallFunction(int a_NumArgs, int a_NumResults, const char * a_FunctionName ); // a_FunctionName is only used for error messages, nothing else
+private:
+ lua_State* m_LuaState;
+}; \ No newline at end of file