lua pass alloc and script (#3179)

* pass alloc and script

* pass in all the spots
This commit is contained in:
Matthew Kennedy 2021-08-19 12:14:02 -07:00 committed by GitHub
parent be29b11d05
commit 0731dbb479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -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 <string>
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");