| 273 | } |
| 274 | |
| 275 | static int c_lua_settable_bypath(lua_State* L) { |
| 276 | size_t len = 0; |
| 277 | const char * pos = NULL; |
| 278 | const char * path = lua_tolstring(L, 2, &len); |
| 279 | lua_pushvalue(L, 1); |
| 280 | do { |
| 281 | pos = strchr(path, '.'); |
| 282 | if (NULL == pos) { // last |
| 283 | lua_pushlstring(L, path, len); |
| 284 | lua_pushvalue(L, 3); |
| 285 | lua_settable(L, -3); |
| 286 | lua_pop(L, 1); |
| 287 | break; |
| 288 | } else { |
| 289 | lua_pushlstring(L, path, pos - path); |
| 290 | len = len - (pos - path + 1); |
| 291 | path = pos + 1; |
| 292 | } |
| 293 | lua_gettable(L, -2); |
| 294 | if (lua_type(L, -1) != LUA_TTABLE) { |
| 295 | return luaL_error(L, "can not set value to %s", lua_tostring(L, 2)); |
| 296 | } |
| 297 | lua_remove(L, -2); |
| 298 | } while(pos); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | LUA_API int xlua_psettable_bypath(lua_State* L, int idx, const char *path) { |
| 303 | int top = lua_gettop(L); |
nothing calls this directly
no test coverage detected