-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLUCEApplication.h
153 lines (152 loc) · 3.41 KB
/
LUCEApplication.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#pragma once
#include "../../Defs.h"
/**
* @brief Load LUCE application.
*
* @param n Application name.
* @param v Application version.
* @param ami Allow multi instance.
* @param f Application main file.
* @param m Application module load code.
*/
#define LUCE_APPLICATION(n, v, ami, f, m) \
class LUCEApplication : public juce::JUCEApplication { \
std::unique_ptr<lua_State, std::function<void(lua_State*)>> _L = nullptr; \
\
public: \
const juce::String getApplicationName() override { return n; }; \
const juce::String getApplicationVersion() override { return v; }; \
bool moreThanOneInstanceAllowed() override { return ami; }; \
\
void initialise(const juce::String& commandLineParameters) override { \
this->_L = std::unique_ptr<lua_State, std::function<void(lua_State*)>>( \
luaL_newstate(), [](lua_State* L) {lua_close(L); }); \
auto L = this->_L.get(); \
\
luaL_openlibs(L); \
luce::createLUCETable(L); \
\
{ \
m \
} \
\
if (luaL_dofile(L, f)) { \
fprintf(stderr, luaL_checkstring(L, -1)); \
quit(); \
return; \
} \
\
{ \
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "initialise"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_pushstring(L, commandLineParameters.toStdString().c_str()); \
lua_call(L, 1, 0); \
\
lua_pop(L, 1); \
} \
}; \
void shutdown() override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "shutdown"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_call(L, 0, 0); \
\
lua_pop(L, 1); \
}; \
void anotherInstanceStarted(const juce::String& commandLine) override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "anotherInstanceStarted"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_pushstring(L, commandLine.toStdString().c_str()); \
lua_call(L, 1, 0); \
\
lua_pop(L, 1); \
}; \
void suspended() override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "suspended"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_call(L, 0, 0); \
\
lua_pop(L, 1); \
}; \
void resumed() override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "resumed"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_call(L, 0, 0); \
\
lua_pop(L, 1); \
}; \
void memoryWarningReceived() override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "memoryWarningReceived"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return; \
} \
\
lua_call(L, 0, 0); \
\
lua_pop(L, 1); \
}; \
bool backButtonPressed() override { \
auto L = this->_L.get(); \
\
lua_getglobal(L, "luce"); \
\
lua_getfield(L, -1, "backButtonPressed"); \
if (!lua_isfunction(L, -1)) { \
lua_pop(L, 2); \
return this->juce::JUCEApplication::backButtonPressed(); \
} \
\
lua_pushvalue(L, -2); \
lua_call(L, 1, 1); \
\
auto result = lua_toboolean(L, -1); \
\
lua_pop(L, 2); \
\
return result; \
}; \
}; \
\
START_JUCE_APPLICATION(LUCEApplication)