Skip to content

Commit

Permalink
Fixed cCompositeChat's constructor LuaAPI bindings.
Browse files Browse the repository at this point in the history
The tolua-generated constructor would return an extra string value.
  • Loading branch information
madmaxoft committed Sep 25, 2016
1 parent af4e880 commit e169043
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 36 deletions.
144 changes: 133 additions & 11 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand All @@ -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.",
},
},
Expand Down Expand Up @@ -10100,7 +10103,7 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Returns =
Expand All @@ -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 =
{
Expand Down Expand Up @@ -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 =
{
Expand Down Expand Up @@ -10219,7 +10222,7 @@ a_Player:OpenWindow(Window);
{
{
Name = "MobType",
Type = "Globals#eMobType",
Type = "Globals#eMonsterType",
},
},
Returns =
Expand All @@ -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 =
{
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
{
Expand Down Expand Up @@ -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:
Expand All @@ -18604,7 +18726,7 @@ World:ForEachEntity(
{
Include = "^sl.*",
TextBefore = [[
The following constants define the block types that are propelled outwards after an explosion.
The following constants define the block types that are propelled outwards after an explosion.
]],
},
eSpreadSource =
Expand Down
104 changes: 102 additions & 2 deletions src/Bindings/ManualBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/ClientHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 "";
}


Expand Down
Loading

0 comments on commit e169043

Please sign in to comment.