-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua.cpp
More file actions
146 lines (128 loc) · 3.53 KB
/
lua.cpp
File metadata and controls
146 lines (128 loc) · 3.53 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
#include <lua.hpp>
#include <nlohmann/json.hpp>
#include "textmodule.hpp"
#include "textmodule_lua.hpp"
#include "textmodule_string.hpp"
#include "textmodule_option.hpp"
#include "base.hpp"
#include "string.hpp"
#include "debug.hpp"
#include "os.hpp"
#include "tmstring.hpp"
#include "clipboard.hpp"
#include "filesystem.hpp"
#include "hash.hpp"
#include "http.hpp"
#include "cmath.hpp"
#include "random.hpp"
#include "bit.hpp"
#include "qrcode.hpp"
#include "obj.hpp"
#include "ease.hpp"
#include "device.hpp"
#include "time.hpp"
#include "json.hpp"
#include "exedit.hpp"
#include "complex.hpp"
#include "quaternion.hpp"
#include "vector2.hpp"
#include "vector3.hpp"
#include "vector4.hpp"
#include "matrix2.hpp"
#include "matrix3.hpp"
#include "matrix4.hpp"
#include "colorlist.hpp"
#include "color.hpp"
#include "pixel.hpp"
#include "image.hpp"
void luaReg(lua_State* L, nlohmann::json opt, const char* module) {
//create base table
static luaL_Reg none[] = {
{nullptr, nullptr}
};
luaL_register(L, module, none);
auto api = opt["api"];
//module
luaReg_base(L, opt); //base
luaReg_debug(L, opt); //debug
luaReg_string(L, opt); //string
luaReg_os(L, opt); //os
luaReg_clipboard(L, opt); //clipboard
luaReg_filesystem(L, opt); //filesystem
luaReg_hash(L, opt); //hash
luaReg_http(L, opt); //http
luaReg_cmath(L, opt); //math
luaReg_random(L, opt); //random
luaReg_bit(L, opt); //bit
luaReg_qrcode(L, opt); //qrcode
luaReg_obj(L, opt); //obj
luaReg_ease(L, opt); //ease
luaReg_device(L, opt); //device
luaReg_time(L, opt); //time
luaReg_json(L, opt); //json
//luaReg_exedit(L, opt); //exedit
//color
luaReg_color(L, opt); //color
luaReg_pixel(L, opt); //pixel
luaReg_colorlist(L, opt); //colorlist
//luaReg_image(L, opt); //image
//geometry
luaReg_complex(L, opt); //complex
luaReg_quaternion(L, opt); //quaternion
luaReg_vector2(L, opt); //vector2
luaReg_vector3(L, opt); //vector3
luaReg_vector4(L, opt); //vector4
luaReg_matrix2(L, opt); //matrix2
luaReg_matrix3(L, opt); //matrix3
luaReg_matrix4(L, opt); //matrix4
}
int luaSetup(lua_State* L) {
nlohmann::json option = getOption();
tm_debuglog(option, "INFO", "adding a directory to the search path used to locate DLLs");
SetDllPath();
// Luaインスタンスに変数を登録
if (option[OPTION_VMODULE]) {
tm_debuglog(option, "INFO", "start module registration: " MODULE_NAME);
luaReg(L, option, MODULE_NAME); //main module
if (option[OPTION_VMODULE_ALIAS]) { // tm alias
tm_debuglog(option, "INFO", "start module registration: " ALIAS_MODULE_NAME);
luaReg(L, option, ALIAS_MODULE_NAME);
}
}
// バージョンチェック
int n = 0;
if (option[OPTION_VVER_CHECK]) {
tm_debuglog(option, "INFO", "check the module version");
int v = versionCheck();
if (v == VERSION_CHECK_ERROR) {
tm_debuglog(option, "VERSION_CHECK", "version check: error");
luaL_error(L, VERSION_CHECK_MSG_ERROR);
n = 1;
}
else if (v == VERSION_CHECK_OUTDATED) {
tm_debuglog(option, "VERSION_CHECK", "version check: outdated");
luaL_error(L, VERSION_CHECK_MSG_OUTDATED);
n = 1;
}
else
tm_debuglog(option, "VERSION_CHECK", "version check: latest");
}
return n;
}
extern "C" {
__declspec(dllexport) int luaopen_textmodule(lua_State* L) {
try {
int n = luaSetup(L);
return 1 + n;
}
catch (nlohmann::json::exception& j) {
std::string what = std::string("invalid json format or value: config.json\n") + std::string(j.what());
luaL_error(L, what.c_str());
return 0;
}
catch (std::exception& e) {
luaL_error(L, e.what());
return 0;
}
}
}