Fix empty string being discarded at beginning of lua log/return lists

This commit is contained in:
jacob1 2022-10-19 17:28:04 -04:00
parent b306c2c33c
commit 6338da7cb7
No known key found for this signature in database
GPG Key ID: 4E58A32D510E1995
3 changed files with 29 additions and 10 deletions

View File

@ -413,24 +413,32 @@ int luatpt_setconsole(lua_State* l)
luacon_controller->HideConsole();
return 0;
}
int luatpt_log(lua_State* l)
{
int args = lua_gettop(l);
String text;
bool hasText = false;
for(int i = 1; i <= args; i++)
{
luaL_tostring(l, -1);
if(text.length())
text=tpt_lua_optString(l, -1, "") + ", " + text;
if (hasText)
{
text = tpt_lua_optString(l, -1, "") + ", " + text;
}
else
text=tpt_lua_optString(l, -1, "");
{
text = tpt_lua_optString(l, -1, "");
hasText = true;
}
lua_pop(l, 2);
}
if((*luacon_currentCommand))
if ((*luacon_currentCommand))
{
if(luacon_lastError->length())
if (luacon_hasLastError)
*luacon_lastError += "; ";
*luacon_lastError += text;
luacon_hasLastError = true;
}
else
luacon_ci->Log(CommandInterface::LogNotice, text);

View File

@ -22,6 +22,7 @@ extern Renderer * luacon_ren;
extern bool *luacon_currentCommand;
extern String *luacon_lastError;
extern bool luacon_hasLastError;
class LuaSmartRef;
extern int *lua_el_mode;

View File

@ -82,6 +82,7 @@ Renderer * luacon_ren;
bool *luacon_currentCommand;
String *luacon_lastError;
bool luacon_hasLastError;
String lastCode;
int *lua_el_mode;
@ -231,6 +232,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
luacon_currentCommand = &currentCommand;
luacon_lastError = &lastError;
luacon_hasLastError = false;
lastCode = "";
@ -4343,9 +4345,10 @@ void LuaScriptInterface::OnTick()
int LuaScriptInterface::Command(String command)
{
lastError = "";
luacon_hasLastError = false;
if (command[0] == '!')
{
lastError = "";
int ret = legacy->Command(command.Substr(1));
lastError = legacy->GetLastError();
return ret;
@ -4353,8 +4356,6 @@ int LuaScriptInterface::Command(String command)
else
{
int level = lua_gettop(l), ret = -1;
String text = "";
lastError = "";
currentCommand = true;
if (lastCode.length())
lastCode += "\n";
@ -4382,16 +4383,25 @@ int LuaScriptInterface::Command(String command)
lastCode = "";
ret = lua_pcall(l, 0, LUA_MULTRET, 0);
if (ret)
{
lastError = luacon_geterror();
}
else
{
for (level++;level<=lua_gettop(l);level++)
String text = "";
bool hasText = false;
for (level++; level <= lua_gettop(l); level++)
{
luaL_tostring(l, level);
if (text.length())
if (hasText)
{
text += ", " + tpt_lua_optString(l, -1, "");
}
else
{
text = tpt_lua_optString(l, -1, "");
hasText = true;
}
lua_pop(l, 1);
}
if (text.length())