MCPcopy Create free account
hub / github.com/Tencent/UnLua / Lpb_loadfile

Function Lpb_loadfile

Plugins/UnLuaExtensions/LuaProtobuf/Source/src/pb.cpp:1202–1227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1200}
1201
1202static int Lpb_loadfile(lua_State *L) {
1203 lpb_State *LS = lpb_lstate(L);
1204 const char *filename = luaL_checkstring(L, 1);
1205 size_t size;
1206 pb_Buffer b;
1207 pb_Slice s;
1208 int ret;
1209 FILE *fp = fopen(filename, "rb");
1210 if (fp == NULL)
1211 return luaL_fileresult(L, 0, filename);
1212 pb_initbuffer(&b);
1213 do {
1214 char *d = pb_prepbuffsize(&b, BUFSIZ);
1215 if (d == NULL) return fclose(fp), luaL_error(L, "out of memory");
1216 size = fread(d, 1, BUFSIZ, fp);
1217 pb_addsize(&b, size);
1218 } while (size == BUFSIZ);
1219 fclose(fp);
1220 s = pb_result(&b);
1221 ret = pb_load(&LS->local, &s);
1222 if (ret == PB_OK) global_state = &LS->local;
1223 pb_resetbuffer(&b);
1224 lua_pushboolean(L, ret == PB_OK);
1225 lua_pushinteger(L, pb_pos(s)+1);
1226 return 2;
1227}
1228
1229static int lpb_pushtype(lua_State *L, const pb_Type *t) {
1230 if (t == NULL) return 0;

Callers

nothing calls this directly

Calls 11

lpb_lstateFunction · 0.85
pb_initbufferFunction · 0.85
pb_prepbuffsizeFunction · 0.85
luaL_errorFunction · 0.85
pb_resultFunction · 0.85
pb_loadFunction · 0.85
pb_resetbufferFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushintegerFunction · 0.85
pb_posFunction · 0.85
luaL_fileresultFunction · 0.70

Tested by

no test coverage detected