diff options
author | Mattes D <github@xoft.cz> | 2016-09-25 12:42:05 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-09-25 12:42:05 +0200 |
commit | e169043a841824eacebeb7db7ecb202a7d3c4b02 (patch) | |
tree | 2867c0814251c68764cae34745447d2904a2c0b3 /src | |
parent | InfoReg: Don't fail if there are no commands to register. (diff) | |
download | cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar.gz cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar.bz2 cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar.lz cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar.xz cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.tar.zst cuberite-e169043a841824eacebeb7db7ecb202a7d3c4b02.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 104 | ||||
-rw-r--r-- | src/ClientHandle.cpp | 8 | ||||
-rw-r--r-- | src/CompositeChat.cpp | 5 | ||||
-rw-r--r-- | src/CompositeChat.h | 26 | ||||
-rw-r--r-- | src/Defines.h | 1 |
5 files changed, 119 insertions, 25 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index b68abb536..be7b86d7a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3455,6 +3455,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]) @@ -3477,7 +3540,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); @@ -3602,6 +3665,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) @@ -3675,7 +3771,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); @@ -3759,10 +3855,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/ClientHandle.cpp b/src/ClientHandle.cpp index 303583769..21947af13 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -213,7 +213,7 @@ AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a -AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData) +AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { switch (a_ChatPrefix) { @@ -237,11 +237,9 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue); } } + case mtMaxPlusOne: break; } - ASSERT(!"Unhandled chat prefix type!"); - #ifndef __clang__ - return ""; - #endif + return ""; } diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 2a112f810..657d88292 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -282,11 +282,10 @@ cLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel(eMessageType a_MessageT case mtPrivateMessage: return cLogger::llRegular; case mtJoin: return cLogger::llRegular; case mtLeave: return cLogger::llRegular; + case mtMaxPlusOne: break; } ASSERT(!"Unhandled MessageType"); - #ifndef __clang__ - return cLogger::llError; - #endif + return cLogger::llError; } diff --git a/src/CompositeChat.h b/src/CompositeChat.h index 2c1ff5fab..ab16e9f72 100644 --- a/src/CompositeChat.h +++ b/src/CompositeChat.h @@ -122,25 +122,23 @@ public: typedef std::vector<cBasePart *> cParts; - // tolua_begin - - /** Creates a new empty chat message */ + /** Creates a new empty chat message. + Exported manually due to the other overload needing a manual export. */ cCompositeChat(void); /** Creates a new chat message and parses the text into parts. Recognizes "http:" and "https:" links and @color-codes. - Uses ParseText() for the actual parsing. */ + Uses ParseText() for the actual parsing. + Exported manually due to ToLua++ generating extra output parameter. */ cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom); - ~cCompositeChat(); + ~cCompositeChat(); // tolua_export + + // The following are exported in ManualBindings in order to support chaining - they return "self" in Lua (#755) /** Removes all parts from the object. */ void Clear(void); - // tolua_end - - // The following are exported in ManualBindings in order to support chaining - they return *this in Lua (#755) - /** Adds a plain text part, with optional style. The default style is plain white text. */ void AddTextPart(const AString & a_Message, const AString & a_Style = ""); @@ -148,8 +146,6 @@ public: /** Adds a part that is translated client-side, with the formatting parameters and optional style. */ void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = ""); - // tolua_begin - /** Adds a part that opens an URL when clicked. The default style is underlined light blue text. */ void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "u@c"); @@ -171,14 +167,14 @@ public: Recognizes "http:" and "https:" URLs and @color-codes. */ void ParseText(const AString & a_ParseText); + /** Adds the "underline" style to each part that is an URL. */ + void UnderlineUrls(void); + /** Sets the message type, which is indicated by prefixes added to the message when serializing Takes optional AdditionalMessageTypeData to set m_AdditionalMessageTypeData. See said variable for more documentation. - */ + Exported manually, because ToLua++ would generate extra return values. */ void SetMessageType(eMessageType a_MessageType, const AString & a_AdditionalMessageTypeData = ""); - /** Adds the "underline" style to each part that is an URL. */ - void UnderlineUrls(void); - // tolua_begin /** Returns the message type set previously by SetMessageType(). */ diff --git a/src/Defines.h b/src/Defines.h index 615beeabd..afd806c4e 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -641,6 +641,7 @@ enum eMessageType mtPrivateMessage, // Player to player messaging identifier mtJoin, // A player has joined the server mtLeave, // A player has left the server + mtMaxPlusOne, // The first invalid type, used for checking on LuaAPI boundaries // Common aliases: mtFail = mtFailure, |