MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / luaL_loadfile

Function luaL_loadfile

other_src/lua/src/lauxlib.cpp:577–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575
576
577LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
578 LoadF lf;
579 int status, readstatus;
580 int c;
581 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
582 lf.extraline = 0;
583 if (filename == NULL) {
584 lua_pushliteral(L, "=stdin");
585 lf.f = stdin;
586 }
587 else {
588 lua_pushfstring(L, "@%s", filename);
589 lf.f = fopen(filename, "r");
590 if (lf.f == NULL) return errfile(L, "open", fnameindex);
591 }
592 c = getc(lf.f);
593 if (c == '#') { /* Unix exec. file? */
594 lf.extraline = 1;
595 while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
596 if (c == '\n') c = getc(lf.f);
597 }
598 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
599 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
600 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
601 /* skip eventual `#!...' */
602 while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
603 lf.extraline = 0;
604 }
605 ungetc(c, lf.f);
606 status = lua_load(L, getF, &lf, lua_tostring(L, -1));
607 readstatus = ferror(lf.f);
608 if (filename) fclose(lf.f); /* close file (even in case of errors) */
609 if (readstatus) {
610 lua_settop(L, fnameindex); /* ignore results from `lua_load' */
611 return errfile(L, "read", fnameindex);
612 }
613 lua_remove(L, fnameindex);
614 return status;
615}
616
617
618typedef struct LoadS {

Callers 7

loader_LuaFunction · 0.70
luaB_loadfileFunction · 0.70
luaB_dofileFunction · 0.70
pmainFunction · 0.70
dofileFunction · 0.70
handle_scriptFunction · 0.70
LuaRobotMethod · 0.50

Calls 6

lua_gettopFunction · 0.70
lua_pushfstringFunction · 0.70
errfileFunction · 0.70
lua_loadFunction · 0.70
lua_settopFunction · 0.70
lua_removeFunction · 0.70

Tested by

no test coverage detected