diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 4a2539043b..c2ca1c4419 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -632,6 +632,18 @@ int lua_canRxAddMask(lua_State* l) { } #endif // EFI_CAN_SUPPORT +static int lua_vincpy(lua_State* l) { + luaL_checktype(l, 1, LUA_TTABLE); + size_t sourceIndex = luaL_checknumber(l, 2); + size_t destinationIndex = luaL_checknumber(l, 3); + size_t size = luaL_checknumber(l, 4); + for (int i = 0;ivinNumber[sourceIndex + i]); + lua_rawseti(l, 1, destinationIndex + i); + } + return 0; +} + void configureRusefiLuaHooks(lua_State* lState) { LuaClass luaTimer(lState, "Timer"); luaTimer @@ -658,6 +670,7 @@ void configureRusefiLuaHooks(lua_State* lState) { lua_register(lState, "readPin", lua_readpin); lua_register(lState, "vin", lua_vin); + lua_register(lState, "vincpy", lua_vincpy); lua_register(lState, "getAuxAnalog", lua_getAuxAnalog); lua_register(lState, "getSensorByIndex", lua_getSensorByIndex); lua_register(lState, "getSensor", lua_getSensorByName); diff --git a/unit_tests/tests/lua/test_lua_vin.cpp b/unit_tests/tests/lua/test_lua_vin.cpp index 79527e883e..430e81a767 100644 --- a/unit_tests/tests/lua/test_lua_vin.cpp +++ b/unit_tests/tests/lua/test_lua_vin.cpp @@ -13,7 +13,7 @@ TEST(LuaVin, Test) { strcpy(engineConfiguration->vinNumber, "GM123"); - const char* realdata = TWO_BYTES_MSB R"( + const char* realdata = R"( function testFunc() return vin(0) @@ -21,3 +21,21 @@ TEST(LuaVin, Test) { EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x47); } + +TEST(LuaVinCpy, Test) { + EngineTestHelper eth(engine_type_e::TEST_CRANK_ENGINE); + + strcpy(engineConfiguration->vinNumber, "GM123"); + + const char* realdata = ARRAY_EQUALS PRINT_ARRAY R"( + + function testFunc() + data = {0, 0, 0, 0, 0} + vincpy(data, 2, 1, 3); + print(arrayToString(data)) + expected = { 0x31, 0x32, 0x33, 0x00, 0x00 } + return equals(data, expected) + end)"; + + EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0); +}