| 380 | |
| 381 | |
| 382 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
| 383 | const char *fname, int szhint) { |
| 384 | const char *e; |
| 385 | lua_pushvalue(L, idx); |
| 386 | do { |
| 387 | e = strchr(fname, '.'); |
| 388 | if (e == NULL) e = fname + strlen(fname); |
| 389 | lua_pushlstring(L, fname, e - fname); |
| 390 | lua_rawget(L, -2); |
| 391 | if (lua_isnil(L, -1)) { /* no such field? */ |
| 392 | lua_pop(L, 1); /* remove this nil */ |
| 393 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ |
| 394 | lua_pushlstring(L, fname, e - fname); |
| 395 | lua_pushvalue(L, -2); |
| 396 | lua_settable(L, -4); /* set new table into field */ |
| 397 | } |
| 398 | else if (!lua_istable(L, -1)) { /* field has a non-table value? */ |
| 399 | lua_pop(L, 2); /* remove table and value */ |
| 400 | return fname; /* return problematic part of the name */ |
| 401 | } |
| 402 | lua_remove(L, -2); /* remove previous table */ |
| 403 | fname = e + 1; |
| 404 | } while (*e == '.'); |
| 405 | return NULL; |
| 406 | } |
| 407 | |
| 408 | |
| 409 |
no test coverage detected