int sexe_execv(char *path, char **argv) { lua_State *L = luaL_newstate(); int status; int argc; int narg; int err; argc = 0; while (argv[argc]) argc++; /* open standard libraries */ luaL_checkversion(L); lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ lua_gc(L, LUA_GCRESTART, 0); //if (!args[has_E] && handle_luainit(L) != LUA_OK) err = _api_handle_luainit(L); if (err) { lua_close(L); return (err); } install_sexe_userdata(L, argv[0]); install_sexe_functions(L); /* sexe api lib */ narg = _api_push_args(L, argv, 0); status = sexe_loadfile(L, path, NULL); lua_insert(L, -(narg+1)); if (status == LUA_OK) { status = _api_docall(L, narg, LUA_MULTRET); update_sexe_userdata(L); } else { lua_pop(L, narg); } status = _api_report(L, status); lua_close(L); return (status); }
static int pmain(lua_State* L) { int argc=(int)lua_tointeger(L,1); char** argv=(char**)lua_touserdata(L,2); const Proto* f; int tot; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); tot = 0; for (i=1; i<argc; i++) { if (argv[i][0] == '-') continue; if (sexe_loadfile(L,argv[i], NULL)!=LUA_OK) fatal(lua_tostring(L,-1)); tot++; } f=combine(L, tot); SexePrintFunction(f, (run_flags & RUNF_VERBOSE)); return (0); }