MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / pmain

Function pmain

src/Chain/libraries/glua/lua.cpp:552–591  ·  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

550** Reads the options and handles them all.
551*/
552static int pmain(lua_State *L) {
553 int argc = (int)lua_tointeger(L, 1);
554 char **argv = (char **)lua_touserdata(L, 2);
555 int script;
556 int args = collectargs(argv, &script);
557 luaL_checkversion(L); /* check that interpreter has correct version */
558 if (argv[0] && argv[0][0]) progname = argv[0];
559 if (args == has_error) { /* bad arg? */
560 print_usage(argv[script]); /* 'script' has index of bad arg. */
561 return 0;
562 }
563 if (args & has_v) /* option '-v'? */
564 print_version();
565 if (args & has_E) { /* option '-E'? */
566 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
567 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
568 }
569 luaL_openlibs(L); /* open standard libraries */
570 createargtable(L, argv, argc, script); /* create table 'arg' */
571 if (!(args & has_E)) { /* no option '-E'? */
572 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
573 return 0; /* error running LUA_INIT */
574 }
575 if (!runargs(L, argv, script)) /* execute arguments -e and -l */
576 return 0; /* something failed */
577 if (script < argc && /* execute main script (if there is one) */
578 handle_script(L, argv + script) != LUA_OK)
579 return 0;
580 if (args & has_i) /* -i option? */
581 doREPL(L); /* do read-eval-print loop */
582 else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */
583 if (lua_stdin_is_tty()) { /* running in interactive mode? */
584 print_version();
585 doREPL(L); /* do read-eval-print loop */
586 }
587 else dofile(L, nullptr); /* executes stdin as a file */
588 }
589 lua_pushboolean(L, 1); /* signal no errors */
590 return 1;
591}
592
593
594int main1(int argc, char **argv) {

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected