rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
rusefi_lua.h
Go to the documentation of this file.
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
7class LuaHandle final {
8public:
9 LuaHandle() : LuaHandle(nullptr) { }
10 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!
18 m_ptr = rhs.m_ptr;
19 rhs.m_ptr = nullptr;
20 }
21
22 // Move assignment operator
24 m_ptr = rhs.m_ptr;
25 rhs.m_ptr = nullptr;
26
27 return *this;
28 }
29
30 // Destruction cleans up lua state
32 if (m_ptr) {
33 efiPrintf("LUA: Tearing down instance...");
34 lua_close(m_ptr);
35 }
36 }
37
38 operator lua_State*() const { return m_ptr; }
39
40private:
41 lua_State* m_ptr;
42};
43
44void startLua();
45
46#if EFI_UNIT_TEST
47#include <rusefi/expected.h>
48
49expected<float> testLuaReturnsNumberOrNil(const char* script);
50float testLuaReturnsNumber(const char* script);
51int testLuaReturnsInteger(const char* script);
52void testLuaExecString(const char* script);
53#endif
54
55#if EFI_CAN_SUPPORT
56
57#include "can.h"
58
59// Lua CAN rx feature
60void initLuaCanRx();
61
62// Called from the Lua loop to process any pending CAN frames
63int doLuaCanRx(LuaHandle& ls);
64// Called from the CAN RX thread to queue a frame for Lua consumption
65void processLuaCan(const size_t busIndex, const CANRxFrame& frame);
66size_t getLuaCanRxDropped();
67#endif // EFI_CAN_SUPPORT
LuaHandle(const LuaHandle &)=delete
lua_State * m_ptr
Definition rusefi_lua.h:41
LuaHandle(LuaHandle &&rhs)
Definition rusefi_lua.h:17
LuaHandle & operator=(const LuaHandle &)=delete
LuaHandle(lua_State *ptr)
Definition rusefi_lua.h:10
LuaHandle & operator=(LuaHandle &&rhs)
Definition rusefi_lua.h:23
int doLuaCanRx(LuaHandle &ls)
float testLuaReturnsNumber(const char *script)
Definition lua.cpp:371
void processLuaCan(const size_t busIndex, const CANRxFrame &frame)
size_t getLuaCanRxDropped()
void testLuaExecString(const char *script)
Definition lua.cpp:394
expected< float > testLuaReturnsNumberOrNil(const char *script)
Definition lua.cpp:354
void startLua()
Definition lua.cpp:281
void initLuaCanRx()
int testLuaReturnsInteger(const char *script)
Definition lua.cpp:383