commit
439eb8d6cb
@ -2965,6 +2965,7 @@ end
|
|||||||
RotateBlockFaceCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise." },
|
RotateBlockFaceCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise." },
|
||||||
StringSplit = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered."},
|
StringSplit = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered."},
|
||||||
StringSplitAndTrim = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Each of the separate strings is trimmed (whitespace removed from the beginning and end of the string)"},
|
StringSplitAndTrim = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Each of the separate strings is trimmed (whitespace removed from the beginning and end of the string)"},
|
||||||
|
StringSplitWithQuotes = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Whitespace wrapped with single or double quotes will be ignored"},
|
||||||
StringToBiome = {Params = "string", Return = "{{Globals#BiomeTypes|BiomeType}}", Notes = "Converts a string representation to a {{Globals#BiomeTypes|BiomeType}} enumerated value"},
|
StringToBiome = {Params = "string", Return = "{{Globals#BiomeTypes|BiomeType}}", Notes = "Converts a string representation to a {{Globals#BiomeTypes|BiomeType}} enumerated value"},
|
||||||
StringToDamageType = {Params = "string", Return = "{{Globals#DamageType|DamageType}}", Notes = "Converts a string representation to a {{Globals#DamageType|DamageType}} enumerated value."},
|
StringToDamageType = {Params = "string", Return = "{{Globals#DamageType|DamageType}}", Notes = "Converts a string representation to a {{Globals#DamageType|DamageType}} enumerated value."},
|
||||||
StringToDimension = {Params = "string", Return = "{{Globals#WorldDimension|Dimension}}", Notes = "Converts a string representation to a {{Globals#WorldDimension|Dimension}} enumerated value"},
|
StringToDimension = {Params = "string", Return = "{{Globals#WorldDimension|Dimension}}", Notes = "Converts a string representation to a {{Globals#WorldDimension|Dimension}} enumerated value"},
|
||||||
|
@ -266,6 +266,24 @@ static int tolua_StringSplit(lua_State * tolua_S)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int tolua_StringSplitWithQuotes(lua_State * tolua_S)
|
||||||
|
{
|
||||||
|
cLuaState S(tolua_S);
|
||||||
|
|
||||||
|
AString str;
|
||||||
|
AString delim;
|
||||||
|
|
||||||
|
S.GetStackValues(1, str, delim);
|
||||||
|
|
||||||
|
AStringVector Split = StringSplitWithQuotes(str, delim);
|
||||||
|
S.Push(Split);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int tolua_StringSplitAndTrim(lua_State * tolua_S)
|
static int tolua_StringSplitAndTrim(lua_State * tolua_S)
|
||||||
{
|
{
|
||||||
cLuaState LuaState(tolua_S);
|
cLuaState LuaState(tolua_S);
|
||||||
@ -3663,6 +3681,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
|||||||
// Globals:
|
// Globals:
|
||||||
tolua_function(tolua_S, "Clamp", tolua_Clamp);
|
tolua_function(tolua_S, "Clamp", tolua_Clamp);
|
||||||
tolua_function(tolua_S, "StringSplit", tolua_StringSplit);
|
tolua_function(tolua_S, "StringSplit", tolua_StringSplit);
|
||||||
|
tolua_function(tolua_S, "StringSplitWithQuotes", tolua_StringSplitWithQuotes);
|
||||||
tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim);
|
tolua_function(tolua_S, "StringSplitAndTrim", tolua_StringSplitAndTrim);
|
||||||
tolua_function(tolua_S, "LOG", tolua_LOG);
|
tolua_function(tolua_S, "LOG", tolua_LOG);
|
||||||
tolua_function(tolua_S, "LOGINFO", tolua_LOGINFO);
|
tolua_function(tolua_S, "LOGINFO", tolua_LOGINFO);
|
||||||
|
@ -111,12 +111,12 @@ public:
|
|||||||
Command permissions have already been checked.
|
Command permissions have already been checked.
|
||||||
Returns true if command handled successfully
|
Returns true if command handled successfully
|
||||||
*/
|
*/
|
||||||
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player) = 0;
|
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player, const AString & a_FullCommand) = 0;
|
||||||
|
|
||||||
/** Handles the console command split into a_Split.
|
/** Handles the console command split into a_Split.
|
||||||
Returns true if command handled successfully. Output is to be sent to the a_Output callback.
|
Returns true if command handled successfully. Output is to be sent to the a_Output callback.
|
||||||
*/
|
*/
|
||||||
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output) = 0;
|
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_FullCommand) = 0;
|
||||||
|
|
||||||
/// All bound commands are to be removed, do any language-dependent cleanup here
|
/// All bound commands are to be removed, do any language-dependent cleanup here
|
||||||
virtual void ClearCommands(void) {}
|
virtual void ClearCommands(void) {}
|
||||||
|
@ -1465,7 +1465,7 @@ bool cPluginLua::OnWorldTick(cWorld & a_World, std::chrono::milliseconds a_Dt, s
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player)
|
bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player, const AString & a_FullCommand)
|
||||||
{
|
{
|
||||||
ASSERT(!a_Split.empty());
|
ASSERT(!a_Split.empty());
|
||||||
CommandMap::iterator cmd = m_Commands.find(a_Split[0]);
|
CommandMap::iterator cmd = m_Commands.find(a_Split[0]);
|
||||||
@ -1477,7 +1477,7 @@ bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player
|
|||||||
|
|
||||||
cCSLock Lock(m_CriticalSection);
|
cCSLock Lock(m_CriticalSection);
|
||||||
bool res = false;
|
bool res = false;
|
||||||
m_LuaState.Call(cmd->second, a_Split, &a_Player, cLuaState::Return, res);
|
m_LuaState.Call(cmd->second, a_Split, &a_Player, a_FullCommand, cLuaState::Return, res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1485,7 +1485,7 @@ bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
|
bool cPluginLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_FullCommand)
|
||||||
{
|
{
|
||||||
ASSERT(!a_Split.empty());
|
ASSERT(!a_Split.empty());
|
||||||
CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]);
|
CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]);
|
||||||
@ -1500,7 +1500,7 @@ bool cPluginLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOut
|
|||||||
cCSLock Lock(m_CriticalSection);
|
cCSLock Lock(m_CriticalSection);
|
||||||
bool res = false;
|
bool res = false;
|
||||||
AString str;
|
AString str;
|
||||||
m_LuaState.Call(cmd->second, a_Split, cLuaState::Return, res, str);
|
m_LuaState.Call(cmd->second, a_Split, a_FullCommand, cLuaState::Return, res, str);
|
||||||
if (res && !str.empty())
|
if (res && !str.empty())
|
||||||
{
|
{
|
||||||
a_Output.Out(str);
|
a_Output.Out(str);
|
||||||
|
@ -131,9 +131,9 @@ public:
|
|||||||
virtual bool OnWorldStarted (cWorld & a_World) override;
|
virtual bool OnWorldStarted (cWorld & a_World) override;
|
||||||
virtual bool OnWorldTick (cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) override;
|
virtual bool OnWorldTick (cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) override;
|
||||||
|
|
||||||
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player) override;
|
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player, const AString & a_FullCommand) override;
|
||||||
|
|
||||||
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output) override;
|
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_FullCommand) override;
|
||||||
|
|
||||||
virtual void ClearCommands(void) override;
|
virtual void ClearCommands(void) override;
|
||||||
|
|
||||||
|
@ -1465,7 +1465,7 @@ cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer & a_Player,
|
|||||||
|
|
||||||
ASSERT(cmd->second.m_Plugin != nullptr);
|
ASSERT(cmd->second.m_Plugin != nullptr);
|
||||||
|
|
||||||
if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player))
|
if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player, a_Command))
|
||||||
{
|
{
|
||||||
return crError;
|
return crError;
|
||||||
}
|
}
|
||||||
@ -1768,7 +1768,7 @@ bool cPluginManager::IsConsoleCommandBound(const AString & a_Command)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginManager::ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
|
bool cPluginManager::ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_Command)
|
||||||
{
|
{
|
||||||
if (a_Split.empty())
|
if (a_Split.empty())
|
||||||
{
|
{
|
||||||
@ -1795,7 +1795,7 @@ bool cPluginManager::ExecuteConsoleCommand(const AStringVector & a_Split, cComma
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd->second.m_Plugin->HandleConsoleCommand(a_Split, a_Output);
|
return cmd->second.m_Plugin->HandleConsoleCommand(a_Split, a_Output, a_Command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ public:
|
|||||||
bool IsConsoleCommandBound(const AString & a_Command); // tolua_export
|
bool IsConsoleCommandBound(const AString & a_Command); // tolua_export
|
||||||
|
|
||||||
/** Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback */
|
/** Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback */
|
||||||
bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output);
|
bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_Command);
|
||||||
|
|
||||||
/** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
|
/** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
|
||||||
If a_Player is not nullptr, only commands for which the player has permissions are added.
|
If a_Player is not nullptr, only commands for which the player has permissions are added.
|
||||||
|
@ -549,7 +549,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
else if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output))
|
else if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output, a_Cmd))
|
||||||
{
|
{
|
||||||
a_Output.Finished();
|
a_Output.Finished();
|
||||||
return;
|
return;
|
||||||
|
@ -140,6 +140,54 @@ AStringVector StringSplit(const AString & str, const AString & delim)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AStringVector StringSplitWithQuotes(const AString & str, const AString & delim)
|
||||||
|
{
|
||||||
|
AStringVector results;
|
||||||
|
|
||||||
|
size_t cutAt = 0;
|
||||||
|
size_t Prev = 0;
|
||||||
|
size_t cutAtQuote = 0;
|
||||||
|
|
||||||
|
while ((cutAt = str.find_first_of(delim, Prev)) != str.npos)
|
||||||
|
{
|
||||||
|
AString current = str.substr(Prev, cutAt - Prev);
|
||||||
|
if ((current.at(0) == '"') || (current.at(0) == '\''))
|
||||||
|
{
|
||||||
|
Prev += 1;
|
||||||
|
cutAtQuote = str.find_first_of(current.at(0), Prev);
|
||||||
|
if (cutAtQuote != str.npos)
|
||||||
|
{
|
||||||
|
current = str.substr(Prev, cutAtQuote - Prev);
|
||||||
|
cutAt = cutAtQuote + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
results.push_back(current);
|
||||||
|
Prev = cutAt + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Prev < str.length())
|
||||||
|
{
|
||||||
|
AString current = str.substr(Prev);
|
||||||
|
|
||||||
|
// If the remant is wrapped in matching quotes, remove them:
|
||||||
|
if (
|
||||||
|
(current.length() >= 2) &&
|
||||||
|
((current.front() == '"') || (current.front() == '\'')) &&
|
||||||
|
(current.front() == current.back())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
current = current.substr(1, current.length() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.push_back(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AStringVector StringSplitAndTrim(const AString & str, const AString & delim)
|
AStringVector StringSplitAndTrim(const AString & str, const AString & delim)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,11 @@ extern AString & AppendPrintf (AString & a_Dst, const char * format, ...) FORMAT
|
|||||||
Return the splitted strings as a stringvector. */
|
Return the splitted strings as a stringvector. */
|
||||||
extern AStringVector StringSplit(const AString & str, const AString & delim);
|
extern AStringVector StringSplit(const AString & str, const AString & delim);
|
||||||
|
|
||||||
|
/** Split the string at any of the listed delimiters. Keeps quoted content together
|
||||||
|
Resolves issue #490
|
||||||
|
Return the splitted strings as a stringvector. */
|
||||||
|
extern AStringVector StringSplitWithQuotes(const AString & str, const AString & delim);
|
||||||
|
|
||||||
/** Split the string at any of the listed delimiters and trim each value.
|
/** Split the string at any of the listed delimiters and trim each value.
|
||||||
Returns the splitted strings as a stringvector. */
|
Returns the splitted strings as a stringvector. */
|
||||||
extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
|
extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
|
||||||
|
Loading…
Reference in New Issue
Block a user