-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathluachild_common.c
56 lines (37 loc) · 1017 Bytes
/
luachild_common.c
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
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "luachild.h"
int set_table_field(lua_State *L, const char * field_name){
lua_pushstring(L, field_name);
lua_insert(L, -2);
lua_settable(L, -3);
return 0;
}
SHFUNC int luaopen_luachild(lua_State *L)
{
/* Process methods */
luaL_newmetatable(L, PROCESS_HANDLE);
lua_pushcfunction(L, process_tostring);
set_table_field(L, "__tostring");
lua_pushcfunction(L, process_wait);
set_table_field(L, "wait");
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
/* Top module functions */
lua_newtable(L);
lua_pushcfunction(L, lc_pipe);
set_table_field(L, "pipe");
lua_pushcfunction(L, lc_setenv);
set_table_field(L, "setenv");
lua_pushcfunction(L, lc_environ);
set_table_field(L, "environ");
lua_pushcfunction(L, lc_spawn);
set_table_field(L, "spawn");
lua_pushcfunction(L, process_wait);
set_table_field(L, "wait");
return 1;
}