summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-04-23 19:41:01 +0200
committerMattes D <github@xoft.cz>2015-04-23 19:41:01 +0200
commit08624348f4e84fdc9909eb5de4478443bad8cc8d (patch)
tree26083482d28734594ba7e5c28af887224e9f12b9 /src/Bindings/LuaState.cpp
parentMerge pull request #1883 from mc-server/NarrowWindowID (diff)
downloadcuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar.gz
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar.bz2
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar.lz
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar.xz
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.tar.zst
cuberite-08624348f4e84fdc9909eb5de4478443bad8cc8d.zip
Diffstat (limited to '')
-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)));
+ }
}