aboutsummaryrefslogtreecommitdiff
path: root/src/events/Event.hpp
blob: 11f1141dc156695bf430e92ed7f7762756e440b3 (plain) (blame)
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
#pragma once

#include <QtCore>
#include <lua.hpp>

#define SET_FIELD(NAME, TYPE, VALUE)                                                               \
  lua_pushstring(state, NAME);                                                                     \
  lua_push##TYPE(state, VALUE);                                                                    \
  lua_settable(state, -3);

// Not a huge fan but looks nice
#define SET_FIELD_CLOSURE_WITH_SELF(NAME, CLOSURE)                                                 \
  lua_pushstring(state, NAME);                                                                     \
  lua_pushlightuserdata(state, (void *)this);                                                      \
  lua_pushcclosure(state, CLOSURE, 1);                                                             \
  lua_settable(state, -3);

#define GET_CLOSURE_SELF(TYPE) static_cast<TYPE>(lua_touserdata(state, lua_upvalueindex(1)));

class Event {
public:
  QString kind = "-";

  virtual void lua_push(lua_State *state) const {
    lua_newtable(state);
    SET_FIELD("type", string, kind.toStdString().c_str())
  };
};