| 355 | |
| 356 | |
| 357 | LUALIB_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 |
no test coverage detected