| 222 | } |
| 223 | |
| 224 | static int c_lua_gettable_bypath(lua_State* L) { |
| 225 | size_t len = 0; |
| 226 | const char * pos = NULL; |
| 227 | const char * path = lua_tolstring(L, 2, &len); |
| 228 | lua_pushvalue(L, 1); |
| 229 | do { |
| 230 | pos = strchr(path, '.'); |
| 231 | if (NULL == pos) { |
| 232 | lua_pushlstring(L, path, len); |
| 233 | } else { |
| 234 | lua_pushlstring(L, path, pos - path); |
| 235 | len = len - (pos - path + 1); |
| 236 | path = pos + 1; |
| 237 | } |
| 238 | lua_gettable(L, -2); |
| 239 | if (lua_type(L, -1) != LUA_TTABLE) { |
| 240 | if (NULL != pos) { // not found in path |
| 241 | lua_pushnil(L); |
| 242 | } |
| 243 | break; |
| 244 | } |
| 245 | lua_remove(L, -2); |
| 246 | } while(pos); |
| 247 | return 1; |
| 248 | } |
| 249 | |
| 250 | LUA_API int xlua_pgettable_bypath(lua_State* L, int idx, const char *path) { |
| 251 | idx = lua_absindex(L, idx); |
nothing calls this directly
no test coverage detected