| 338 | |
| 339 | |
| 340 | static int pmain (lua_State *L) { |
| 341 | struct Smain *s = (struct Smain *)lua_touserdata(L, 1); |
| 342 | char **argv = s->argv; |
| 343 | int script; |
| 344 | int has_i = 0, has_v = 0, has_e = 0; |
| 345 | globalL = L; |
| 346 | if (argv[0] && argv[0][0]) progname = argv[0]; |
| 347 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ |
| 348 | luaL_openlibs(L); /* open libraries */ |
| 349 | lua_gc(L, LUA_GCRESTART, 0); |
| 350 | s->status = handle_luainit(L); |
| 351 | if (s->status != 0) return 0; |
| 352 | script = collectargs(argv, &has_i, &has_v, &has_e); |
| 353 | if (script < 0) { /* invalid args? */ |
| 354 | print_usage(); |
| 355 | s->status = 1; |
| 356 | return 0; |
| 357 | } |
| 358 | if (has_v) print_version(); |
| 359 | s->status = runargs(L, argv, (script > 0) ? script : s->argc); |
| 360 | if (s->status != 0) return 0; |
| 361 | if (script) |
| 362 | s->status = handle_script(L, argv, script); |
| 363 | if (s->status != 0) return 0; |
| 364 | if (has_i) |
| 365 | dotty(L); |
| 366 | else if (script == 0 && !has_e && !has_v) { |
| 367 | if (lua_stdin_is_tty()) { |
| 368 | print_version(); |
| 369 | dotty(L); |
| 370 | } |
| 371 | else dofile(L, NULL); /* executes stdin as a file */ |
| 372 | } |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | int main (int argc, char **argv) { |
nothing calls this directly
no test coverage detected