From 41b99b0593b492b3a119412924345c4c650bf17b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 28 Oct 2021 05:18:56 -0700 Subject: [PATCH] make lua CAN happy (#3416) * lua can tx * index * make rx match --- firmware/controllers/lua/lua_can_rx.cpp | 4 +++- firmware/controllers/lua/lua_hooks.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/lua/lua_can_rx.cpp b/firmware/controllers/lua/lua_can_rx.cpp index fedf065294..979140d5ae 100644 --- a/firmware/controllers/lua/lua_can_rx.cpp +++ b/firmware/controllers/lua/lua_can_rx.cpp @@ -78,7 +78,9 @@ static void handleCanFrame(LuaHandle& ls, CANRxFrame* frame) { lua_newtable(ls); for (size_t i = 0; i < dlc; i++) { lua_pushinteger(ls, frame->data8[i]); - lua_rawseti(ls, -2, i); + + // index is i+1 because Lua "arrays" (tables) are 1-indexed + lua_rawseti(ls, -2, i + 1); } // Perform the actual function call diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index e1a4c23ce0..3f406e58d4 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -125,7 +125,7 @@ static int lua_txCan(lua_State* l) { while (true) { lua_pushnumber(l, dlc + 1); auto elementType = lua_gettable(l, 4); - auto val = lua_tointeger(l, -1); + auto val = lua_tonumber(l, -1); lua_pop(l, 1); if (elementType == LUA_TNIL) {