MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaL_loadfilex

Function luaL_loadfilex

depends/lua/src/lauxlib.c:703–736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701
702
703LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
704 const char *mode) {
705 LoadF lf;
706 int status, readstatus;
707 int c;
708 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
709 if (filename == NULL) {
710 lua_pushliteral(L, "=stdin");
711 lf.f = stdin;
712 }
713 else {
714 lua_pushfstring(L, "@%s", filename);
715 lf.f = fopen(filename, "r");
716 if (lf.f == NULL) return errfile(L, "open", fnameindex);
717 }
718 if (skipcomment(&lf, &c)) /* read initial portion */
719 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
720 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
721 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
722 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
723 skipcomment(&lf, &c); /* re-read initial portion */
724 }
725 if (c != EOF)
726 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
727 status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
728 readstatus = ferror(lf.f);
729 if (filename) fclose(lf.f); /* close file (even in case of errors) */
730 if (readstatus) {
731 lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
732 return errfile(L, "read", fnameindex);
733 }
734 lua_remove(L, fnameindex);
735 return status;
736}
737
738
739typedef struct LoadS {

Callers 1

luaB_loadfileFunction · 0.85

Calls 6

lua_gettopFunction · 0.85
lua_pushfstringFunction · 0.85
errfileFunction · 0.85
skipcommentFunction · 0.85
lua_loadFunction · 0.85
lua_settopFunction · 0.85

Tested by

no test coverage detected