diff options
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/BindingsProcessor.lua | 56 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 185 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_RankManager.cpp | 87 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 1 |
4 files changed, 212 insertions, 117 deletions
diff --git a/src/Bindings/BindingsProcessor.lua b/src/Bindings/BindingsProcessor.lua index df479a634..4bea64435 100644 --- a/src/Bindings/BindingsProcessor.lua +++ b/src/Bindings/BindingsProcessor.lua @@ -25,7 +25,7 @@ Placeholders in use (i = internal ToLua++): - \3 and \4: (i) Embedded C code ("<>") - \5 and \6: (i) Embedded C code ("{}") - \17 and \18: DoxyComment for next item ("/** ... */") via an ID lookup - - \19 and \20: DocyComment for previous item ("///< ... \n") via an ID lookup + - \19 and \20: DoxyComment for previous item ("///< ... \n") via an ID lookup --]] @@ -121,7 +121,7 @@ function parser_hook(a_Code) return strsub(a_Code, e) -- normally we would use 'e + 1', but we need to preserve the [^:] end end - + -- Process forward DoxyComments: do local b, e, comment = a_Code:find("^%s*(%b\17\18)") @@ -135,7 +135,7 @@ function parser_hook(a_Code) return strsub(a_Code, e + 1) end end - + -- Process backward DoxyComments: do local b, e, comment = a_Code:find("^%s*(%b\19\20)") @@ -200,7 +200,7 @@ local function OutputLuaStateHelpers(a_Package) f:write("\n\n\n\n\n") f:close() end - + -- Output the Push() and GetStackValue() function declarations: do local f = assert(io.open("LuaState_Declaration.inc", "w")) @@ -342,12 +342,12 @@ local function outputClassFunctionDocs(a_File, a_Class, a_Functions) return (a_Fn1.Name < a_Fn2.Name) end ) - + -- If there are no functions, bail out: if not(functions[1]) then return end - + -- Output the descriptions: a_File:write("\t\tFunctions =\n\t\t{\n") for _, fn in ipairs(functions) do @@ -401,12 +401,12 @@ local function outputClassVariableDocs(a_File, a_Class, a_Variables) return (a_Var1.Name < a_Var2.Name) end ) - + -- If there are no variables, bail out: if not(variables[1]) then return end - + -- Output the descriptions: a_File:write("\t\tVariables =\n\t\t{\n") for _, v in ipairs(variables) do @@ -442,12 +442,12 @@ local function outputClassConstantDocs(a_File, a_Class, a_Constants, a_IgnoredCo return (a_Var1.Name < a_Var2.Name) end ) - + -- If there are no constants, bail out: if not(constants[1]) then return end - + -- Output the descriptions: a_File:write("\t\tConstants =\n\t\t{\n") for _, con in ipairs(constants) do @@ -474,14 +474,14 @@ local function outputClassEnumDocs(a_File, a_Class, a_Enums) if (not(a_Enums) or not(a_Enums[1])) then return end - + -- Sort the enums by name: table.sort(a_Enums, function (a_Enum1, a_Enum2) return (a_Enum1.name < a_Enum2.name) end ) - + -- Output the enums: a_File:write("\t\tEnums =\n\t\t{\n") for i, enum in ipairs(a_Enums) do @@ -540,7 +540,7 @@ local function outputClassDocs(a_Class, a_Functions, a_Variables, a_Constants, a if (a_Class.DoxyComment) then f:write("\t\tDesc = ", string.format("%q", a_Class.DoxyComment), ",\n") end - + -- If the class inherits from anything, output it here: local ignoredConstants = {} if (a_Class.base and (a_Class.base ~= "")) then @@ -559,19 +559,19 @@ local function outputClassDocs(a_Class, a_Functions, a_Variables, a_Constants, a end f:write("\t\t},\n") end - + -- Output the functions: outputClassFunctionDocs(f, a_Class, a_Functions) - + -- Output the variables: outputClassVariableDocs(f, a_Class, a_Variables) - + -- Output the constants: outputClassConstantDocs(f, a_Class, a_Constants, ignoredConstants) - + -- Output the enums: outputClassEnumDocs(f, a_Class, a_Class.enums) - + -- Output the footer: f:write("\t},\n}\n") f:close() @@ -616,7 +616,7 @@ local function genPackageDocs(a_Self) f:close() end end - + applyNextDoxyComments(a_Self) -- Generate docs for each member: @@ -631,7 +631,7 @@ local function genPackageDocs(a_Self) end i = i + 1 end - + -- Output the globals' docs: local functions = {} local variables = {} @@ -646,7 +646,7 @@ local function genPackageDocs(a_Self) a_Self.lname = "Globals" outputClassDocs(a_Self, functions, variables, constants, filenames) a_Self.lname = oldName - + -- Output the list of docs files: table.sort(filenames) local f = assert(io.open("docs/_files.lua", "w")) @@ -686,7 +686,7 @@ local function genClassDocs(a_Self, a_Filenames) end i = i + 1 end - + -- Output the individual docs outputClassDocs(a_Self, functions, variables, constants, a_Filenames) end @@ -706,7 +706,7 @@ local function parseFunctionParameters(a_Function) ) then return {} end - + local res = {} local idx = 1 for _, param in ipairs(a_Function.args or {}) do @@ -751,7 +751,7 @@ end local function genFunctionMemberDocs(a_Self, a_Functions, a_Variables, a_Constants) assert(a_Self.lname) - + local fn = a_Functions[a_Self.lname] or {} a_Functions[a_Self.lname] = fn @@ -776,14 +776,14 @@ end local function genVariableMemberDocs(a_Self, a_Functions, a_Variables, a_Constants) assert(a_Self.lname) - + local desc = { Name = a_Self.lname, Type = a_Self.type, DoxyComment = a_Self.DoxyComment, } - + if (string.find(a_Self.type,'const%s+') or string.find(a_Self.mod, 'tolua_readonly') or string.find(a_Self.mod, 'tolua_inherits')) then a_Constants[a_Self.lname] = desc else @@ -806,7 +806,7 @@ local function generateDocs(a_Package) return false, "Cannot access the docs folder: " .. msg end f:close() - + -- Generate the docs: classPackage.genDocs = genPackageDocs classClass.genDocs = genClassDocs @@ -858,7 +858,7 @@ end function preprocess_hook(a_Package) assert(a_Package) assert(type(a_Package.code) == "string") - + -- Replace all DoxyComments with placeholders so that they aren't erased later on: a_Package.code = a_Package.code :gsub("/%*%*%s*(.-)%s*%*/", diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 038c67995..083a30f2a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1315,8 +1315,9 @@ static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S) static int tolua_cPluginManager_BindCommand(lua_State * a_LuaState) { /* Function signatures: - cPluginManager:BindCommand(Command, Permission, Function, HelpString) - cPluginManager.BindCommand(Command, Permission, Function, HelpString) -- without the "self" param + cPluginManager:Get():BindCommand(Command, Permission, Function, HelpString) -- regular + cPluginManager:BindCommand(Command, Permission, Function, HelpString) -- static + cPluginManager.BindCommand(Command, Permission, Function, HelpString) -- without the "self" param */ cLuaState L(a_LuaState); cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L); @@ -1379,8 +1380,9 @@ static int tolua_cPluginManager_BindCommand(lua_State * a_LuaState) static int tolua_cPluginManager_BindConsoleCommand(lua_State * a_LuaState) { /* Function signatures: - cPluginManager:BindConsoleCommand(Command, Function, HelpString) - cPluginManager.BindConsoleCommand(Command, Function, HelpString) -- without the "self" param + cPluginManager:Get():BindConsoleCommand(Command, Function, HelpString) -- regular + cPluginManager:BindConsoleCommand(Command, Function, HelpString) -- static + cPluginManager.BindConsoleCommand(Command, Function, HelpString) -- without the "self" param */ // Get the plugin identification out of LuaState: @@ -1908,20 +1910,17 @@ static int tolua_sha1HexString(lua_State * tolua_S) -static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, std::string >& a_StringStringMap) +static int tolua_get_HTTPRequest_Params(lua_State * a_LuaState) { - lua_newtable(tolua_S); - int top = lua_gettop(tolua_S); - - for (std::map<std::string, std::string>::iterator it = a_StringStringMap.begin(); it != a_StringStringMap.end(); ++it) + cLuaState L(a_LuaState); + HTTPRequest * self; + if (!L.GetStackValues(1, self)) { - const char * key = it->first.c_str(); - const char * value = it->second.c_str(); - lua_pushstring(tolua_S, key); - lua_pushstring(tolua_S, value); - lua_settable(tolua_S, top); + tolua_Error err; + tolua_error(a_LuaState, "Invalid self parameter, expected a HTTPRequest instance", &err); + return 0; } - + L.Push(self->Params); return 1; } @@ -1929,40 +1928,44 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, -static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) -{ - HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr)); - return tolua_push_StringStringMap(tolua_S, self->Params); -} - - - - - -static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) +static int tolua_get_HTTPRequest_PostParams(lua_State * a_LuaState) { - HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr)); - return tolua_push_StringStringMap(tolua_S, self->PostParams); + cLuaState L(a_LuaState); + HTTPRequest * self; + if (!L.GetStackValues(1, self)) + { + tolua_Error err; + tolua_error(a_LuaState, "Invalid self parameter, expected a HTTPRequest instance", &err); + return 0; + } + L.Push(self->PostParams); + return 1; } -static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) +static int tolua_get_HTTPRequest_FormData(lua_State* a_LuaState) { - HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr)); - std::map<std::string, HTTPFormData> & FormData = self->FormData; - - lua_newtable(tolua_S); - int top = lua_gettop(tolua_S); + cLuaState L(a_LuaState); + HTTPRequest * self; + if (!L.GetStackValues(1, self)) + { + tolua_Error err; + tolua_error(a_LuaState, "Invalid self parameter, expected a HTTPRequest instance", &err); + return 0; + } - for (std::map<std::string, HTTPFormData>::iterator it = FormData.begin(); it != FormData.end(); ++it) + const auto & FormData = self->FormData; + lua_newtable(a_LuaState); + int top = lua_gettop(a_LuaState); + for (auto itr = FormData.cbegin(); itr != FormData.cend(); ++itr) { - lua_pushstring(tolua_S, it->first.c_str()); - tolua_pushusertype(tolua_S, &(it->second), "HTTPFormData"); - // lua_pushlstring(tolua_S, it->second.Value.c_str(), it->second.Value.size()); // Might contain binary data - lua_settable(tolua_S, top); + lua_pushstring(a_LuaState, itr->first.c_str()); + tolua_pushusertype(a_LuaState, const_cast<void *>(reinterpret_cast<const void *>(&(itr->second))), "HTTPFormData"); + // lua_pushlstring(a_LuaState, it->second.Value.c_str(), it->second.Value.size()); // Might contain binary data + lua_settable(a_LuaState, top); } return 1; @@ -3453,6 +3456,69 @@ static int tolua_cChunkDesc_GetBlockTypeMeta(lua_State * a_LuaState) +static int tolua_cCompositeChat_new(lua_State * a_LuaState) +{ + /* Function signatures: + cCompositeChat() + cCompositeChat(a_ParseText, a_MessageType) + */ + + // Check if it's the no-param version: + cLuaState L(a_LuaState); + if (lua_isnone(a_LuaState, 2)) + { + auto * res = static_cast<cCompositeChat *>(Mtolua_new(cCompositeChat())); + L.Push(res); + return 1; + } + + // Check the second signature: + AString parseText; + if (!L.GetStackValue(2, parseText)) + { + tolua_Error err; + tolua_error(a_LuaState, "Invalid ParseText parameter (1) in cCompositeChat constructor.", &err); + return 0; + } + int messageTypeInt = mtCustom; + if (!lua_isnone(a_LuaState, 3)) + { + if (!L.GetStackValue(3, messageTypeInt)) + { + tolua_Error err; + tolua_error(a_LuaState, "Invalid type of the MessageType parameter (2) in cCompositeChat constructor.", &err); + return 0; + } + if ((messageTypeInt < 0) || (messageTypeInt >= mtMaxPlusOne)) + { + tolua_Error err; + tolua_error(a_LuaState, "Invalid MessageType parameter (2) value in cCompositeChat constructor.", &err); + return 0; + } + } + L.Push(static_cast<cCompositeChat *>(Mtolua_new(cCompositeChat(parseText, static_cast<eMessageType>(messageTypeInt))))); + return 1; +} + + + + + +static int tolua_cCompositeChat_new_local(lua_State * a_LuaState) +{ + // Use the same constructor as global, just register it for GC: + auto res = tolua_cCompositeChat_new(a_LuaState); + if (res == 1) + { + tolua_register_gc(a_LuaState, lua_gettop(a_LuaState)); + } + return res; +} + + + + + static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) { // function cCompositeChat:AddRunCommandPart(Message, Command, [Style]) @@ -3475,7 +3541,7 @@ static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S) } // Add the part: - AString Text, Command, Style; + AString Text, Command, Style = "u@a"; L.GetStackValue(2, Text); L.GetStackValue(3, Command); L.GetStackValue(4, Style); @@ -3600,6 +3666,39 @@ static int tolua_cCompositeChat_AddUrlPart(lua_State * tolua_S) +static int tolua_cCompositeChat_Clear(lua_State * tolua_S) +{ + // function cCompositeChat:Clear() + // Exported manually to support call-chaining (return *this) + + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cCompositeChat") || + !L.CheckParamEnd(2) + ) + { + return 0; + } + cCompositeChat * self = reinterpret_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (self == nullptr) + { + tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:ParseText'", nullptr); + return 0; + } + + // Clear all the parts: + self->Clear(); + + // Cut away everything from the stack except for the cCompositeChat instance; return that: + lua_settop(L, 1); + return 1; +} + + + + + static int tolua_cCompositeChat_ParseText(lua_State * tolua_S) { // function cCompositeChat:ParseText(TextMessage) @@ -3673,7 +3772,7 @@ static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S) static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) { // function cCompositeChat:UnderlineUrls() - // Exported manually to support call-chaining (return *this) + // Exported manually to support call-chaining (return self) // Check params: cLuaState L(tolua_S); @@ -3757,10 +3856,14 @@ 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); diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp index 7871c26ef..84ca67c4e 100644 --- a/src/Bindings/ManualBindings_RankManager.cpp +++ b/src/Bindings/ManualBindings_RankManager.cpp @@ -100,58 +100,58 @@ static int tolua_cRankManager_AddPermissionToGroup(lua_State * L) -/** Binds cRankManager::AddRestrictionToGroup */ -static int tolua_cRankManager_AddRestrictionToGroup(lua_State * L) +/** Binds cRankManager::AddRank */ +static int tolua_cRankManager_AddRank(lua_State * L) { // Function signature: - // cRankManager:AddRestrictionToGroup(Permission, GroupName) -> bool + // cRankManager:AddRank(RankName) cLuaState S(L); if ( !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2, 3) || - !S.CheckParamEnd(4) + !S.CheckParamString(2, 5) || + !S.CheckParamEnd(6) ) { return 0; } // Read the params: - AString GroupName, Permission; - S.GetStackValues(2, Permission, GroupName); + AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode; + S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode); - // Add the group to the rank: - S.Push(cRoot::Get()->GetRankManager()->AddRestrictionToGroup(Permission, GroupName)); - return 1; + // Add the rank: + cRoot::Get()->GetRankManager()->AddRank(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode); + return 0; } -/** Binds cRankManager::AddRank */ -static int tolua_cRankManager_AddRank(lua_State * L) +/** Binds cRankManager::AddRestrictionToGroup */ +static int tolua_cRankManager_AddRestrictionToGroup(lua_State * L) { // Function signature: - // cRankManager:AddRank(RankName) + // cRankManager:AddRestrictionToGroup(Restriction, GroupName) -> bool cLuaState S(L); if ( !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2, 5) || - !S.CheckParamEnd(6) + !S.CheckParamString(2, 3) || + !S.CheckParamEnd(4) ) { return 0; } // Read the params: - AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode; - S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode); + AString GroupName, Restriction; + S.GetStackValues(2, Restriction, GroupName); - // Add the rank: - cRoot::Get()->GetRankManager()->AddRank(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode); - return 0; + // Add the group to the rank: + S.Push(cRoot::Get()->GetRankManager()->AddRestrictionToGroup(Restriction, GroupName)); + return 1; } @@ -233,11 +233,11 @@ static int tolua_cRankManager_GetAllPermissions(lua_State * L) -/** Binds cRankManager::GetAllPermissions */ -static int tolua_cRankManager_GetAllRestrictions(lua_State * L) +/** Binds cRankManager::GetAllPermissionsRestrictions */ +static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L) { // Function signature: - // cRankManager:GetAllRestrictions() -> arraytable of Permissions + // cRankManager:GetAllPermissionsRestrictions() -> arraytable of Permissions and Restrictions together cLuaState S(L); if ( @@ -248,11 +248,9 @@ static int tolua_cRankManager_GetAllRestrictions(lua_State * L) return 0; } - // Get the permissions: - AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllRestrictions(); - // Push the results: - S.Push(Permissions); + S.Push(cRoot::Get()->GetRankManager()->GetAllPermissionsRestrictions()); + return 1; } @@ -260,11 +258,11 @@ static int tolua_cRankManager_GetAllRestrictions(lua_State * L) -/** Binds cRankManager::GetAllPermissionsRestrictions */ -static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L) +/** Binds cRankManager::GetAllPlayerUUIDs */ +static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) { // Function signature: - // cRankManager:GetAllPermissionsRestrictions() -> arraytable of Permissions and Restrictions + // cRankManager:GetAllPlayerUUIDs() -> arraytable of Player UUID's cLuaState S(L); if ( @@ -275,11 +273,11 @@ static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L) return 0; } - // Get the permissions: - AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllPermissionsRestrictions(); + // Get the player uuid's: + AStringVector Players = cRoot::Get()->GetRankManager()->GetAllPlayerUUIDs(); // Push the results: - S.Push(Permissions); + S.Push(Players); return 1; } @@ -287,11 +285,11 @@ static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L) -/** Binds cRankManager::GetAllPlayerUUIDs */ -static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) +/** Binds cRankManager::GetAllRanks */ +static int tolua_cRankManager_GetAllRanks(lua_State * L) { // Function signature: - // cRankManager:GetAllPlayerUUIDs() -> arraytable of Player UUID's + // cRankManager:GetAllRanks() -> arraytable of RankNames cLuaState S(L); if ( @@ -302,11 +300,8 @@ static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) return 0; } - // Get the player uuid's: - AStringVector Players = cRoot::Get()->GetRankManager()->GetAllPlayerUUIDs(); - // Push the results: - S.Push(Players); + S.Push(cRoot::Get()->GetRankManager()->GetAllRanks()); return 1; } @@ -314,11 +309,11 @@ static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) -/** Binds cRankManager::GetAllRanks */ -static int tolua_cRankManager_GetAllRanks(lua_State * L) +/** Binds cRankManager::GetAllRestrictions */ +static int tolua_cRankManager_GetAllRestrictions(lua_State * L) { // Function signature: - // cRankManager:GetAllRanks() -> arraytable of RankNames + // cRankManager:GetAllRestrictions() -> arraytable of Restrictions cLuaState S(L); if ( @@ -329,11 +324,9 @@ static int tolua_cRankManager_GetAllRanks(lua_State * L) return 0; } - // Get the ranks: - AStringVector Ranks = cRoot::Get()->GetRankManager()->GetAllRanks(); - // Push the results: - S.Push(Ranks); + S.Push(cRoot::Get()->GetRankManager()->GetAllRestrictions()); + return 1; } diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index d1fc2ae4f..f2896abde 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -150,7 +150,6 @@ bool cPluginLua::Load(void) if (!m_LuaState.LoadFile(Path)) { SetLoadError("Failed to load file Info.lua."); - m_Status = cPluginManager::psError; Close(); return false; } |