Libsaki
Core library of Pancake Mahjong
girl_x.h
1 #ifndef SAKI_APP_GIRL_X_H
2 #define SAKI_APP_GIRL_X_H
3 
4 #include "lua_class.h"
5 #include "../table/girl.h"
6 
7 #include <sstream>
8 
9 
10 namespace saki
11 {
12 
13 
14 
18 class GirlX : public Girl, public LuaUserErrorHandler
19 {
20 public:
21  GirlX(Who who, std::string luaCode);
22  GirlX(const GirlX &copy);
23  GirlX(GirlX &&move) = default;
24  GirlX &operator=(const GirlX &copy) = delete;
25  GirlX &operator=(GirlX &&move) = delete;
26  ~GirlX() override = default;
27 
28  std::unique_ptr<Girl> clone() const override;
29 
30  bool checkInit(Who who, const Hand &init, const Table &table, int iter) override;
31  void onDice(util::Rand &rand, const Table &table) override;
32  void onMonkey(std::array<Exist, 4> &exists, const Table &table) override;
33  void onDraw(const Table &table, Mount &mount, Who who, bool rinshan) override;
34 
35  std::string popUpStr() const override;
36 
37  void onTableEvent(const Table &table, const TableEvent &event) override;
38 
39 private:
40  void setupLuaGlobal();
41  void addError(const char *what);
42 
43  sol::object runInGirlEnv(const std::string_view &code) noexcept;
44 
45  void popUpIfAny(const Table &table);
46 
47  void handleUserError(const char *msg) override;
48 
49 private:
50  sol::state mLua;
51  sol::environment mGirlEnv;
52  std::ostringstream mErrStream;
53 };
54 
55 
56 
57 } // namespace saki
58 
59 
60 
61 #endif // SAKI_APP_GIRL_X_H
Definition: table_event.h:23
Definition: sol.hpp:1174
Definition: mount.h:54
Definition: table.h:87
Definition: lua_user_error_handler.h:11
Lua intepreter for custom characters.
Definition: girl_x.h:18
Definition: rand.h:19
void onDice(util::Rand &rand, const Table &table) override
Called when someone is about to dice.
Definition: girl_x.cpp:77
void onDraw(const Table &table, Mount &mount, Who who, bool rinshan) override
Called when someone is about to draw a tile from the mountain.
Definition: girl_x.cpp:123
Definition: ai.cpp:18
Definition: hand.h:17
Definition: sol.hpp:28236
Base class for skill implementation.
Definition: girl.h:35
Definition: who.h:14