allocate lua properties in spi ram

custom
jacqueline 1 year ago
parent c0ec19c496
commit ea8a7b0f93
  1. 4
      src/lua/include/property.hpp
  2. 13
      src/lua/property.cpp
  3. 5
      src/memory/include/memory_resource.hpp

@ -35,7 +35,7 @@ class Property {
Property(const LuaValue&);
Property(const LuaValue&, std::function<bool(const LuaValue&)>);
auto Get() -> const LuaValue& { return value_; }
auto Get() -> const LuaValue& { return *value_; }
auto IsTwoWay() -> bool { return cb_.has_value(); }
@ -46,7 +46,7 @@ class Property {
auto AddLuaBinding(lua_State*, int ref) -> void;
private:
LuaValue value_;
std::unique_ptr<LuaValue> value_;
std::optional<std::function<bool(const LuaValue&)>> cb_;
std::pmr::vector<std::pair<lua_State*, int>> bindings_;
};

@ -9,6 +9,7 @@
#include <cmath>
#include <memory>
#include <memory_resource>
#include <string>
#include <variant>
@ -160,11 +161,15 @@ template <class... Ts>
inline constexpr bool always_false_v = false;
Property::Property(const LuaValue& val)
: value_(val), cb_(), bindings_(&memory::kSpiRamResource) {}
: value_(memory::SpiRamAllocator<LuaValue>().new_object<LuaValue>(val)),
cb_(),
bindings_(&memory::kSpiRamResource) {}
Property::Property(const LuaValue& val,
std::function<bool(const LuaValue& val)> cb)
: value_(val), cb_(cb), bindings_(&memory::kSpiRamResource) {}
: value_(memory::SpiRamAllocator<LuaValue>().new_object<LuaValue>(val)),
cb_(cb),
bindings_(&memory::kSpiRamResource) {}
static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void {
std::visit(
@ -273,7 +278,7 @@ auto Property::PushValue(lua_State& s) -> int {
static_assert(always_false_v<T>, "PushValue missing type");
}
},
value_);
*value_);
return 1;
}
@ -343,7 +348,7 @@ auto Property::PopValue(lua_State& s) -> bool {
}
auto Property::Update(const LuaValue& v) -> void {
value_ = v;
*value_ = v;
for (int i = bindings_.size() - 1; i >= 0; i--) {
auto& b = bindings_[i];

@ -40,4 +40,9 @@ class Resource : public std::pmr::memory_resource {
extern Resource kSpiRamResource;
template <typename T>
auto SpiRamAllocator() {
return std::pmr::polymorphic_allocator<T>{&kSpiRamResource};
}
} // namespace memory

Loading…
Cancel
Save