MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / luaL_loadfile

Function luaL_loadfile

lua/lauxlib.c:600–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

598
599
600LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
601 LoadF lf;
602 int status, readstatus;
603 int c;
604 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
605 lf.extraline = 0;
606 if (filename == NULL) {
607 lua_pushliteral(L, "=stdin");
608 lf.f = stdin;
609 }
610 else {
611 lua_pushfstring(L, "@%s", filename);
612 lf.f = fopen(filename, "r");
613 if (lf.f == NULL) return errfile(L, "open", fnameindex);
614 }
615 c = getc(lf.f);
616 if (c == '#') { /* Unix exec. file? */
617 lf.extraline = 1;
618 while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
619 if (c == '\n') c = getc(lf.f);
620 }
621 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
622 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
623 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
624 /* skip eventual `#!...' */
625 while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
626 lf.extraline = 0;
627 }
628 ungetc(c, lf.f);
629 status = lua_load(L, getF, &lf, lua_tostring(L, -1));
630 readstatus = ferror(lf.f);
631 if (filename) fclose(lf.f); /* close file (even in case of errors) */
632 if (readstatus) {
633 lua_settop(L, fnameindex); /* ignore results from `lua_load' */
634 return errfile(L, "read", fnameindex);
635 }
636 lua_remove(L, fnameindex);
637 return status;
638}
639
640
641typedef struct LoadS {

Callers 6

dofileFunction · 0.85
handle_scriptFunction · 0.85
luaB_loadfileFunction · 0.85
luaB_dofileFunction · 0.85
pmainFunction · 0.85
loader_LuaFunction · 0.85

Calls 6

lua_gettopFunction · 0.85
lua_pushfstringFunction · 0.85
errfileFunction · 0.85
lua_loadFunction · 0.85
lua_settopFunction · 0.85
lua_removeFunction · 0.85

Tested by

no test coverage detected