From 0731dbb4797269a43fab692e229099d920523a53 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 19 Aug 2021 12:14:02 -0700 Subject: [PATCH] lua pass alloc and script (#3179) * pass alloc and script * pass in all the spots --- firmware/controllers/lua/lua.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index 45a70ce04c..04c0c92a8c 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -97,8 +97,8 @@ static int lua_setTickRate(lua_State* l) { return 0; } -static LuaHandle setupLuaState() { - LuaHandle ls = lua_newstate(myAlloc, NULL); +static LuaHandle setupLuaState(lua_Alloc alloc) { + LuaHandle ls = lua_newstate(alloc, NULL); if (!ls) { firmwareError(OBD_PCM_Processor_Fault, "Failed to start Lua interpreter"); @@ -213,10 +213,10 @@ static bool needsReset = false; // Returns true if it should be re-called immediately, // or false if there was a problem setting up the interpreter // or parsing the script. -static bool runOneLua() { +static bool runOneLua(lua_Alloc alloc, const char* script) { needsReset = false; - auto ls = setupLuaState(); + auto ls = setupLuaState(alloc); // couldn't start Lua interpreter, bail out if (!ls) { @@ -226,7 +226,7 @@ static bool runOneLua() { // Reset default tick rate luaTickPeriodMs = 100; - if (!loadScript(ls, config->luaScript)) { + if (!loadScript(ls, script)) { return false; } @@ -249,7 +249,7 @@ void LuaThread::ThreadTask() { chHeapObjectInit(&heap, &luaHeap, sizeof(luaHeap)); while (!chThdShouldTerminateX()) { - bool wasOk = runOneLua(); + bool wasOk = runOneLua(myAlloc, config->luaScript); if (!wasOk) { // Something went wrong executing the script, spin @@ -297,7 +297,7 @@ void startLua() { #include static LuaHandle runScript(const char* script) { - auto ls = setupLuaState(); + auto ls = setupLuaState(myAlloc); if (!ls) { throw new std::logic_error("Call to setupLuaState failed, returned null"); @@ -363,7 +363,7 @@ int testLuaReturnsInteger(const char* script) { } void testLuaExecString(const char* script) { - auto ls = setupLuaState(); + auto ls = setupLuaState(myAlloc); if (!ls) { throw new std::logic_error("Call to setupLuaState failed, returned null");