1
0

Fixed cCompositeChat's constructor LuaAPI bindings.

The tolua-generated constructor would return an extra string value.
This commit is contained in:
Mattes D 2016-09-25 12:42:05 +02:00
parent af4e88030b
commit e169043a84
6 changed files with 253 additions and 37 deletions

View File

@ -3698,11 +3698,13 @@ end
},
Clear =
{
Returns = "self",
Notes = "Removes all parts from this object",
},
constructor =
{
{
Returns = { {Type = "cCompositeChat"} },
Notes = "Creates an empty chat message",
},
{
@ -3718,6 +3720,7 @@ end
IsOptional = true,
},
},
Returns = { {Type = "cCompositeChat"} },
Notes = "Creates a chat message containing the specified text, parsed by the ParseText() function. This allows easy migration from old chat messages.",
},
},
@ -10100,7 +10103,7 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Returns =
@ -10110,7 +10113,7 @@ a_Player:OpenWindow(Window);
Type = "cMonster#eFamily",
},
},
Notes = "Returns the mob family ({{cMonster#eFamily|mfXXX}} constants) based on the mob type ({{Globals#eMobType|mtXXX}} constants)",
Notes = "Returns the mob family ({{cMonster#eFamily|mfXXX}} constants) based on the mob type ({{Globals#eMonsterType|mtXXX}} constants)",
},
GetAge =
{
@ -10149,10 +10152,10 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Notes = "Returns the type of this mob ({{Globals#eMobType|mtXXX}} constant)",
Notes = "Returns the type of this mob ({{Globals#eMonsterType|mtXXX}} constant)",
},
GetRelativeWalkSpeed =
{
@ -10219,7 +10222,7 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Returns =
@ -10228,7 +10231,7 @@ a_Player:OpenWindow(Window);
Type = "string",
},
},
Notes = "Returns the string representing the given mob type ({{Globals#eMobType|mtXXX}} constant), or empty string if unknown type.",
Notes = "Returns the string representing the given mob type ({{Globals#eMonsterType|mtXXX}} constant), or empty string if unknown type.",
},
MobTypeToVanillaName =
{
@ -10317,10 +10320,10 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Notes = "Returns the mob type ({{Globals#eMobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized.",
Notes = "Returns the mob type ({{Globals#eMonsterType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized.",
},
},
Constants =
@ -18497,6 +18500,66 @@ World:ForEachEntity(
{
Notes = "A wither skull explosion. The SourceData param is the {{cWitherSkullEntity|wither skull entity}} object.",
},
mtCustom =
{
Notes = "Send raw data without any processing",
},
mtDeath =
{
Notes = "Denotes death of player",
},
mtError =
{
Notes = "Something could not be done (i.e. command not executed due to insufficient privilege)",
},
mtFail =
{
Notes = "Something could not be done (i.e. command not executed due to insufficient privilege)",
},
mtFailure =
{
Notes = "Something could not be done (i.e. command not executed due to insufficient privilege)",
},
mtFatal =
{
Notes = "Something catastrophic occured (i.e. plugin crash)",
},
mtInfo =
{
Notes = "Informational message (i.e. command usage)",
},
mtInformation =
{
Notes = "Informational message (i.e. command usage)",
},
mtJoin =
{
Notes = "A player has joined the server",
},
mtLeave =
{
Notes = "A player has left the server",
},
mtMaxPlusOne =
{
Notes = "The first invalid type, used for checking on LuaAPI boundaries",
},
mtPM =
{
Notes = "Player to player messaging identifier",
},
mtPrivateMessage =
{
Notes = "Player to player messaging identifier",
},
mtSuccess =
{
Notes = "Something executed successfully",
},
mtWarning =
{
Notes = "Something concerning (i.e. reload) is about to happen",
},
},
ConstantGroups =
{
@ -18590,11 +18653,70 @@ World:ForEachEntity(
StringToBiome() function that can convert a string into one of these constants.
]],
},
eMobType =
eMessageType =
{
-- Need to be specified explicitly, because there's also eMonsterType using the same "mt" prefix
Include =
{
"mtCustom",
"mtDeath",
"mtError",
"mtFail",
"mtFailure",
"mtFatal",
"mtInfo",
"mtInformation",
"mtJoin",
"mtLeave",
"mtMaxPlusOne",
"mtPrivateMessage",
"mtPM",
"mtSuccess",
"mtWarning",
},
TextBefore = [[
These constants are used together with messaging functions and classes, they specify the type of
message being sent. The server can be configured to modify the message text (add prefixes) based
on the message's type.
]],
},
eMonsterType =
{
Include =
{
"^mt.*",
"mtInvalidType",
"mtBat",
"mtBlaze",
"mtCaveSpider",
"mtChicken",
"mtCow",
"mtCreeper",
"mtEnderDragon",
"mtEnderman",
"mtGhast",
"mtGiant",
"mtGuardian",
"mtHorse",
"mtIronGolem",
"mtMagmaCube",
"mtMooshroom",
"mtOcelot",
"mtPig",
"mtRabbit",
"mtSheep",
"mtSilverfish",
"mtSkeleton",
"mtSlime",
"mtSnowGolem",
"mtSpider",
"mtSquid",
"mtVillager",
"mtWitch",
"mtWither",
"mtWolf",
"mtZombie",
"mtZombiePigman",
"mtMax",
},
TextBefore = [[
The following constants are used for distinguishing between the individual mob types:

View File

@ -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);

View File

@ -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
}

View File

@ -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
}

View File

@ -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);
/** 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.
*/
void SetMessageType(eMessageType a_MessageType, const AString & a_AdditionalMessageTypeData = "");
/** 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 = "");
// tolua_begin
/** Returns the message type set previously by SetMessageType(). */

View File

@ -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,