| 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 | 297 | 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 | 297 | LuaHandle(LuaHandle&& rhs) { | ||
| 18 | 297 | m_ptr = rhs.m_ptr; | ||
| 19 | 297 | rhs.m_ptr = nullptr; | ||
| 20 | 297 | } | ||
| 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 | 594 | ~LuaHandle() { | ||
| 32 |
2/2✓ Branch 0 taken 297 times.
✓ Branch 1 taken 297 times.
|
2/2✓ Decision 'true' taken 297 times.
✓ Decision 'false' taken 297 times.
|
594 | if (m_ptr) { |
| 33 | 297 | efiPrintf("LUA: Tearing down instance..."); | ||
| 34 | 297 | lua_close(m_ptr); | ||
| 35 | } | |||
| 36 | 594 | } | ||
| 37 | ||||
| 38 | 4140 | 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 |