-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluapp.cpp
74 lines (56 loc) · 1.35 KB
/
luapp.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "uv.h"
#include "luvit/luvit_init.h"
}
int main(int argc, char *argv[])
{
lua_State *L;
uv_loop_t *loop;
argv = uv_setup_args(argc, argv);
L = luaL_newstate();
if (L == NULL)
{
fprintf(stderr, "luaL_newstate has failed\n");
return 1;
}
luaL_openlibs(L);
loop = uv_default_loop();
#ifdef USE_OPENSSL
luvit_init_ssl();
#endif
/* Get argv */
lua_createtable (L, argc, 0);
for (int index = 0; index < argc; index++) {
lua_pushstring (L, argv[index]);
lua_rawseti(L, -2, index);
}
lua_setglobal(L, "argv");
if (luvit_init(L, loop))
{
fprintf(stderr, "luvit_init has failed\n");
return 1;
}
lua_pushboolean(L, true);
lua_setglobal(L, "LUAPP");
lua_pushboolean(L, false);
lua_setglobal(L, "SERVER");
lua_pushboolean(L, false);
lua_setglobal(L, "CLIENT");
luaL_dostring(L, "package.path = package.path .. \";resources/lua/?.lua;resources/lua/?/init.lua\"");
if(luaL_dostring(L, "require \"luapp\""))
{
printf("%s\n", lua_tostring(L, -1));
lua_pop(L, 1);
lua_close(L);
return -1;
}
lua_close(L);
uv_loop_close(loop);
L = NULL;
loop = NULL;
return 0;
}