MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaL_findtable

Function luaL_findtable

deps/lua/src/lauxlib.c:357–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355
356
357LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
358 const char *fname, int szhint) {
359 const char *e;
360 lua_pushvalue(L, idx);
361 do {
362 e = strchr(fname, '.');
363 if (e == NULL) e = fname + strlen(fname);
364 lua_pushlstring(L, fname, e - fname);
365 lua_rawget(L, -2);
366 if (lua_isnil(L, -1)) { /* no such field? */
367 lua_pop(L, 1); /* remove this nil */
368 lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
369 lua_pushlstring(L, fname, e - fname);
370 lua_pushvalue(L, -2);
371 lua_settable(L, -4); /* set new table into field */
372 }
373 else if (!lua_istable(L, -1)) { /* field has a non-table value? */
374 lua_pop(L, 2); /* remove table and value */
375 return fname; /* return problematic part of the name */
376 }
377 lua_remove(L, -2); /* remove previous table */
378 fname = e + 1;
379 } while (*e == '.');
380 return NULL;
381}
382
383
384

Callers 3

luaI_openlibFunction · 0.85
ll_moduleFunction · 0.85
luaopen_packageFunction · 0.85

Calls 6

lua_pushvalueFunction · 0.85
lua_pushlstringFunction · 0.85
lua_rawgetFunction · 0.85
lua_createtableFunction · 0.85
lua_settableFunction · 0.85
lua_removeFunction · 0.85

Tested by

no test coverage detected