rusefi-1/firmware/controllers/lua/lua_hooks.cpp

35 lines
654 B
C++
Raw Normal View History

#include "lua.hpp"
#include "lua_hooks.h"
#include "loggingcentral.h"
#include "sensor.h"
static int lua_efi_print(lua_State* l) {
auto msg = luaL_checkstring(l, 1);
efiPrintf("LUA: %s", msg);
return 0;
}
static int lua_get_sensor(lua_State* l) {
auto sensorIndex = luaL_checkinteger(l, 1);
auto result = Sensor::get(static_cast<SensorType>(sensorIndex));
if (result) {
// return value if valid
lua_pushnumber(l, result.Value);
} else {
// return nil if invalid
lua_pushnil(l);
}
return 1;
}
void configureRusefiLuaHooks(lua_State* l) {
lua_register(l, "print", lua_efi_print);
lua_register(l, "getSensor", lua_get_sensor);
}