MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / pmain

Function pmain

lib/lua/src/lua.c:626–668  ·  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

624** Reads the options and handles them all.
625*/
626static int pmain (lua_State *L) {
627 int argc = (int)lua_tointeger(L, 1);
628 char **argv = (char **)lua_touserdata(L, 2);
629 int script;
630 int args = collectargs(argv, &script);
631 int optlim = (script > 0) ? script : argc; /* first argv not an option */
632 luaL_checkversion(L); /* check that interpreter has correct version */
633 if (args == has_error) { /* bad arg? */
634 print_usage(argv[script]); /* 'script' has index of bad arg. */
635 return 0;
636 }
637 if (args & has_v) /* option '-v'? */
638 print_version();
639 if (args & has_E) { /* option '-E'? */
640 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
641 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
642 }
643 luaL_openlibs(L); /* open standard libraries */
644 createargtable(L, argv, argc, script); /* create table 'arg' */
645 lua_gc(L, LUA_GCRESTART); /* start GC... */
646 lua_gc(L, LUA_GCGEN, 0, 0); /* ...in generational mode */
647 if (!(args & has_E)) { /* no option '-E'? */
648 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
649 return 0; /* error running LUA_INIT */
650 }
651 if (!runargs(L, argv, optlim)) /* execute arguments -e and -l */
652 return 0; /* something failed */
653 if (script > 0) { /* execute main script (if there is one) */
654 if (handle_script(L, argv + script) != LUA_OK)
655 return 0; /* interrupt in case of error */
656 }
657 if (args & has_i) /* -i option? */
658 doREPL(L); /* do read-eval-print loop */
659 else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */
660 if (lua_stdin_is_tty()) { /* running in interactive mode? */
661 print_version();
662 doREPL(L); /* do read-eval-print loop */
663 }
664 else dofile(L, NULL); /* executes stdin as a file */
665 }
666 lua_pushboolean(L, 1); /* signal no errors */
667 return 1;
668}
669
670
671int main (int argc, char **argv) {

Callers

nothing calls this directly

Calls 14

lua_touserdataFunction · 0.85
collectargsFunction · 0.85
print_usageFunction · 0.85
print_versionFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_setfieldFunction · 0.85
luaL_openlibsFunction · 0.85
createargtableFunction · 0.85
lua_gcFunction · 0.85
handle_luainitFunction · 0.85
runargsFunction · 0.85
handle_scriptFunction · 0.85

Tested by

no test coverage detected