diff options
author | madmaxoft <github@xoft.cz> | 2014-07-03 17:49:21 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-07-03 17:49:21 +0200 |
commit | 2dbed03cbce873d8a6582bfdc5c4b826b6e7eade (patch) | |
tree | c95173c315bbd1020301188b138d426fa800b5d2 /src/Bindings | |
parent | CMake: Changed slash format to support MSYS. (diff) | |
download | cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar.gz cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar.bz2 cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar.lz cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar.xz cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.tar.zst cuberite-2dbed03cbce873d8a6582bfdc5c4b826b6e7eade.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/LuaState.cpp | 12 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 5 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 5 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 7a5ed1425..32638df96 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -811,6 +811,18 @@ 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)) + { + a_ReturnedVal = (eWeather)Clamp((int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal), (int)wSunny, (int)wThunderstorm); + } +} + + + + + bool cLuaState::CallFunction(int a_NumResults) { ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 066390e39..723193ae7 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -30,6 +30,7 @@ extern "C" } #include "../Vector3.h" +#include "../Defines.h" @@ -222,6 +223,10 @@ public: /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */ void GetStackValue(int a_StackPos, double & a_Value); + /** Retrieve value at a_StackPos, if it is a valid number, converting and clamping it to eWeather. + If not, a_Value is unchanged. */ + void GetStackValue(int a_StackPos, eWeather & a_Value); + /** Call any 0-param 0-return Lua function in a single line: */ template <typename FnT> diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 344031995..104380ea4 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1347,18 +1347,15 @@ bool cPluginLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather) { cCSLock Lock(m_CriticalSection); bool res = false; - int NewWeather = a_NewWeather; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WEATHER_CHANGING]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_World, NewWeather, cLuaState::Return, res, NewWeather); + m_LuaState.Call((int)(**itr), &a_World, a_NewWeather, cLuaState::Return, res, a_NewWeather); if (res) { - a_NewWeather = (eWeather)NewWeather; return true; } } - a_NewWeather = (eWeather)NewWeather; return false; } |