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