rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
lua_hooks_util.h File Reference

Functions

void configureRusefiLuaUtilHooks (lua_State *l)
 

Function Documentation

◆ configureRusefiLuaUtilHooks()

void configureRusefiLuaUtilHooks ( lua_State *  l)

Definition at line 39 of file lua_hooks_util.cpp.

39 {
40 lua_register(lState, "print", lua_efi_print);
41 lua_register(lState, "interpolate", lua_interpolate);
42
43 lua_register(lState, "findCurveIndex", [](lua_State* l) {
44 auto name = luaL_checklstring(l, 1, nullptr);
45 auto result = getCurveIndexByName(name);
46 if (!result) {
47 lua_pushnil(l);
48 } else {
49 // TS counts curve from 1 so convert indexing here
50 lua_pushnumber(l, result.Value + HUMAN_OFFSET);
51 }
52 return 1;
53 });
54
55 lua_register(lState, "findTableIndex",
56 [](lua_State* l) {
57 auto name = luaL_checklstring(l, 1, nullptr);
58 auto index = getTableIndexByName(name);
59 if (!index) {
60 lua_pushnil(l);
61 } else {
62 // TS counts curve from 1 so convert indexing here
63 lua_pushnumber(l, index.Value + HUMAN_OFFSET);
64 }
65 return 1;
66 });
67
68 lua_register(lState, "findSetting",
69 [](lua_State* l) {
70 auto name = luaL_checklstring(l, 1, nullptr);
71 auto defaultValue = luaL_checknumber(l, 2);
72
73 auto index = getSettingIndexByName(name);
74 if (!index) {
75 lua_pushnumber(l, defaultValue);
76 } else {
77 // TS counts curve from 1 so convert indexing here
78 lua_pushnumber(l, engineConfiguration->scriptSetting[index.Value]);
79 }
80 return 1;
81 });
82
83#ifndef STARTUP_STANDBY_PROHIBITED_PERIOD_SEC
84#define STARTUP_STANDBY_PROHIBITED_PERIOD_SEC 3
85#endif
86
87// works on STM32F4 and STM32F7 but only on specific boards
88// (it's all about PA0 being not used by ADC etc)
89#if defined(LUA_STM32_STANDBY)
90 lua_register(lState, "mcu_standby", [](lua_State*) {
91 if (getTimeNowS() < STARTUP_STANDBY_PROHIBITED_PERIOD_SEC) {
92 criticalError("mcu_standby invoked right on start");
93 return 0;
94 }
97 return 0;
98 });
99#endif
100
101/*
102 * todo: shall we? same for milliseconds?
103 lua_register(l, "getNowSeconds", [](lua_State* l) -> int {
104 int result = getTimeNowS();
105 lua_pushnumber(l, result);
106 return 1;
107 });
108*/
109}
void stm32_standby()
Definition mpu_util.cpp:18
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
Definition efitime.cpp:42
static constexpr engine_configuration_s * engineConfiguration
void onBoardStandBy()
static int lua_efi_print(lua_State *l)
static int lua_interpolate(lua_State *l)
expected< int > getSettingIndexByName(const char *name)
expected< int > getTableIndexByName(const char *name)
expected< int > getCurveIndexByName(const char *name)

Referenced by configureRusefiLuaHooks().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.