summaryrefslogtreecommitdiff
path: root/src/ui/screen_lua.cpp
blob: b3554241ddf1f798db7cdd308668a218efe6c7c3 (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
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#include "screen_lua.hpp"

#include "core/lv_obj_tree.h"
#include "lua.hpp"
#include "themes.hpp"

#include "luavgl.h"

namespace ui {
namespace screens {

Lua::Lua() : s_(nullptr), obj_ref_() {
  themes::Theme::instance()->ApplyStyle(root_, "root");
}

Lua::~Lua() {
  if (s_ && obj_ref_) {
    luaL_unref(s_, LUA_REGISTRYINDEX, *obj_ref_);
  }
}

auto Lua::SetObjRef(lua_State* s) -> void {
  assert(s_ == nullptr);
  s_ = s;
  obj_ref_ = luaL_ref(s, LUA_REGISTRYINDEX);
}

}  // namespace screens
}  // namespace ui