terom@93: #include "lua_console.h" terom@93: #include "lua_objs.h" terom@93: #include "log.h" terom@93: terom@93: #include terom@93: terom@93: #include terom@93: terom@93: static void lua_console_on_line (const char *line, void *arg) terom@93: { terom@93: struct lua_console *lc = arg; terom@136: struct error_info err; terom@93: terom@93: // ignore empty lines and EOF terom@93: if (!line || !(*line)) terom@93: return; terom@93: terom@136: // eval it terom@136: if (nexus_lua_eval(lc->lua, line, &err)) terom@137: console_print(lc->console, error_msg(&err)); terom@93: terom@136: // XXX: display return value? terom@136: terom@93: } terom@93: terom@170: static void lua_console_on_eof (void *arg) terom@170: { terom@170: struct lua_console *lc = arg; terom@170: terom@170: // exit the process terom@170: nexus_shutdown(lc->lua->nexus); terom@170: } terom@170: terom@93: static struct console_callbacks _console_callbacks = { terom@170: .on_line = lua_console_on_line, terom@170: .on_eof = lua_console_on_eof, terom@93: }; terom@93: terom@105: err_t lua_console_create (struct lua_console **lc_ptr, struct console *console, struct nexus_lua *lua, struct error_info *err) terom@93: { terom@93: struct lua_console *lc; terom@93: terom@93: // allocate terom@93: if ((lc = calloc(1, sizeof(*lc))) == NULL) terom@93: return SET_ERROR(err, ERR_CALLOC); terom@93: terom@93: // store terom@93: lc->console = console; terom@105: lc->lua = lua; terom@93: terom@93: // set our console callbacks terom@93: console_set_callbacks(console, &_console_callbacks, lc); terom@93: terom@93: // ok terom@93: *lc_ptr = lc; terom@93: terom@93: return SUCCESS; terom@93: } terom@93: terom@93: void lua_console_destroy (struct lua_console *lc) terom@93: { terom@105: // the console terom@93: console_destroy(lc->console); terom@93: terom@93: free(lc); terom@93: }