diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34ee71cf..cdee2f6c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,4 +82,4 @@ jobs: - uses: actions/upload-artifact@v2 with: name: coverage - path: coverage \ No newline at end of file + path: coverage diff --git a/CLI/Repl.cpp b/CLI/Repl.cpp index a3880b5f..0b50f0c4 100644 --- a/CLI/Repl.cpp +++ b/CLI/Repl.cpp @@ -204,6 +204,9 @@ extern "C" { const char* executeScript(const char* source) { + // static string for caching result (prevents dangling ptr on function exit) + static std::string result; + // setup flags for (Luau::FValue* flag = Luau::FValue::list; flag; flag = flag->next) if (strncmp(flag->name, "Luau", 4) == 0) @@ -221,9 +224,8 @@ extern "C" // run code + collect error std::string error = runCode(L, source); - - // output error(s) - static std::string result = error; + result = error; + if (error.length()) { return result.c_str();