static int pmain(lua_State *L) { struct Smain *s = &smain; char **argv = s->argv; int script; int flags = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* linker-enforced version check */ script = collectargs(argv, &flags); if (script < 0) { /* invalid args? */ print_usage(); s->status = 1; return 0; } if ((flags & FLAGS_NOENV)) { lua_pushboolean(L, 1); lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); } lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ s->status = tvm_loadbufferx(L, luaJIT_BC_op, luaJIT_BC_op_SIZE, "op", "b") || docall(L, 0, 1); if (s->status != 0) return 0; s->status = tvm_loadbufferx(L, luaJIT_BC_parse, luaJIT_BC_parse_SIZE, "parse", "b") || docall(L, 0, 1); if (s->status != 0) return 0; s->status = tvm_loadbufferx(L, luaJIT_BC_lunokhod, luaJIT_BC_lunokhod_SIZE, "lunokhod", "b") || docall(L, 0, 1); if (s->status != 0) return 0; lua_gc(L, LUA_GCRESTART, -1); if (!(flags & FLAGS_NOENV)) { s->status = handle_luainit(L); if (s->status != 0) return 0; } if ((flags & FLAGS_VERSION)) print_version(); s->status = runargs(L, argv, (script > 0) ? script : s->argc); if (s->status != 0) return 0; if (script) { s->status = handle_script(L, argv, script); if (s->status != 0) return 0; } if ((flags & FLAGS_INTERACTIVE)) { print_jit_status(L); dotty(L); } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) { if (lua_stdin_is_tty()) { print_version(); print_jit_status(L); dotty(L); } else { dofile(L, NULL); /* executes stdin as a file */ } } return 0; }
static void print_version(lua_State *L, int jit) { #ifndef LUAJIT_PRETEND_RIO fputs(LJX_VERSION ", type _COPYRIGHTS, _CREDITS, _VERSION for more info.\n", stdout); fputs(LUA_VERSION ", ABI: " LUA_ABIVER_STRING " on " LJ_OS_NAME "/" LJ_ARCH_NAME #if LJ_4GB "/4GB heap" #elif LJ_GC64 "/GC64" #endif , stdout); #ifdef __DATE__ fputs(", built " __DATE__, stdout); #endif #ifdef __VERSION__ fputs(" using GCC " __VERSION__ "\n", stdout); #else fputs("\n", stdout); #endif if (jit) print_jit_status(L); #else fputs(LUA_RELEASE " " LUA_COPYRIGHT"\n", stdout); #endif /* These are defined only in interactive session. */ lua_pushliteral(L, LUA_COPYRIGHTS); lua_setglobal(L, "_COPYRIGHTS"); lua_pushliteral(L, LUA_CREDITS); lua_setglobal(L, "_CREDITS"); }
static int pmain(lua_State *L) { struct Smain *s = (struct Smain *)lua_touserdata(L, 1); char **argv = s->argv; int script; int has_i = 0, has_v = 0, has_e = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* linker-enforced version check */ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ lua_gc(L, LUA_GCRESTART, -1); s->status = handle_luainit(L); if (s->status != 0) return 0; script = collectargs(argv, &has_i, &has_v, &has_e); if (script < 0) { /* invalid args? */ print_usage(); s->status = 1; return 0; } if (has_v) print_version(); s->status = runargs(L, argv, (script > 0) ? script : s->argc); if (s->status != 0) return 0; if (script) s->status = handle_script(L, argv, script); if (s->status != 0) return 0; if (has_i) { print_jit_status(L); dotty(L); } else if (script == 0 && !has_e && !has_v) { if (lua_stdin_is_tty()) { print_version(); print_jit_status(L); dotty(L); } else { dofile(L, NULL); /* executes stdin as a file */ } } return 0; }