From fbe98665245af8a552177d4a82ca0ba41b52a625 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 5 Jun 2016 17:20:50 +0200 Subject: Bindings: Add a const-ptr variant to all stack getter functions --- src/Bindings/BindingsProcessor.lua | 15 +++++++++++++++ src/Bindings/LuaState.cpp | 1 + 2 files changed, 16 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/BindingsProcessor.lua b/src/Bindings/BindingsProcessor.lua index a398f5026..e7b909ded 100644 --- a/src/Bindings/BindingsProcessor.lua +++ b/src/Bindings/BindingsProcessor.lua @@ -85,6 +85,7 @@ local function OutputLuaStateHelpers(a_Package) f:write("\n\n\n\n\n") for _, item in ipairs(types) do f:write("typedef " .. item.name .. " * Ptr" .. item.lname .. ";\n") + f:write("typedef const " .. item.name .. " * ConstPtr" .. item.lname .. ";\n") end f:write("\n\n\n\n\n") f:close() @@ -104,6 +105,7 @@ local function OutputLuaStateHelpers(a_Package) end for _, item in ipairs(types) do f:write("bool GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n") + f:write("bool GetStackValue(int a_StackPos, ConstPtr" .. item.lname .. " & a_ReturnedVal);\n") end f:write("\n\n\n\n\n") f:close() @@ -139,6 +141,19 @@ local function OutputLuaStateHelpers(a_Package) f:write("\t}\n") f:write("\treturn false;\n") f:write("}\n\n\n\n\n\n") + + f:write("bool cLuaState::GetStackValue(int a_StackPos, ConstPtr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n") + f:write("\tif (lua_isnil(m_LuaState, a_StackPos))\n\t{\n") + f:write("\t\ta_ReturnedVal = nullptr;\n") + f:write("\t\treturn false;\n\t}\n") + f:write("\ttolua_Error err;\n") + f:write("\tif (tolua_isusertype(m_LuaState, a_StackPos, \"const " .. item.name .. "\", false, &err))\n") + f:write("\t{\n") + f:write("\t\ta_ReturnedVal = *(reinterpret_cast(lua_touserdata(m_LuaState, a_StackPos)));\n") + f:write("\t\treturn true;\n"); + f:write("\t}\n") + f:write("\treturn false;\n") + f:write("}\n\n\n\n\n\n") end f:close() end diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index e0551c550..f11e74e75 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1656,6 +1656,7 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) case LUA_TNUMBER: Printf(Value, "%f", static_cast(lua_tonumber(a_LuaState, i))); break; case LUA_TSTRING: Printf(Value, "%s", lua_tostring(a_LuaState, i)); break; case LUA_TTABLE: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break; + case LUA_TUSERDATA: Printf(Value, "%p (%s)", lua_touserdata(a_LuaState, i), tolua_typename(a_LuaState, i)); break; default: break; } LOGD(" Idx %d: type %d (%s) %s", i, Type, lua_typename(a_LuaState, Type), Value.c_str()); -- cgit v1.2.3 From c2759186c09dc981aa672fecb57cce4aea722ec6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 5 Jun 2016 18:23:16 +0200 Subject: Bindings: Fixed cBoundingBox API. --- src/Bindings/ManualBindings.cpp | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 91e80acbc..9945929d0 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -37,6 +37,7 @@ #include "../CommandOutput.h" #include "../BuildInfo.h" #include "../HTTP/UrlParser.h" +#include "../BoundingBox.h" @@ -3143,6 +3144,80 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S) +static int tolua_cBoundingBox_CalcLineIntersection(lua_State * a_LuaState) +{ + /* Function signatures: + bbox:CalcLineIntersection(pt1, pt2) -> bool, [number, blockface] + cBoundingBox:CalcLineIntersection(min, max, pt1, pt2) -> bool, [number, blockface] + */ + cLuaState L(a_LuaState); + const Vector3d * min; + const Vector3d * max; + const Vector3d * pt1; + const Vector3d * pt2; + double lineCoeff; + eBlockFace blockFace; + bool res; + if (L.GetStackValues(2, min, max, pt1, pt2)) // Try the static signature first + { + res = cBoundingBox::CalcLineIntersection(min, max, pt1, pt2, lineCoeff, blockFace); + } + else + { + const cBoundingBox * bbox; + if (!L.GetStackValues(1, bbox, pt1, pt2)) // Try the regular signature + { + L.LogStack(); + tolua_error(a_LuaState, "Invalid function params. Expected either bbox:CalcLineIntersection(pt1, pt2) or cBoundingBox:CalcLineIntersection(min, max, pt1, pt2).", nullptr); + return 0; + } + res = bbox->CalcLineIntersection(pt1, pt2, lineCoeff, blockFace); + } + L.Push(res); + if (res) + { + L.Push(lineCoeff); + L.Push(blockFace); + return 3; + } + return 1; +} + + + + + +static int tolua_cBoundingBox_Intersect(lua_State * a_LuaState) +{ + /* Function signature: + bbox:Intersect(a_OtherBbox) -> bool, cBoundingBox + */ + cLuaState L(a_LuaState); + const cBoundingBox * self; + const cBoundingBox * other; + if (!L.GetStackValues(1, self, other)) + { + L.LogStack(); + tolua_error(a_LuaState, "Invalid function params. Expected bbox:Intersect(otherBbox).", nullptr); + return 0; + } + auto intersection = new cBoundingBox(*self); + auto res = self->Intersect(*other, *intersection); + L.Push(res); + if (!res) + { + delete intersection; + return 1; + } + L.Push(intersection); + tolua_register_gc(L, lua_gettop(L)); // Make Lua own the "intersection" object + return 2; +} + + + + + static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) { // function cCompositeChat:AddRunCommandPart(Message, Command, [Style]) @@ -3431,6 +3506,11 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "SaveToSchematicString", tolua_cBlockArea_SaveToSchematicString); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cBoundingBox"); + tolua_function(tolua_S, "CalcLineIntersection", tolua_cBoundingBox_CalcLineIntersection); + tolua_function(tolua_S, "Intersect", tolua_cBoundingBox_Intersect); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cClientHandle"); tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); -- cgit v1.2.3