Merge pull request #1289 from mc-server/LuaAPI
Added Clamp() function to the lua api.
This commit is contained in:
commit
e2f1e0589c
@ -2762,6 +2762,7 @@ end
|
||||
AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, [IsInverse]", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified {{Globals#BlockFaces|face}}"},
|
||||
BlockFaceToString = {Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "string", Notes = "Returns the string representation of the {{Globals#BlockFaces|eBlockFace}} constant. Uses the axis-direction-based names, such as BLOCK_FACE_XP." },
|
||||
BlockStringToType = {Params = "BlockTypeString", Return = "BLOCKTYPE", Notes = "Returns the block type parsed from the given string"},
|
||||
Clamp = {Params = "Number, Min, Max", Return = "number", Notes = "Clamp the number to the specified range."},
|
||||
ClickActionToString = {Params = "{{Globals#ClickAction|ClickAction}}", Return = "string", Notes = "Returns a string description of the ClickAction enumerated value"},
|
||||
DamageTypeToString = {Params = "{{Globals#DamageType|DamageType}}", Return = "string", Notes = "Converts the {{Globals#DamageType|DamageType}} enumerated value to a string representation "},
|
||||
EscapeString = {Params = "string", Return = "string", Notes = "Returns a copy of the string with all quotes and backslashes escaped by a backslash"},
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
lua_Number Number = tolua_tonumber(LuaState, 1, 0);
|
||||
lua_Number Min = tolua_tonumber(LuaState, 2, 0);
|
||||
lua_Number Max = tolua_tonumber(LuaState, 3, 0);
|
||||
|
||||
lua_Number Result = Clamp(Number, Min, 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);
|
||||
|
Loading…
Reference in New Issue
Block a user