MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / pmain

Function pmain

third-party/lua-5.5.0/src/lua.c:704–746  ·  view source on GitHub ↗

** Main body of stand-alone interpreter (to be called in protected mode). ** Reads the options and handles them all. */

Source from the content-addressed store, hash-verified

702** Reads the options and handles them all.
703*/
704static int pmain (lua_State *L) {
705 int argc = (int)lua_tointeger(L, 1);
706 char **argv = (char **)lua_touserdata(L, 2);
707 int script;
708 int args = collectargs(argv, &script);
709 int optlim = (script > 0) ? script : argc; /* first argv not an option */
710 luaL_checkversion(L); /* check that interpreter has correct version */
711 if (args == has_error) { /* bad arg? */
712 print_usage(argv[script]); /* 'script' has index of bad arg. */
713 return 0;
714 }
715 if (args & has_v) /* option '-v'? */
716 print_version();
717 if (args & has_E) { /* option '-E'? */
718 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
719 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
720 }
721 luai_openlibs(L); /* open standard libraries */
722 createargtable(L, argv, argc, script); /* create table 'arg' */
723 lua_gc(L, LUA_GCRESTART); /* start GC... */
724 lua_gc(L, LUA_GCGEN); /* ...in generational mode */
725 if (!(args & has_E)) { /* no option '-E'? */
726 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
727 return 0; /* error running LUA_INIT */
728 }
729 if (!runargs(L, argv, optlim)) /* execute arguments -e, -l, and -W */
730 return 0; /* something failed */
731 if (script > 0) { /* execute main script (if there is one) */
732 if (handle_script(L, argv + script) != LUA_OK)
733 return 0; /* interrupt in case of error */
734 }
735 if (args & has_i) /* -i option? */
736 doREPL(L); /* do read-eval-print loop */
737 else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */
738 if (lua_stdin_is_tty()) { /* running in interactive mode? */
739 print_version();
740 doREPL(L); /* do read-eval-print loop */
741 }
742 else dofile(L, NULL); /* executes stdin as a file */
743 }
744 lua_pushboolean(L, 1); /* signal no errors */
745 return 1;
746}
747
748
749int main (int argc, char **argv) {

Callers

nothing calls this directly

Calls 14

lua_touserdataFunction · 0.70
collectargsFunction · 0.70
print_usageFunction · 0.70
print_versionFunction · 0.70
lua_pushbooleanFunction · 0.70
lua_setfieldFunction · 0.70
createargtableFunction · 0.70
lua_gcFunction · 0.70
handle_luainitFunction · 0.70
runargsFunction · 0.70
handle_scriptFunction · 0.70
doREPLFunction · 0.70

Tested by

no test coverage detected