|
27 | 27 | #include "types.h"
|
28 | 28 |
|
29 | 29 | #define STREQUAL(a, b) (!strcmp(a, b))
|
| 30 | +#define LUA_ENTRY_INT(name) \ |
| 31 | + if (STREQUAL(entry, #name)) { \ |
| 32 | + lua_pushinteger(L, (lua_Integer)udata->name); \ |
| 33 | + return 1; \ |
| 34 | + } |
| 35 | +#define LUA_ENTRY_STR(name) \ |
| 36 | + if (STREQUAL(entry, #name)) { \ |
| 37 | + lua_pushstring(L, udata->name); \ |
| 38 | + return 1; \ |
| 39 | + } |
30 | 40 | #define LM_PROCESS_META "lm_process_t"
|
31 | 41 |
|
32 | 42 | int lua_lm_process_index(lua_State *L)
|
33 | 43 | {
|
34 | 44 | lm_process_t *udata = (lm_process_t *)luaL_checkudata(L, 1, LM_PROCESS_META);
|
35 | 45 | const char *entry = luaL_checkstring(L, 2);
|
36 | 46 |
|
37 |
| - if (STREQUAL(entry, "pid")) { |
38 |
| - lua_pushinteger(L, (lua_Integer)udata->pid); |
39 |
| - } else if (STREQUAL(entry, "ppid")) { |
40 |
| - lua_pushinteger(L, (lua_Integer)udata->ppid); |
41 |
| - } else if (STREQUAL(entry, "bits")) { |
42 |
| - lua_pushinteger(L, (lua_Integer)udata->bits); |
43 |
| - } else if (STREQUAL(entry, "start_time")) { |
44 |
| - lua_pushinteger(L, (lua_Integer)udata->start_time); |
45 |
| - } else if (STREQUAL(entry, "path")) { |
46 |
| - lua_pushstring(L, udata->path); |
47 |
| - } else if (STREQUAL(entry, "name")) { |
48 |
| - lua_pushstring(L, udata->name); |
49 |
| - } else { |
50 |
| - lua_pushnil(L); |
51 |
| - } |
| 47 | + LUA_ENTRY_INT(pid) |
| 48 | + LUA_ENTRY_INT(ppid) |
| 49 | + LUA_ENTRY_INT(bits) |
| 50 | + LUA_ENTRY_INT(start_time) |
| 51 | + LUA_ENTRY_STR(path) |
| 52 | + LUA_ENTRY_STR(name) |
52 | 53 |
|
| 54 | + lua_pushnil(L); |
53 | 55 | return 1;
|
54 | 56 | }
|
55 | 57 |
|
|
0 commit comments