diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-08-05 13:47:10 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-08-05 13:47:10 +0200 |
commit | a92cff20ea59b68827a6f579d0ba9ccb40276d6b (patch) | |
tree | 96d765e1de79252b629aebdda6908c904891bdee /src | |
parent | Fixed unsigned long comparison to size_t (diff) | |
download | cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar.gz cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar.bz2 cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar.lz cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar.xz cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.tar.zst cuberite-a92cff20ea59b68827a6f579d0ba9ccb40276d6b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 042ffb19e..b41cd94bc 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -82,6 +82,33 @@ static int lua_do_error(lua_State* L, const char * a_pFormat, ...) // Lua bound functions with special return types +static int tolua_Clamp(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + int NumArgs = lua_gettop(LuaState); + if (NumArgs != 3) + { + return lua_do_error(LuaState, "Error in function call '#funcname#': Requires 3 arguments, got %i", NumArgs); + } + + if (!lua_isnumber(LuaState, 1) || !lua_isnumber(LuaState, 2) || !lua_isnumber(LuaState, 3)) + { + return lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3"); + } + + int Min = (int)tolua_tonumber(LuaState, 1, 0); + int Number = (int)tolua_tonumber(LuaState, 2, 0); + int Max = (int)tolua_tonumber(LuaState, 3, 0); + + int Result = std::min(std::max(Min, Number), Max); + LuaState.Push(Result); + return 1; +} + + + + + static int tolua_StringSplit(lua_State * tolua_S) { cLuaState LuaState(tolua_S); @@ -3103,6 +3130,7 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); + tolua_function(tolua_S, "Clamp", tolua_Clamp); tolua_function(tolua_S, "StringSplit", tolua_StringSplit); tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim); tolua_function(tolua_S, "LOG", tolua_LOG); |