|
|
|
|
|
|
|
|
size_t keylen; |
|
|
size_t keylen; |
|
|
const char *k; |
|
|
const char *k; |
|
|
bool is_array = true, is_implicit = false, found_mt = false; |
|
|
bool is_array = true, is_implicit = false, found_mt = false; |
|
|
int max = INT_MIN; |
|
|
|
|
|
|
|
|
size_t max = 0, nelts = 0; |
|
|
|
|
|
|
|
|
if (idx < 0) { |
|
|
if (idx < 0) { |
|
|
/* For negative indicies we want to invert them */ |
|
|
/* For negative indicies we want to invert them */ |
|
|
|
|
|
|
|
|
} else if (strcmp (classname, UCL_ARRAY_TYPE_META) == 0) { |
|
|
} else if (strcmp (classname, UCL_ARRAY_TYPE_META) == 0) { |
|
|
is_array = true; |
|
|
is_array = true; |
|
|
found_mt = true; |
|
|
found_mt = true; |
|
|
|
|
|
#if LUA_VERSION_NUM >= 502 |
|
|
|
|
|
max = lua_rawlen (L, idx); |
|
|
|
|
|
#else |
|
|
|
|
|
max = lua_objlen (L, idx); |
|
|
|
|
|
#endif |
|
|
|
|
|
nelts = max; |
|
|
} else if (strcmp (classname, UCL_IMPL_ARRAY_TYPE_META) == 0) { |
|
|
} else if (strcmp (classname, UCL_IMPL_ARRAY_TYPE_META) == 0) { |
|
|
is_array = true; |
|
|
is_array = true; |
|
|
is_implicit = true; |
|
|
is_implicit = true; |
|
|
found_mt = true; |
|
|
found_mt = true; |
|
|
|
|
|
#if LUA_VERSION_NUM >= 502 |
|
|
|
|
|
max = lua_rawlen (L, idx); |
|
|
|
|
|
#else |
|
|
|
|
|
max = lua_objlen (L, idx); |
|
|
|
|
|
#endif |
|
|
|
|
|
nelts = max; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
/* Keys are not integer */ |
|
|
/* Keys are not integer */ |
|
|
lua_pop (L, 2); |
|
|
|
|
|
is_array = false; |
|
|
is_array = false; |
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
/* Keys are not numeric */ |
|
|
/* Keys are not numeric */ |
|
|
lua_pop (L, 2); |
|
|
|
|
|
is_array = false; |
|
|
is_array = false; |
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
lua_pop (L, 1); |
|
|
lua_pop (L, 1); |
|
|
|
|
|
nelts ++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (is_array) { |
|
|
|
|
|
#if LUA_VERSION_NUM >= 502 |
|
|
|
|
|
max = lua_rawlen (L, idx); |
|
|
|
|
|
#else |
|
|
|
|
|
max = lua_objlen (L, idx); |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Table iterate */ |
|
|
/* Table iterate */ |
|
|
if (is_array) { |
|
|
if (is_array) { |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
if (!is_implicit) { |
|
|
if (!is_implicit) { |
|
|
top = ucl_object_typed_new (UCL_ARRAY); |
|
|
top = ucl_object_typed_new (UCL_ARRAY); |
|
|
|
|
|
ucl_object_reserve (top, nelts); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
top = NULL; |
|
|
top = NULL; |
|
|
|
|
|
|
|
|
else { |
|
|
else { |
|
|
lua_pushnil (L); |
|
|
lua_pushnil (L); |
|
|
top = ucl_object_typed_new (UCL_OBJECT); |
|
|
top = ucl_object_typed_new (UCL_OBJECT); |
|
|
|
|
|
ucl_object_reserve (top, nelts); |
|
|
|
|
|
|
|
|
while (lua_next (L, idx) != 0) { |
|
|
while (lua_next (L, idx) != 0) { |
|
|
/* copy key to avoid modifications */ |
|
|
/* copy key to avoid modifications */ |
|
|
k = lua_tolstring (L, -2, &keylen); |
|
|
|
|
|
obj = ucl_object_lua_fromelt (L, lua_gettop (L), flags); |
|
|
|
|
|
|
|
|
lua_pushvalue (L, -2); |
|
|
|
|
|
k = lua_tolstring (L, -1, &keylen); |
|
|
|
|
|
obj = ucl_object_lua_fromelt (L, lua_gettop (L) - 1, flags); |
|
|
|
|
|
|
|
|
if (obj != NULL) { |
|
|
if (obj != NULL) { |
|
|
ucl_object_insert_key (top, obj, k, keylen, true); |
|
|
ucl_object_insert_key (top, obj, k, keylen, true); |
|
|
} |
|
|
} |
|
|
lua_pop (L, 1); |
|
|
|
|
|
|
|
|
lua_pop (L, 2); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|