blob: b6b4718f70dda0eed0d6a909ef1c5f670ccba164 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include <memory>
#include <string>
#include "lua.hpp"
#include "lvgl.h"
#include "service_locator.hpp"
namespace lua {
using LuaValue = std::variant<std::monostate, int, float, bool, std::string>;
class Property {
public:
Property() : Property(std::monostate{}) {}
Property(const LuaValue&);
Property(const LuaValue&, std::function<bool(const LuaValue&)>);
auto IsTwoWay() -> bool { return cb_.has_value(); }
auto PushValue(lua_State& s) -> int;
auto PopValue(lua_State& s) -> bool;
auto Update(const LuaValue& new_val) -> void;
auto AddLuaBinding(lua_State*, int ref) -> void;
private:
LuaValue value_;
std::optional<std::function<bool(const LuaValue&)>> cb_;
std::vector<std::pair<lua_State*, int>> bindings_;
};
class PropertyBindings {
public:
PropertyBindings(lua_State&);
auto Register(lua_State*, Property*) -> void;
};
} // namespace lua
|