7 #include <lua5.1/lauxlib.h> |
7 #include <lua5.1/lauxlib.h> |
8 |
8 |
9 static void lua_console_on_line (const char *line, void *arg) |
9 static void lua_console_on_line (const char *line, void *arg) |
10 { |
10 { |
11 struct lua_console *lc = arg; |
11 struct lua_console *lc = arg; |
12 lua_State *L = lc->lua->st; |
12 struct error_info err; |
13 int ret; |
|
14 |
13 |
15 // ignore empty lines and EOF |
14 // ignore empty lines and EOF |
16 if (!line || !(*line)) |
15 if (!line || !(*line)) |
17 return; |
16 return; |
18 |
17 |
19 // XXX: move to nexus_lua |
18 // eval it |
20 |
19 if (nexus_lua_eval(lc->lua, line, &err)) |
21 // load the line as a lua function |
|
22 if ((ret = luaL_loadstring(L, line))) |
|
23 goto error; |
|
24 |
|
25 // execute it |
|
26 if ((ret = lua_pcall(L, 0, 0, 0))) |
|
27 goto error; |
|
28 |
|
29 // XXX: display results? |
|
30 |
|
31 error: |
|
32 if (ret) { |
|
33 struct error_info err; |
|
34 |
|
35 // build the error_info |
|
36 nexus_lua_error(L, ret, &err); |
|
37 |
|
38 // log it |
|
39 log_error("%s", error_msg(&err)); |
20 log_error("%s", error_msg(&err)); |
40 |
21 |
41 // pop it |
22 // XXX: display return value? |
42 lua_pop(L, -1); |
23 |
43 } |
|
44 } |
24 } |
45 |
25 |
46 static struct console_callbacks _console_callbacks = { |
26 static struct console_callbacks _console_callbacks = { |
47 .on_line = &lua_console_on_line, |
27 .on_line = &lua_console_on_line, |
48 }; |
28 }; |