From e4a872c251799e324e777bf32cbc3c258a20eb70 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Nov 2021 23:27:48 -0400 Subject: [PATCH] refatoring: splitting lua hooks into multiple files --- firmware/controllers/lua/lua.mk | 1 + firmware/controllers/lua/lua_hooks.cpp | 12 +++-------- firmware/controllers/lua/lua_hooks_util.cpp | 23 +++++++++++++++++++++ firmware/controllers/lua/lua_hooks_util.h | 13 ++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 firmware/controllers/lua/lua_hooks_util.cpp create mode 100644 firmware/controllers/lua/lua_hooks_util.h diff --git a/firmware/controllers/lua/lua.mk b/firmware/controllers/lua/lua.mk index b530911ac0..448f6956a0 100644 --- a/firmware/controllers/lua/lua.mk +++ b/firmware/controllers/lua/lua.mk @@ -3,6 +3,7 @@ LUA_EXT=$(PROJECT_DIR)/ext/lua ALLCPPSRC += $(LUA_DIR)/lua.cpp \ $(LUA_DIR)/lua_hooks.cpp \ + $(LUA_DIR)/lua_hooks_util.cpp \ $(LUA_DIR)/system_lua.cpp \ $(LUA_DIR)/lua_can_rx.cpp \ diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 3f406e58d4..cf6f35694a 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -10,19 +10,12 @@ #include "settings.h" #include #include "luaaa.hpp" +#include "lua_hooks_util.h" using namespace luaaa; // Some functions lean on existing FSIO implementation #include "fsio_impl.h" -static int lua_efi_print(lua_State* l) { - auto msg = luaL_checkstring(l, 1); - - efiPrintf("LUA: %s", msg); - - return 0; -} - static int lua_readpin(lua_State* l) { auto msg = luaL_checkstring(l, 1); #if EFI_PROD_CODE @@ -388,7 +381,8 @@ void configureRusefiLuaHooks(lua_State* l) { .fun("set", &LuaSensor::set) .fun("invalidate", &LuaSensor::invalidate); - lua_register(l, "print", lua_efi_print); + configureRusefiLuaUtilHooks(l); + lua_register(l, "readPin", lua_readpin); lua_register(l, "getAuxAnalog", lua_getAuxAnalog); lua_register(l, "getSensorByIndex", lua_getSensorByIndex); diff --git a/firmware/controllers/lua/lua_hooks_util.cpp b/firmware/controllers/lua/lua_hooks_util.cpp new file mode 100644 index 0000000000..34d484ca50 --- /dev/null +++ b/firmware/controllers/lua/lua_hooks_util.cpp @@ -0,0 +1,23 @@ +/* + * lua_hooks_util.cpp + * + * Created on: Nov 2, 2021 + * Author: rusefi + */ + +#include "pch.h" +#include "lua_hooks_util.h" + +static int lua_efi_print(lua_State* l) { + auto msg = luaL_checkstring(l, 1); + + efiPrintf("LUA: %s", msg); + + return 0; +} + +void configureRusefiLuaUtilHooks(lua_State* l) { + lua_register(l, "print", lua_efi_print); +} + + diff --git a/firmware/controllers/lua/lua_hooks_util.h b/firmware/controllers/lua/lua_hooks_util.h new file mode 100644 index 0000000000..d83503c750 --- /dev/null +++ b/firmware/controllers/lua/lua_hooks_util.h @@ -0,0 +1,13 @@ +/* + * lua_hooks_util.h + * + * Created on: Nov 2, 2021 + * Author: rusefi + */ + +#pragma once + +#include "rusefi_lua.h" + +void configureRusefiLuaUtilHooks(lua_State* l); +