summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-04-23 21:36:17 +0200
committerMattes D <github@xoft.cz>2015-04-23 21:36:17 +0200
commita41f21f76f558e6808647c72478c6c3a42c77090 (patch)
treec4d91ef3f38ade72f61a400887372b8589bceb23 /src/Bindings/LuaState.cpp
parentNether Quartz is handled in the Ore handler. (diff)
parentImplemented cPluginManager:DoWithPlugin(), fixed ForEachPlugin(). (diff)
downloadcuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar.gz
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar.bz2
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar.lz
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar.xz
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.tar.zst
cuberite-a41f21f76f558e6808647c72478c6c3a42c77090.zip
Diffstat (limited to 'src/Bindings/LuaState.cpp')
-rw-r--r--src/Bindings/LuaState.cpp108
1 files changed, 89 insertions, 19 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 25c77a652..468e54f32 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -740,6 +740,18 @@ void cLuaState::Push(cPlayer * a_Player)
+void cLuaState::Push(cPlugin * a_Plugin)
+{
+ ASSERT(IsValid());
+
+ tolua_pushusertype(m_LuaState, a_Plugin, "cPlugin");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
void cLuaState::Push(cPluginLua * a_Plugin)
{
ASSERT(IsValid());
@@ -911,6 +923,20 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type)
+void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
+{
+ size_t len = 0;
+ const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
+ if (data != nullptr)
+ {
+ a_Value.assign(data, len);
+ }
+}
+
+
+
+
+
void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
@@ -920,25 +946,20 @@ void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
-void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
+void cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref)
{
- size_t len = 0;
- const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
- if (data != nullptr)
- {
- a_Value.assign(data, len);
- }
+ a_Ref.RefStack(*this, a_StackPos);
}
-void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
- a_ReturnedVal = (int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
+ a_ReturnedVal = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
}
}
@@ -946,23 +967,27 @@ void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
-void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal)
{
- if (lua_isnumber(m_LuaState, a_StackPos))
+ if (!lua_isnumber(m_LuaState, a_StackPos))
{
- a_ReturnedVal = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
+ return;
}
+ a_ReturnedVal = static_cast<eWeather>(Clamp(
+ static_cast<int>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)),
+ static_cast<int>(wSunny), static_cast<int>(wThunderstorm))
+ );
}
-void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
- a_ReturnedVal = (eWeather)Clamp((int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal), (int)wSunny, (int)wThunderstorm);
+ a_ReturnedVal = static_cast<int>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal));
}
}
@@ -988,7 +1013,7 @@ void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
-void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, pPluginManager & a_ReturnedVal)
{
if (lua_isnil(m_LuaState, a_StackPos))
{
@@ -996,9 +1021,9 @@ void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
return;
}
tolua_Error err;
- if (tolua_isusertype(m_LuaState, a_StackPos, "cWorld", false, &err))
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cPluginManager", false, &err))
{
- a_ReturnedVal = *((cWorld **)lua_touserdata(m_LuaState, a_StackPos));
+ a_ReturnedVal = *(reinterpret_cast<cPluginManager **>(lua_touserdata(m_LuaState, a_StackPos)));
}
}
@@ -1006,9 +1031,54 @@ void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
-void cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref)
+void cLuaState::GetStackValue(int a_StackPos, pRoot & a_ReturnedVal)
{
- a_Ref.RefStack(*this, a_StackPos);
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cRoot", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cRoot **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
+}
+
+
+
+
+
+void cLuaState::GetStackValue(int a_StackPos, pScoreboard & a_ReturnedVal)
+{
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cScoreboard", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cScoreboard **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
+}
+
+
+
+
+
+void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
+{
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cWorld", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cWorld **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
}