-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiBacklog_BindLua.cpp
More file actions
202 lines (192 loc) · 5.36 KB
/
Copy pathwiBacklog_BindLua.cpp
File metadata and controls
202 lines (192 loc) · 5.36 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "wiBacklog_BindLua.h"
#include "wiBacklog.h"
#include "wiLua.h"
#include "wiMath_BindLua.h"
#include "wiHelper.h"
#include <string>
#ifdef PLATFORM_WINDOWS_DESKTOP
#include <shellapi.h>
#endif
namespace wi::lua::backlog
{
int backlog_clear(lua_State* L)
{
wi::backlog::clear();
return 0;
}
int backlog_post(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
std::string ss;
for (int i = 1; i <= argc; i++)
{
if (wi::lua::SIsString(L, i))
{
ss += wi::lua::SGetString(L, i);
}
else if (wi::lua::SIsNumber(L, i))
{
double arg = wi::lua::SGetDouble(L, i);
ss += std::to_string(arg);
}
else if (wi::lua::SIsBool(L, i)) {
bool arg = wi::lua::SGetBool(L, i);
ss += arg ? "true" : "false";
}
else if (wi::lua::SIsNil(L, i)) {
ss += "nil";
}
else
{
Vector_BindLua* vec = Luna<Vector_BindLua>::lightcheck(L, i);
if (vec != nullptr)
{
ss += "Vector(" + std::to_string(vec->data.x) + ", " + std::to_string(vec->data.y) + ", " + std::to_string(vec->data.z) + ", " + std::to_string(vec->data.w) + ")";
}
else
{
Matrix_BindLua* mat = Luna<Matrix_BindLua>::lightcheck(L, i);
if (mat != nullptr)
{
ss += "Matrix(\n";
ss += "\t" + std::to_string(mat->data._11) + ", " + std::to_string(mat->data._12) + ", " + std::to_string(mat->data._13) + ", " + std::to_string(mat->data._14) + "\n";
ss += "\t" + std::to_string(mat->data._21) + ", " + std::to_string(mat->data._22) + ", " + std::to_string(mat->data._23) + ", " + std::to_string(mat->data._24) + "\n";
ss += "\t" + std::to_string(mat->data._31) + ", " + std::to_string(mat->data._32) + ", " + std::to_string(mat->data._33) + ", " + std::to_string(mat->data._34) + "\n";
ss += "\t" + std::to_string(mat->data._41) + ", " + std::to_string(mat->data._42) + ", " + std::to_string(mat->data._43) + ", " + std::to_string(mat->data._44) + "\n";
ss += ")";
}
}
}
}
if (!ss.empty())
{
wi::backlog::post(ss);
}
return 0;
}
int backlog_fontsize(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
wi::backlog::setFontSize(wi::lua::SGetInt(L, 1));
}
else
wi::lua::SError(L, "backlog_fontsize(int val) not enough arguments!");
return 0;
}
int backlog_isactive(lua_State* L)
{
wi::lua::SSetBool(L, wi::backlog::isActive());
return 1;
}
int backlog_fontrowspacing(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
wi::backlog::setFontRowspacing(wi::lua::SGetFloat(L, 1));
}
else
wi::lua::SError(L, "backlog_fontrowspacing(int val) not enough arguments!");
return 0;
}
int backlog_setlevel(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
wi::backlog::SetLogLevel((wi::backlog::LogLevel)wi::lua::SGetInt(L, 1));
}
else
wi::lua::SError(L, "backlog_setlevel(int val) not enough arguments!");
return 0;
}
int backlog_lock(lua_State* L)
{
wi::backlog::Lock();
return 0;
}
int backlog_unlock(lua_State* L)
{
wi::backlog::Unlock();
return 0;
}
int backlog_blocklua(lua_State* L)
{
wi::backlog::BlockLuaExecution();
return 0;
}
int backlog_unblocklua(lua_State* L)
{
wi::backlog::UnblockLuaExecution();
return 0;
}
int backlog_open(lua_State* L)
{
wi::backlog::Flush();
const std::string logfile = wi::backlog::GetLogFile();
#ifdef PLATFORM_WINDOWS_DESKTOP
HINSTANCE result = ShellExecuteA(NULL, "open", logfile.c_str(), NULL, NULL, SW_SHOWNORMAL);
if ((INT_PTR)result > 32)
{
wi::backlog::post("Opening log file: " + logfile);
}
else
{
wi::backlog::post("Failed to open log file: " + logfile, wi::backlog::LogLevel::Error);
}
#elif defined(PLATFORM_LINUX)
std::string op = "xdg-open \"" + logfile + "\"";
int status = system(op.c_str());
if (status == 0)
{
wi::backlog::post("Opening log file: " + logfile);
}
else
{
wi::backlog::post("Failed to open log file: " + logfile, wi::backlog::LogLevel::Error);
}
#else
wi::backlog::post("backlog_open(): not implemented for this operating system!", wi::backlog::LogLevel::Warning);
#endif
return 0;
}
int backlog_flush(lua_State* L)
{
wi::backlog::Flush();
return 0;
}
int backlog_setautoflushinterval(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
if (argc > 0)
{
wi::backlog::SetAutoFlushInterval((uint32_t)wi::lua::SGetInt(L, 1));
}
else
wi::lua::SError(L, "backlog_setautoflushinterval(int milliseconds) not enough arguments!");
return 0;
}
void Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
wi::lua::RegisterFunc("backlog_clear", backlog_clear);
wi::lua::RegisterFunc("backlog_post", backlog_post);
wi::lua::RegisterFunc("backlog_fontsize", backlog_fontsize);
wi::lua::RegisterFunc("backlog_isactive", backlog_isactive);
wi::lua::RegisterFunc("backlog_fontrowspacing", backlog_fontrowspacing);
wi::lua::RegisterFunc("backlog_setlevel", backlog_setlevel);
wi::lua::RegisterFunc("backlog_lock", backlog_lock);
wi::lua::RegisterFunc("backlog_unlock", backlog_unlock);
wi::lua::RegisterFunc("backlog_blocklua", backlog_blocklua);
wi::lua::RegisterFunc("backlog_unblocklua", backlog_unblocklua);
wi::lua::RegisterFunc("backlog_open", backlog_open);
wi::lua::RegisterFunc("backlog_flush", backlog_flush);
wi::lua::RegisterFunc("backlog_setautoflushinterval", backlog_setautoflushinterval);
}
}
}