From 80ff5e3e633a42fb64117865a4930fc0e0a23b1c Mon Sep 17 00:00:00 2001 From: Pelanyo Kamara Date: Tue, 9 Nov 2021 15:38:33 +0000 Subject: [PATCH] fix logic issue --- .github/workflows/build.yml | 2 +- CLI/Repl.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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();