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
|
#include "lua.h"
#include "table.h"
#include "crypto.h"
#include "io.h"
#include "math.h"
#include "net.h"
#include "thread.h"
#include "test.h"
#include "config.h"
#include <signal.h>
#include <stdlib.h>
void sigHandle(int s){
//signal(s, SIG_IGN);
//signal(s, sigHandle);
exit(s);
}
static int lua_exit(lua_State* L){
lib_thread_clean();
//sigHandle(0);
return 0;
}
#define open_common(name)\
int luaopen_lullaby_##name (lua_State* L){\
luaL_register(L, #name, name##_function_list);\
int tidx = lua_gettop(L);\
i_config_metatable(L, name##_config);\
lua_settop(L, tidx);\
return 1;\
}
open_common(array);
open_common(crypto);
open_common(io);
open_common(math);
open_common(net);
open_common(thread);
open_common(test);
#define push(T, name)\
lua_pushstring(L, #name);\
luaopen_lullaby_##name(L);\
lua_settable(L, T);
int luaopen_lullaby(lua_State* L) {
/*lua_newuserdata(L, 1);
int ud = lua_gettop(L);
lua_newtable(L);
int meta = lua_gettop(L);
luaI_tsetcf(L, meta, "__gc", lua_exit);
lua_pushvalue(L, meta);
lua_setmetatable(L, ud);*/
//create <lib>.array functions
lua_newtable(L);
int top = lua_gettop(L);
//lua_newtable(L);
push(top, array);
push(top, crypto);
push(top, io);
push(top, math);
push(top, net);
push(top, thread);
push(top, test);
luaI_tsets(L, top, "version", GIT_COMMIT)
//lreg("array", array_function_list);
//lreg("crypto", crypto_function_list);
//lreg("io", io_function_list);
//lreg("math", math_function_list);
//lreg("config", config_function_list);
//lreg("net", net_function_list);
//lreg("thread", thread_function_list);
lua_settop(L, top);
return 1;
}
|