From 1b2d791a05954fd161376e3ddce0d44f74fcc6c0 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 10 Jan 2024 16:58:29 +1100 Subject: [PATCH] Use doubles instead of floats for lua numbers (this unpins the ui task) --- lib/esp-idf-lua/lua/luaconf.h | 4 ++-- src/lua/include/property.hpp | 2 +- src/lua/property.cpp | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/esp-idf-lua/lua/luaconf.h b/lib/esp-idf-lua/lua/luaconf.h index 9228b6b5..7b44cd9f 100644 --- a/lib/esp-idf-lua/lua/luaconf.h +++ b/lib/esp-idf-lua/lua/luaconf.h @@ -118,14 +118,14 @@ /* Default configuration ('long long' and 'double', for 64-bit Lua) */ -#define LUA_INT_DEFAULT LUA_INT_LONGLONG +#define LUA_INT_DEFAULT LUA_INT_LONG #define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE /* @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. */ -#define LUA_32BITS 1 +#define LUA_32BITS 0 /* diff --git a/src/lua/include/property.hpp b/src/lua/include/property.hpp index c1dcf44b..a8a88125 100644 --- a/src/lua/include/property.hpp +++ b/src/lua/include/property.hpp @@ -17,7 +17,7 @@ namespace lua { using LuaValue = - std::variant; + std::variant; using LuaFunction = std::function; class Property { diff --git a/src/lua/property.cpp b/src/lua/property.cpp index 7a45552b..89351579 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -7,6 +7,7 @@ #include "property.hpp" #include +#include #include #include @@ -192,8 +193,6 @@ auto Property::PushValue(lua_State& s) -> int { lua_pushnil(&s); } else if constexpr (std::is_same_v) { lua_pushinteger(&s, arg); - } else if constexpr (std::is_same_v) { - lua_pushnumber(&s, arg); } else if constexpr (std::is_same_v) { lua_pushboolean(&s, arg); } else if constexpr (std::is_same_v) { @@ -241,7 +240,7 @@ auto Property::PopValue(lua_State& s) -> bool { if (lua_isinteger(&s, 2)) { new_val = lua_tointeger(&s, 2); } else { - new_val = lua_tonumber(&s, 2); + new_val = static_cast(std::round(lua_tonumber(&s, 2))); } break; case LUA_TBOOLEAN: