summaryrefslogtreecommitdiffstats
path: root/source/LuaState.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-08 16:02:07 +0200
committermadmaxoft <github@xoft.cz>2013-08-08 16:02:07 +0200
commitcc920ea9297953e4f5e07b93587454516de7b34b (patch)
treedd0b571cb25f07b95a96a0c84ca463c2ae4940ec /source/LuaState.cpp
parentcPlugin: Name now defaults to the plugin folder name. (diff)
downloadcuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar.gz
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar.bz2
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar.lz
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar.xz
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.tar.zst
cuberite-cc920ea9297953e4f5e07b93587454516de7b34b.zip
Diffstat (limited to 'source/LuaState.cpp')
-rw-r--r--source/LuaState.cpp66
1 files changed, 60 insertions, 6 deletions
diff --git a/source/LuaState.cpp b/source/LuaState.cpp
index baa20fc07..83581d19a 100644
--- a/source/LuaState.cpp
+++ b/source/LuaState.cpp
@@ -200,7 +200,25 @@ bool cLuaState::LoadFile(const AString & a_FileName)
-bool cLuaState::PushFunction(const char * a_FunctionName, bool a_ShouldLogFailure /* = true */)
+bool cLuaState::HasFunction(const char * a_FunctionName)
+{
+ if (!IsValid())
+ {
+ // This happens if cPlugin::Initialize() fails with an error
+ return false;
+ }
+
+ lua_getglobal(m_LuaState, a_FunctionName);
+ bool res = (!lua_isnil(m_LuaState, -1) && lua_isfunction(m_LuaState, -1));
+ lua_pop(m_LuaState, 1);
+ return res;
+}
+
+
+
+
+
+bool cLuaState::PushFunction(const char * a_FunctionName)
{
ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack
@@ -213,10 +231,7 @@ bool cLuaState::PushFunction(const char * a_FunctionName, bool a_ShouldLogFailur
lua_getglobal(m_LuaState, a_FunctionName);
if (!lua_isfunction(m_LuaState, -1))
{
- if (a_ShouldLogFailure)
- {
- LOGWARNING("Error in %s: Could not find function %s()", m_SubsystemName.c_str(), a_FunctionName);
- }
+ LOGWARNING("Error in %s: Could not find function %s()", m_SubsystemName.c_str(), a_FunctionName);
lua_pop(m_LuaState, 1);
return false;
}
@@ -229,7 +244,7 @@ bool cLuaState::PushFunction(const char * a_FunctionName, bool a_ShouldLogFailur
-bool cLuaState::PushFunctionFromRegistry(int a_FnRef)
+bool cLuaState::PushFunction(int a_FnRef)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack
@@ -545,6 +560,45 @@ void cLuaState::Push(TakeDamageInfo * a_TDI)
+void cLuaState::Push(cWindow * a_Window)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, a_Window, "cWindow");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(cPlugin_NewLua * a_Plugin)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, a_Plugin, "cPlugin_NewLua");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(const HTTPRequest * a_Request)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, (void *)a_Request, "HTTPRequest");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);