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

#pragma once

#include "lua.hpp"

#include "lua/property.hpp"
#include "ui/screen.hpp"

namespace ui {
namespace screens {

class Lua : public Screen {
 public:
  Lua();
  ~Lua();

  auto onShown() -> void override;
  auto onHidden() -> void override;

  auto canPop() -> bool override;

  auto SetObjRef(lua_State*) -> void;

 private:
  /* Invokes a method on this screen's Lua counterpart. */
  auto callMethod(std::string name) -> void;
  /* Applies fn to each binding in this screen's `bindings` field. */
  auto forEachBinding(std::function<void(lua::Binding*)> fn) -> void;

  lua_State* s_;
  std::optional<int> obj_ref_;
};

}  // namespace screens
}  // namespace ui