GCC Code Coverage Report


Directory: ./
File: firmware/controllers/lua/rusefi_lua.h
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 11 0 11
Functions: 100.0% 4 0 4
Branches: 100.0% 2 0 2
Decisions: 100.0% 2 - 2

Line Branch Decision Exec Source
1 // This file is not named lua.h as it would collide with firmware/ext/lua/src/lua.h
2
3 #pragma once
4
5 #include "lua.hpp"
6
7 class LuaHandle final {
8 public:
9 LuaHandle() : LuaHandle(nullptr) { }
10 309 LuaHandle(lua_State* ptr) : m_ptr(ptr) { }
11
12 // Don't allow copying!
13 LuaHandle(const LuaHandle&) = delete;
14 LuaHandle& operator=(const LuaHandle&) = delete;
15
16 // Allow moving!
17 309 LuaHandle(LuaHandle&& rhs) {
18 309 m_ptr = rhs.m_ptr;
19 309 rhs.m_ptr = nullptr;
20 309 }
21
22 // Move assignment operator
23 LuaHandle& operator=(LuaHandle&& rhs) {
24 m_ptr = rhs.m_ptr;
25 rhs.m_ptr = nullptr;
26
27 return *this;
28 }
29
30 // Destruction cleans up lua state
31 618 ~LuaHandle() {
32
2/2
✓ Branch 0 taken 309 times.
✓ Branch 1 taken 309 times.
2/2
✓ Decision 'true' taken 309 times.
✓ Decision 'false' taken 309 times.
618 if (m_ptr) {
33 309 efiPrintf("LUA: Tearing down instance...");
34 309 lua_close(m_ptr);
35 }
36 618 }
37
38 4284 operator lua_State*() const { return m_ptr; }
39
40 private:
41 lua_State* m_ptr;
42 };
43
44 void startLua();
45
46 #if EFI_UNIT_TEST
47 #include <rusefi/expected.h>
48
49 expected<float> testLuaReturnsNumberOrNil(const char* script);
50 float testLuaReturnsNumber(const char* script);
51 int testLuaReturnsInteger(const char* script);
52 void testLuaExecString(const char* script);
53 #endif
54
55 #if EFI_CAN_SUPPORT
56
57 #include "can.h"
58
59 // Lua CAN rx feature
60 void initLuaCanRx();
61
62 // Called from the Lua loop to process any pending CAN frames
63 int doLuaCanRx(LuaHandle& ls);
64 // Called from the CAN RX thread to queue a frame for Lua consumption
65 void processLuaCan(const size_t busIndex, const CANRxFrame& frame);
66 size_t getLuaCanRxDropped();
67 #endif // EFI_CAN_SUPPORT
68