From 63b63c5d844e8702fce2ae0181ee4397b8954d92 Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Sat, 7 May 2022 01:26:13 +0200 Subject: Added check for unexported but documented API (#5418) Also fixed the errors --- Server/Plugins/APIDump/APIDesc.lua | 54 ---------------------- Server/Plugins/APIDump/Classes/Geometry.lua | 57 ----------------------- Server/Plugins/APIDump/Classes/Projectiles.lua | 10 ----- Server/Plugins/APIDump/main_APIDump.lua | 62 ++++++++++++++++++++++++++ src/Bindings/ManualBindings.cpp | 61 ++++++++++++++++++++----- src/Entities/HangingEntity.h | 5 +-- 6 files changed, 113 insertions(+), 136 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 531e11ac1..227e4a6fa 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -908,16 +908,6 @@ return }, Notes = "Returns true if the chunk is set to use default height generator", }, - IsUsingDefaultStructures = - { - Returns = - { - { - Type = "boolean", - }, - }, - Notes = "Returns true if the chunk is set to use default structures", - }, RandomFillRelCuboid = { { @@ -1258,17 +1248,6 @@ return }, Notes = "Sets the chunk to use default height generator or not", }, - SetUseDefaultStructures = - { - Params = - { - { - Name = "ShouldUseDefaultStructures", - Type = "boolean", - }, - }, - Notes = "Sets the chunk to use default structures or not", - }, UpdateHeightmap = { Notes = "Updates the heightmap to match current contents. The plugins should do that if they modify the contents and don't modify the heightmap accordingly; Cuberite expects (and checks in Debug mode) that the heightmap matches the contents when the cChunkDesc is returned from a plugin.", @@ -8707,10 +8686,6 @@ a_Player:OpenWindow(Window); ]], Functions = { - EraseData = - { - Notes = "Erases all pixel data.", - }, GetCenterX = { Returns = @@ -8999,16 +8974,6 @@ a_Player:OpenWindow(Window); }, Notes = "If a map with the specified ID exists, calls the CallbackFunction for that map. The CallbackFunction has the following signature:
function Callback({{cMap|Map}})
Returns true if the map was found and the callback called, false if map not found.", }, - GetNumMaps = - { - Returns = - { - { - Type = "number", - }, - }, - Notes = "Returns the number of registered maps.", - }, }, }, cMojangAPI = @@ -11442,17 +11407,6 @@ a_Player:OpenWindow(Window); }, Notes = "Sets the dominant hand of the player.", }, - SetName = - { - Params = - { - { - Name = "Name", - Type = "string", - }, - }, - Notes = "Sets the player name. This rename will NOT be visible to any players already in the server who are close enough to see this player.", - }, SetNormalMaxSpeed = { Params = @@ -13227,14 +13181,6 @@ end }, }, }, - cWebPlugin = - { - Desc = "", - Functions = - { - - }, - }, cWindow = { Desc = [[ diff --git a/Server/Plugins/APIDump/Classes/Geometry.lua b/Server/Plugins/APIDump/Classes/Geometry.lua index 9d289632c..1fe9090ac 100644 --- a/Server/Plugins/APIDump/Classes/Geometry.lua +++ b/Server/Plugins/APIDump/Classes/Geometry.lua @@ -1192,10 +1192,6 @@ end { Notes = "Updates each coord to its absolute value.", }, - abs = - { - Notes = "OBSOLETE, use Abs() instead.", - }, addedX = { Params = @@ -1293,21 +1289,6 @@ end }, Notes = "Clamps each coord into the specified range.", }, - clamp = - { - Params = - { - { - Name = "min", - Type = "number", - }, - { - Name = "max", - Type = "number", - }, - }, - Notes = "OBSOLETE, use Clamp() instead.", - }, constructor = { { @@ -1772,10 +1753,6 @@ end { Notes = "Updates each coord to its absolute value.", }, - abs = - { - Notes = "OBSOLETE, use Abs() instead.", - }, addedX = { Params = @@ -1873,21 +1850,6 @@ end }, Notes = "Clamps each coord into the specified range.", }, - clamp = - { - Params = - { - { - Name = "min", - Type = "number", - }, - { - Name = "max", - Type = "number", - }, - }, - Notes = "OBSOLETE, use Clamp() instead.", - }, constructor = { { @@ -2384,10 +2346,6 @@ end { Notes = "Updates each coord to its absolute value.", }, - abs = - { - Notes = "OBSOLETE, use Abs() instead.", - }, addedX = { Params = @@ -2485,21 +2443,6 @@ end }, Notes = "Clamps each coord into the specified range.", }, - clamp = - { - Params = - { - { - Name = "min", - Type = "number", - }, - { - Name = "max", - Type = "number", - }, - }, - Notes = "OBSOLETE, use Clamp() instead.", - }, constructor = { { diff --git a/Server/Plugins/APIDump/Classes/Projectiles.lua b/Server/Plugins/APIDump/Classes/Projectiles.lua index f74b92136..b3bf7fbed 100644 --- a/Server/Plugins/APIDump/Classes/Projectiles.lua +++ b/Server/Plugins/APIDump/Classes/Projectiles.lua @@ -215,16 +215,6 @@ return Desc = "Base class for all projectiles, such as arrows and fireballs.", Functions = { - GetCreator = - { - Returns = - { - { - Type = "cEntity", - }, - }, - Notes = "Returns the entity who created this projectile. May return nil.", - }, GetCreatorName = { Returns = diff --git a/Server/Plugins/APIDump/main_APIDump.lua b/Server/Plugins/APIDump/main_APIDump.lua index b1277ca0b..735a6ec05 100644 --- a/Server/Plugins/APIDump/main_APIDump.lua +++ b/Server/Plugins/APIDump/main_APIDump.lua @@ -2041,6 +2041,56 @@ end +--- Checks if any functions that are documented are present in the API +-- Returns an array-table of strings representing the unexported symbol names +-- If no unexported are found, returns no value. +-- If an error occurs, returns true and error message. +local function CheckUnexportedFunctions() + local res = {} + + local API, Globals, Desc = PrepareApi() + for clsname, cls in pairs(Desc.Classes) do + if not(cls.IsExported) then + -- The whole class is not exported + table.insert(res, "class\t" .. clsname .. "\n"); + else + if (cls.Functions ~= nil) then + for fnname, fnapi in pairs(cls.Functions) do + if not(fnapi.IsExported) then + table.insert(res, "func\t" .. clsname .. "." .. fnname); + end + end -- for j, fn - cls.Functions[] + end + if (cls.Constants ~= nil) then + for cnname, cnapi in pairs(cls.Constants) do + if not(cnapi.IsExported) then + table.insert(res, "const\t" .. clsname .. "." .. cnname); + end + end -- for j, fn - cls.Functions[] + end + end + end -- for i, cls - a_APIDesc.Classes[] + + table.sort(res) + + -- Bail out if no items found: + if not(res[1]) then + return + end + + -- Save any found items to a file: + local f = io.open("Unexported.lua", "w") + f:write(table.concat(res, "\n")) + f:write("\n") + f:close() + + return res +end + + + + + local function HandleWebAdminDump(a_Request) if (a_Request.PostParams["Dump"] ~= nil) then @@ -2101,6 +2151,18 @@ local function HandleCmdApiCheck(a_Split, a_EntireCmd) end end + LOG("Checking for unexported Objects...") + local unexported, msg = CheckUnexportedFunctions() + if (unexported) then + if (unexported == true) then + LOGERROR("Cannot check for unexported symbols: " .. (msg or "")) + return true + else + LOGERROR("Found unexported symbols:\n" .. table.concat(unexported, "\n")) + return true + end + end + -- The check completed successfully, remove the "test failed" flag from the filesystem: cFile:DeleteFile("apiCheckFailed.flag") diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2d92c1d3b..f5517dc84 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3889,6 +3889,44 @@ static int tolua_cCompositeChat_new_local(lua_State * a_LuaState) +static int tolua_cCompositeChat_AddShowAchievementPart(lua_State * tolua_S) +{ + // function cCompositeChat:AddShowAchievementPart(PlayerName, Achievement, [Style]) + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamString(2, 3) + ) + { + return 0; + } + + cCompositeChat * self = static_cast(tolua_tousertype(tolua_S, 1, nullptr)); + if (self == nullptr) + { + tolua_error(tolua_S, "invalid 'self' in function call cCompositeChat::AddShowAchievementPart(string, string, string) const.", nullptr); + return 0; + } + + // Add the part: + AString PlayerName, Achievement, Style; + L.GetStackValues(2, PlayerName); + L.GetStackValues(3, Achievement); + L.GetStackValues(4, Style); + self->AddShowAchievementPart(PlayerName, Achievement, Style); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(tolua_S, 1); + return 1; +} + + + + + static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) { // function cCompositeChat:AddRunCommandPart(Message, Command, [Style]) @@ -4529,17 +4567,18 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cCompositeChat"); - tolua_function(tolua_S, "new", tolua_cCompositeChat_new); - tolua_function(tolua_S, "new_local", tolua_cCompositeChat_new_local); - tolua_function(tolua_S, ".call", tolua_cCompositeChat_new_local); - tolua_function(tolua_S, "AddRunCommandPart", tolua_cCompositeChat_AddRunCommandPart); - tolua_function(tolua_S, "AddSuggestCommandPart", tolua_cCompositeChat_AddSuggestCommandPart); - tolua_function(tolua_S, "AddTextPart", tolua_cCompositeChat_AddTextPart); - tolua_function(tolua_S, "AddUrlPart", tolua_cCompositeChat_AddUrlPart); - tolua_function(tolua_S, "Clear", tolua_cCompositeChat_Clear); - tolua_function(tolua_S, "ParseText", tolua_cCompositeChat_ParseText); - tolua_function(tolua_S, "SetMessageType", tolua_cCompositeChat_SetMessageType); - tolua_function(tolua_S, "UnderlineUrls", tolua_cCompositeChat_UnderlineUrls); + tolua_function(tolua_S, "new", tolua_cCompositeChat_new); + tolua_function(tolua_S, "new_local", tolua_cCompositeChat_new_local); + tolua_function(tolua_S, ".call", tolua_cCompositeChat_new_local); + tolua_function(tolua_S, "AddShowAchievementPart", tolua_cCompositeChat_AddShowAchievementPart); + tolua_function(tolua_S, "AddRunCommandPart", tolua_cCompositeChat_AddRunCommandPart); + tolua_function(tolua_S, "AddSuggestCommandPart", tolua_cCompositeChat_AddSuggestCommandPart); + tolua_function(tolua_S, "AddTextPart", tolua_cCompositeChat_AddTextPart); + tolua_function(tolua_S, "AddUrlPart", tolua_cCompositeChat_AddUrlPart); + tolua_function(tolua_S, "Clear", tolua_cCompositeChat_Clear); + tolua_function(tolua_S, "ParseText", tolua_cCompositeChat_ParseText); + tolua_function(tolua_S, "SetMessageType", tolua_cCompositeChat_SetMessageType); + tolua_function(tolua_S, "UnderlineUrls", tolua_cCompositeChat_UnderlineUrls); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cCryptoHash"); diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index dfed17dc5..a0e63d794 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -31,10 +31,7 @@ public: // tolua_export static bool IsValidSupportBlock(BLOCKTYPE a_BlockType); // tolua_export /** Set the direction in which the entity is facing. */ - void SetFacing(eBlockFace a_Facing) - { - m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); - } + void SetFacing(eBlockFace a_Facing) { m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); } // tolua_export /** Set the direction in which the entity is facing. */ void SetProtocolFacing(Byte a_Facing) -- cgit v1.2.3