This repository was archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLuaAPI.cpp
56 lines (52 loc) · 1.54 KB
/
LuaAPI.cpp
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
#include "stdafx.h"
#include <string>
namespace LuaAPI {
static int luaB_print(lua_State* L) {
int n = lua_gettop(L); /* number of arguments */
int i;
static std::string out{};
out = "";
for (i = 1; i <= n; i++) { /* for each argument */
size_t l;
const char* s = luaL_tolstring(L, i, &l); /* convert it to string */
if (i > 1) out.append("\t");
out.append(s, l);
lua_pop(L, 1); /* pop result */
}
out.append("\n");
static std::wstring wide{};
auto len = MultiByteToWideChar(CP_UTF8, 0, out.c_str(), -1, nullptr, 0);
wide.resize(len);
MultiByteToWideChar(CP_UTF8, 0, out.c_str(), -1, (wchar_t*)wide.data(), len);
wprintf(L"%s", wide.c_str());
OutputDebugStringW(wide.c_str());
return 0;
}
static int _sleep(lua_State* L) {
Sleep((int)lua_tointeger(L, 1));
lua_pop(L, 1);
return 0;
}
void init(lua_State* q);
}
#define lua_namespaces \
X(init_vk_lualib)\
X(init_mouse_lualib)\
X(init_send_lualib)\
X(init_keyboard_lualib)\
X(init_hotkey_lualib)\
X(init_micmute_lualib)\
X(init_clipboard_lualib)\
X(init_console_lualib)\
X(init_trayicon_lualib)
#define X(name) void name(lua_State* q);
lua_namespaces
#undef X
void LuaAPI::init(lua_State* q) {
luaM_setglobal_cfunc(q, "print", luaB_print);
luaM_setglobal_cfunc(q, "sleep", _sleep);
#define X(name) name(q);
lua_namespaces
#undef X
}
#undef lua_namespaces