| 10567 | |
| 10568 | |
| 10569 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
| 10570 | const char *fname, int szhint) { |
| 10571 | const char *e; |
| 10572 | lua_pushvalue(L, idx); |
| 10573 | do { |
| 10574 | e = strchr(fname, '.'); |
| 10575 | if (e == NULL) e = fname + strlen(fname); |
| 10576 | lua_pushlstring(L, fname, e - fname); |
| 10577 | lua_rawget(L, -2); |
| 10578 | if (lua_isnil(L, -1)) { /* no such field? */ |
| 10579 | lua_pop(L, 1); /* remove this nil */ |
| 10580 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ |
| 10581 | lua_pushlstring(L, fname, e - fname); |
| 10582 | lua_pushvalue(L, -2); |
| 10583 | lua_settable(L, -4); /* set new table into field */ |
| 10584 | } |
| 10585 | else if (!lua_istable(L, -1)) { /* field has a non-table value? */ |
| 10586 | lua_pop(L, 2); /* remove table and value */ |
| 10587 | return fname; /* return problematic part of the name */ |
| 10588 | } |
| 10589 | lua_remove(L, -2); /* remove previous table */ |
| 10590 | fname = e + 1; |
| 10591 | } while (*e == '.'); |
| 10592 | return NULL; |
| 10593 | } |
| 10594 | |
| 10595 | |
| 10596 |
no test coverage detected