| 403 | |
| 404 | |
| 405 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
| 406 | const char *fname, int szhint) { |
| 407 | const char *e; |
| 408 | lua_pushvalue(L, idx); |
| 409 | do { |
| 410 | e = strchr(fname, '.'); |
| 411 | if (e == NULL) e = fname + strlen(fname); |
| 412 | lua_pushlstring(L, fname, e - fname); |
| 413 | lua_rawget(L, -2); |
| 414 | if (lua_isnil(L, -1)) { /* no such field? */ |
| 415 | lua_pop(L, 1); /* remove this nil */ |
| 416 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ |
| 417 | lua_pushlstring(L, fname, e - fname); |
| 418 | lua_pushvalue(L, -2); |
| 419 | lua_settable(L, -4); /* set new table into field */ |
| 420 | } |
| 421 | else if (!lua_istable(L, -1)) { /* field has a non-table value? */ |
| 422 | lua_pop(L, 2); /* remove table and value */ |
| 423 | return fname; /* return problematic part of the name */ |
| 424 | } |
| 425 | lua_remove(L, -2); /* remove previous table */ |
| 426 | fname = e + 1; |
| 427 | } while (*e == '.'); |
| 428 | return NULL; |
| 429 | } |
| 430 | |
| 431 | |
| 432 |
no test coverage detected