Pioneer
Loading...
Searching...
No Matches
LuaEvent.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _LUAEVENT_H
5#define _LUAEVENT_H
6
7#include "Lua.h"
8#include "LuaObject.h"
9#include "LuaPushPull.h"
10#include "LuaTable.h"
11
12namespace LuaEvent {
13
14 void Init();
15 void Uninit();
16
17 void Clear();
18 void Emit();
19
21
22 // Push an event to the specified event queue, passed as a LuaRef &
23 template <typename... TArgs>
24 inline void Queue(const LuaRef &queue, std::string_view event, TArgs... args)
25 {
26 ScopedTable ev(queue.GetLua());
27 ev.Set("name", event);
28 ev.PushMultiple(args...);
29
30 ScopedTable(queue).PushBack(ev);
31 }
32
33 // Push an event to the specified event queue, passed as a LuaRef &
34 inline void Queue(const LuaRef &queue, std::string_view event)
35 {
36 ScopedTable ev(queue.GetLua());
37 ev.Set("name", event);
38
39 ScopedTable(queue).PushBack(ev);
40 }
41
42 // Push an event to the specified event queue, passed as a LuaRef &
43 template <typename... TArgs>
44 inline void Queue(std::string_view event, TArgs... args)
45 {
46 Queue(GetEventQueue(), event, args...);
47 }
48
49 // Push an event to the specified event queue, passed as a LuaRef &
50 inline void Queue(std::string_view event)
51 {
52 Queue(GetEventQueue(), event);
53 }
54
55} // namespace LuaEvent
56
57#endif
Definition: LuaRef.h:12
lua_State * GetLua() const
Definition: LuaRef.h:26
LuaTable Set(const Key &key, const Value &value) const
Definition: LuaTable.h:365
LuaTable & PushMultiple(Values &... value)
Definition: LuaTable.h:383
LuaTable & PushBack(Value &value)
Definition: LuaTable.h:374
Definition: LuaTable.h:298
Definition: LuaEvent.cpp:11
void Queue(const LuaRef &queue, std::string_view event, TArgs... args)
Definition: LuaEvent.h:24
void Emit()
Definition: LuaEvent.cpp:65
void Init()
Definition: LuaEvent.cpp:36
void Uninit()
Definition: LuaEvent.cpp:50
LuaRef & GetEventQueue()
Definition: LuaEvent.cpp:75
void Clear()
Definition: LuaEvent.cpp:55