Skip to content

Commit 8af7ad8

Browse files
Lua Script Debug Fix (#622)
* Lua Script Debug Fix AND Get Args Params * restore wiArgs, change AttachScript as one liner * cleanups * revert argument changes Co-authored-by: Turánszki János <turanszkij@users.noreply.github.com>
1 parent 4f4c725 commit 8af7ad8

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

WickedEngine/wiArguments.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ namespace wi::arguments
3737
{
3838
return params.find(value) != params.end();
3939
}
40-
4140
}

WickedEngine/wiLua.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,29 @@ namespace wi::lua
5454
return scriptpid_next.fetch_add(1);
5555
}
5656

57-
uint32_t AttachScriptParameters(std::string& script, const std::string& filename, uint32_t PID, const std::string& customparameters_prepend, const std::string& customparameters_append)
58-
{
59-
static const std::string persistent_inject = R"(
60-
local runProcess = function(func)
61-
success, co = Internal_runProcess(script_file(), script_pid(), func)
62-
return success, co
63-
end
64-
if _ENV.PROCESSES_DATA[script_pid()] == nil then
65-
_ENV.PROCESSES_DATA[script_pid()] = { _INITIALIZED = -1 }
66-
end
67-
if _ENV.PROCESSES_DATA[script_pid()]._INITIALIZED < 1 then
68-
_ENV.PROCESSES_DATA[script_pid()]._INITIALIZED = _ENV.PROCESSES_DATA[script_pid()]._INITIALIZED + 1
69-
end
70-
)";
57+
uint32_t AttachScriptParameters(std::string& script, const std::string& filename, uint32_t PID, const std::string& customparameters_prepend, const std::string& customparameters_append)
58+
{
59+
static const std::string persistent_inject =
60+
"local runProcess = function(func) "
61+
" success, co = Internal_runProcess(script_file(), script_pid(), func);"
62+
" return success, co;"
63+
"end;"
64+
"if _ENV.PROCESSES_DATA[script_pid()] == nil then"
65+
" _ENV.PROCESSES_DATA[script_pid()] = { _INITIALIZED = -1 };"
66+
"end;"
67+
"if _ENV.PROCESSES_DATA[script_pid()]._INITIALIZED < 1 then"
68+
" _ENV.PROCESSES_DATA[script_pid()]._INITIALIZED = _ENV.PROCESSES_DATA[script_pid()]._INITIALIZED + 1;"
69+
"end;";
7170

7271
// Make sure the file path doesn't contain backslash characters, replace them with forward slash.
7372
// - backslash would be recognized by lua as escape character
7473
// - the path string could be coming from unknown location (content, programmer, filepicker), so always do this
7574
std::string filepath = filename;
7675
std::replace(filepath.begin(), filepath.end(), '\\', '/');
7776

78-
std::string dynamic_inject = "local function script_file() return \"" + filepath + "\" end\n";
79-
dynamic_inject += "local function script_pid() return \"" + std::to_string(PID) + "\" end\n";
80-
dynamic_inject += "local function script_dir() return \"" + wi::helper::GetDirectoryFromPath(filepath) + "\" end\n";
77+
std::string dynamic_inject = "local function script_file() return \"" + filepath + "\" end;";
78+
dynamic_inject += "local function script_pid() return \"" + std::to_string(PID) + "\" end;";
79+
dynamic_inject += "local function script_dir() return \"" + wi::helper::GetDirectoryFromPath(filepath) + "\" end;";
8180
dynamic_inject += persistent_inject;
8281
script = dynamic_inject + customparameters_prepend + script + customparameters_append;
8382

@@ -537,12 +536,11 @@ namespace wi::lua
537536
{
538537
ss += error;
539538
}
540-
wi::backlog::post(ss);
539+
wi::backlog::post(ss, wi::backlog::LogLevel::Error);
541540
}
542541

543542
void SAddMetatable(lua_State* L, const std::string& name)
544543
{
545544
luaL_newmetatable(L, name.c_str());
546545
}
547-
548546
}

WickedEngine/wiLua.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace wi::lua
6666

6767
// Adds some local management functions to the script
6868
// returns the PID
69-
uint32_t AttachScriptParameters(std::string& script, const std::string& filename = "", uint32_t PID = GeneratePID(), const std::string& customparameters_prepend = "", const std::string& customparameters_append = "");
69+
uint32_t AttachScriptParameters(std::string& script, const std::string& filename = "", uint32_t PID = GeneratePID(), const std::string& customparameters_prepend = "", const std::string& customparameters_append = "");
7070

7171
//Following functions are "static", operating on specified lua state:
7272

WickedEngine/wiScene.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,9 +4230,8 @@ namespace wi::scene
42304230
{
42314231
if (script.script.empty() && script.resource.IsValid())
42324232
{
4233-
script.script += "local function GetEntity() return " + std::to_string(entity) + "; end\n";
42344233
script.script += script.resource.GetScript();
4235-
wi::lua::AttachScriptParameters(script.script, script.filename);
4234+
wi::lua::AttachScriptParameters(script.script, script.filename, wi::lua::GeneratePID(), "local function GetEntity() return " + std::to_string(entity) + "; end;", "");
42364235
}
42374236
wi::lua::RunText(script.script);
42384237

WickedEngine/wiVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace wi::version
99
// minor features, major updates, breaking compatibility changes
1010
const int minor = 71;
1111
// minor bug fixes, alterations, refactors, updates
12-
const int revision = 137;
12+
const int revision = 138;
1313

1414
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
1515

0 commit comments

Comments
 (0)