From 80e02de00b907b7928c28272a4dc06265f474b49 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 6 Nov 2022 20:08:25 -0500 Subject: [PATCH] https://rusefi.com/forum/viewtopic.php?p=46603#p46603 calling 'setTimeout' on bad self (cpp class not export) --- firmware/controllers/lua/lua_hooks.cpp | 5 +++++ firmware/controllers/sensors/stored_value_sensor.h | 2 +- unit_tests/tests/lua/test_lua_basic.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index ca9b0586ca..30600882d9 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -419,6 +419,11 @@ struct LuaSensor final : public StoredValueSensor { return m_isRedundant; } + // do we need method defined exactly on LuaSensor for Luaa to be happy? + void setTimeout(int timeoutMs) override { + StoredValueSensor::setTimeout(timeoutMs); + } + void setRedundant(bool value) { m_isRedundant = value; } diff --git a/firmware/controllers/sensors/stored_value_sensor.h b/firmware/controllers/sensors/stored_value_sensor.h index 6a1b68e5e5..c96dd80faf 100644 --- a/firmware/controllers/sensors/stored_value_sensor.h +++ b/firmware/controllers/sensors/stored_value_sensor.h @@ -77,7 +77,7 @@ public: void showInfo(const char*) const override { } - void setTimeout(int timeoutMs) { + virtual void setTimeout(int timeoutMs) { m_timeoutPeriod = MS2NT(timeoutMs); } diff --git a/unit_tests/tests/lua/test_lua_basic.cpp b/unit_tests/tests/lua/test_lua_basic.cpp index 59c2a91747..5ffb3ed7ef 100644 --- a/unit_tests/tests/lua/test_lua_basic.cpp +++ b/unit_tests/tests/lua/test_lua_basic.cpp @@ -109,6 +109,15 @@ TEST(LuaBasic, ExpectNumOrNilReturnsNothing) { )"), unexpected); } +TEST(LuaSensor, Timeout) { + EXPECT_FLOAT_EQ(0.0f, testLuaReturnsNumberOrNil(R"( + function testFunc() + cltSensor = Sensor.new("clt") + cltSensor:setTimeout(3000) + end + )").value_or(0)); +} + TEST(SystemLua, ScriptLoads) { startLua(); }