diff --git a/src/bin/elua/lualian.lua b/src/bin/elua/lualian.lua index afdb235907..68148b132d 100644 --- a/src/bin/elua/lualian.lua +++ b/src/bin/elua/lualian.lua @@ -27,7 +27,9 @@ getopt.parse { end }, { "v", "verbose", false, help = "Be verbose.", - callback = function() printv = print end + callback = function() + printv = print + end }, { category = "Generator" }, @@ -38,14 +40,20 @@ getopt.parse { end }, { "L", "library", true, help = "Specify a C library name.", - callback = function(d, p, v) libname = v end + callback = function(d, p, v) + libname = v + end }, { "M", "module", true, help = "Specify a module name.", - callback = function(d, p, v) modname = v end + callback = function(d, p, v) + modname = v + end }, { "P", "prefix", true, help = "Specify a class name prefix " .. "to strip out for public interfaces.", - callback = function(d, p, v) cprefix = v end + callback = function(d, p, v) + cprefix = v + end }, { "o", "output", true, help = "Specify output file name(s), by " .. "default goes to stdout.", @@ -69,7 +77,7 @@ getopt.parse { end } -if quit then return end +if quit then return true end for i, v in ipairs(include_dirs) do lualian.include_dir(v) @@ -88,4 +96,6 @@ for i, fname in ipairs(args) do printv(" Output file: printing to stdout...") end lualian.generate(fname, modname, libname, cprefix, fstream) -end \ No newline at end of file +end + +return true \ No newline at end of file diff --git a/src/bin/elua/main.c b/src/bin/elua/main.c index 534e1b8356..5dcd01a770 100644 --- a/src/bin/elua/main.c +++ b/src/bin/elua/main.c @@ -49,12 +49,12 @@ static int traceback(lua_State *L) { return 1; } -static int docall(lua_State *L, int narg) { +static int docall(lua_State *L, int narg, int nret) { int status; int bs = lua_gettop(L) - narg; lua_pushcfunction(L, traceback); lua_insert(L, bs); - status = lua_pcall(L, narg, 0, bs); + status = lua_pcall(L, narg, nret, bs); lua_remove(L, bs); if (status) lua_gc(L, LUA_GCCOLLECT, 0); return status; @@ -122,15 +122,15 @@ static int dolib(lua_State *L, const char *libname) { } static int dofile(lua_State *L, const char *fname) { - return report(L, elua_loadfile(L, fname) || docall(L, 0)); + return report(L, elua_loadfile(L, fname) || docall(L, 0, 1)); } static int dostr(lua_State *L, const char *chunk, const char *chname) { return report(L, luaL_loadbuffer(L, chunk, strlen(chunk), chname) - || docall(L, 0)); + || docall(L, 0, 0)); } -static int doscript(lua_State *L, int argc, char **argv, int n) { +static int doscript(lua_State *L, int argc, char **argv, int n, int *quit) { int status; const char *fname = argv[n]; int narg = getargs(L, argc, argv, n); @@ -141,10 +141,14 @@ static int doscript(lua_State *L, int argc, char **argv, int n) { status = elua_loadfile(L, fname); lua_insert(L, -(narg + 1)); if (!status) { - status = docall(L, narg); + status = docall(L, narg, 1); } else { lua_pop(L, narg); } + if (!status) { + *quit = lua_toboolean(L, -1); + lua_pop(L, 1); + } return report(L, status); } @@ -368,9 +372,15 @@ static int lua_main(lua_State *L) { /* run script or execute sdin as file */ if (optind < argc) { - if ((m->status = doscript(L, argc, argv, optind))) return 0; + int quit = 0; + if ((m->status = doscript(L, argc, argv, optind, &quit))) return 0; + if (quit) return 0; } else if (!hasexec) { - dofile(L, NULL); + int quit; + if ((m->status = dofile(L, NULL))) return 0; + quit = lua_toboolean(L, -1); + lua_pop(L, 1); + if (quit) return 0; } ecore_main_loop_begin();