◆ doInteractive()
Definition at line 228 of file lua.cpp.
238 if (lua_isinteger(ls, -1)) {
239 efiPrintf(TAG
"interactive returned integer: %d", lua_tointeger(ls, -1));
240 }
else if (lua_isnumber(ls, -1)) {
241 efiPrintf(TAG
"interactive returned number: %f", lua_tonumber(ls, -1));
242 }
else if (lua_isstring(ls, -1)) {
243 efiPrintf(TAG
"interactive returned string: '%s'", lua_tostring(ls, -1));
244 }
else if (lua_isboolean(ls, -1)) {
245 efiPrintf(TAG
"interactive returned bool: %s", lua_toboolean(ls, -1) ?
"true" :
"false");
246 }
else if (lua_isnil(ls, -1)) {
247 efiPrintf(TAG
"interactive returned nil.");
249 efiPrintf(TAG
"interactive returned nothing.");
253 efiPrintf(TAG
"interactive error: %s", lua_tostring(ls, -1));
static char interactiveCmd[100]
static bool interactivePending
Referenced by runOneLua().
◆ invokeTick()
Definition at line 261 of file lua.cpp.
265 lua_getglobal(ls,
"onTick");
266 if (lua_isnil(ls, -1)) {
272 int status = lua_pcall(ls, 0, 0, 0);
276 auto errMsg = lua_tostring(ls, -1);
277 efiPrintf(TAG
"error %s", errMsg);
Referenced by runOneLua().
◆ loadLibraries()
Definition at line 158 of file lua.cpp.
159 constexpr luaL_Reg libs[] = {
162 { LUA_MATHLIBNAME, luaopen_math },
165 for (
size_t i = 0; i <
efi::size(libs); i++) {
166 luaL_requiref(ls, libs[i].name, libs[i].func, 1);
Referenced by setupLuaState().
◆ loadScript()
static bool loadScript |
( |
LuaHandle & |
ls, |
|
|
const char * |
scriptStr |
|
) |
| |
|
static |
Definition at line 206 of file lua.cpp.
207 efiPrintf(TAG
"loading script length: %d...", efiStrlen(scriptStr));
209 if (0 != luaL_dostring(ls, scriptStr)) {
210 efiPrintf(TAG
"ERROR loading script: %s", lua_tostring(ls, -1));
215 efiPrintf(TAG
"script loaded successfully!");
static void printLuaMemoryInfo()
Referenced by runOneLua(), runScript(), and testLuaExecString().
◆ lua_setTickRate()
static int lua_setTickRate |
( |
lua_State * |
l | ) |
|
|
static |
Definition at line 147 of file lua.cpp.
148 float freq = luaL_checknumber(l, 1);
152 freq = clampF(1, freq, 200);
static int luaTickPeriodUs
Referenced by setupLuaState().
◆ myAlloc()
static void * myAlloc |
( |
void * |
, |
|
|
void * |
ptr, |
|
|
size_t |
osize, |
|
|
size_t |
nsize |
|
) |
| |
|
static |
Definition at line 122 of file lua.cpp.
127 return userHeap.realloc(ptr, osize, nsize);
TunerStudioOutputChannels outputChannels
static Heap userHeap(luaUserHeap)
engine_configuration_s * engineConfiguration
Referenced by runScript(), and testLuaExecString().
◆ printLuaMemoryInfo()
static void printLuaMemoryInfo |
( |
| ) |
|
|
static |
Definition at line 115 of file lua.cpp.
118 float pct = 100.0f * memoryUsed / heapSize;
119 efiPrintf(
"Lua memory heap usage: %d / %d bytes = %.1f%%", memoryUsed, heapSize, pct);
Referenced by loadScript(), and startLua().
◆ resetLua()
◆ runOneLua()
static bool runOneLua |
( |
lua_Alloc |
alloc, |
|
|
const char * |
script |
|
) |
| |
|
static |
Definition at line 310 of file lua.cpp.
327 while (!
needsReset && !chThdShouldTerminateX()) {
static bool loadScript(LuaHandle &ls, const char *scriptStr)
static void doInteractive(LuaHandle &ls)
static LuaHandle setupLuaState(lua_Alloc alloc)
static void invokeTick(LuaHandle &ls)
int doLuaCanRx(LuaHandle &ls)
bool getAuxDigital(int index)
uint32_t luaInvocationCounter
uint32_t luaLastCycleDuration
◆ runScript()
static LuaHandle runScript |
( |
const char * |
script | ) |
|
|
static |
Definition at line 442 of file lua.cpp.
446 throw std::logic_error(
"Call to setupLuaState failed, returned null");
450 throw std::logic_error(
"Call to loadScript failed");
453 lua_getglobal(ls,
"testFunc");
454 if (lua_isnil(ls, -1)) {
455 throw std::logic_error(
"Failed to find function testFunc");
458 int status = lua_pcall(ls, 0, 1, 0);
461 std::string msg = std::string(
"lua error while running script: ") + lua_tostring(ls, -1);
462 throw std::logic_error(msg);
static void * myAlloc(void *, void *ptr, size_t osize, size_t nsize)
Referenced by testLuaReturnsInteger(), testLuaReturnsNumber(), and testLuaReturnsNumberOrNil().
◆ setupLuaState()
static LuaHandle setupLuaState |
( |
lua_Alloc |
alloc | ) |
|
|
static |
Definition at line 171 of file lua.cpp.
172 LuaHandle ls = lua_newstate(alloc, NULL);
175 criticalError(
"Failed to start Lua interpreter");
180 lua_atpanic(ls, [](lua_State* l) {
181 criticalError(
"Lua panic: %s", lua_tostring(l, -1));
197 lua_gc(ls, LUA_GCCOLLECT, 0);
201 lua_gc(ls, LUA_GCINC, 50, 1000, 9);
static void loadLibraries(LuaHandle &ls)
static int lua_setTickRate(lua_State *l)
void configureRusefiLuaHooks(lua_State *lState)
Referenced by runOneLua(), runScript(), and testLuaExecString().
◆ startLua()
Definition at line 386 of file lua.cpp.
387 #if defined(STM32F4) && !defined(EFI_IS_F42x)
393 char *
buffer = (
char *)0x20020000;
398 #if LUA_USER_HEAP > 1
void addConsoleActionS(const char *token, VoidCharPtr callback)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
static LuaThread luaThread
script_setting_t scriptSetting[SCRIPT_SETTING_COUNT]
static BigBufferHandle buffer
Referenced by commonEarlyInit().
◆ strtof_rusefi()
float strtof_rusefi |
( |
const char * |
str, |
|
|
char ** |
endPtr |
|
) |
| |
Definition at line 526 of file lua.cpp.
527 bool afterDecimalPoint =
false;
531 *endPtr =
const_cast<char*
>(str);
534 float integerPart = 0;
535 float fractionalPart = 0;
537 while (*str !=
'\0') {
539 int digitVal = c -
'0';
541 if (c >=
'0' && c <=
'9') {
542 if (!afterDecimalPoint) {
544 integerPart = 10 * integerPart + digitVal;
547 fractionalPart = 10 * fractionalPart + digitVal;
550 }
else if (c ==
'.') {
551 afterDecimalPoint =
true;
559 *endPtr =
const_cast<char*
>(str);
563 return integerPart + fractionalPart / div;
◆ testLuaExecString()
void testLuaExecString |
( |
const char * |
script | ) |
|
Definition at line 508 of file lua.cpp.
512 throw std::logic_error(
"Call to setupLuaState failed, returned null");
516 throw std::logic_error(
"Call to loadScript failed");
◆ testLuaReturnsInteger()
int testLuaReturnsInteger |
( |
const char * |
script | ) |
|
Definition at line 497 of file lua.cpp.
501 if (!lua_isinteger(ls, -1)) {
502 throw std::logic_error(
"Returned value is not an integer");
505 return lua_tointeger(ls, -1);
static LuaHandle runScript(const char *script)
◆ testLuaReturnsNumber()
float testLuaReturnsNumber |
( |
const char * |
script | ) |
|
Definition at line 485 of file lua.cpp.
489 if (!lua_isnumber(ls, -1)) {
490 throw new std::logic_error(
"Returned value is not a number");
494 return lua_tonumber(ls, -1);
◆ testLuaReturnsNumberOrNil()
expected<float> testLuaReturnsNumberOrNil |
( |
const char * |
script | ) |
|
Definition at line 468 of file lua.cpp.
472 if (lua_isnil(ls, -1)) {
477 if (!lua_isnumber(ls, -1)) {
478 throw std::logic_error(
"Returned value is not a number");
482 return lua_tonumber(ls, -1);
◆ userHeap()
static Heap userHeap |
( |
luaUserHeap |
| ) |
|
|
static |
◆ interactiveCmd
◆ interactivePending
bool interactivePending = false |
|
static |
◆ LUA_HEAD_RAM_SECTION
char luaUserHeap [LUA_USER_HEAP] SDRAM_OPTIONAL LUA_HEAD_RAM_SECTION |
|
static |
◆ luaThread
◆ luaTickPeriodUs
◆ needsReset
◆ recentRxCount
◆ rxTime
◆ totalRxCount
Go to the source code of this file.