static int ucl_object_push_lua_common(lua_State *L, const ucl_object_t *obj, int flags);
static ucl_object_t *ucl_object_lua_fromtable(lua_State *L, int idx, ucl_string_flags_t flags);
static ucl_object_t *ucl_object_lua_fromelt(lua_State *L, int idx, ucl_string_flags_t flags);
+static ucl_object_t *lua_ucl_object_get(lua_State *L, int index);
static void *ucl_null;
obj = ucl_object_typed_new(UCL_NULL);
}
else {
- /* Assume it is a text like object */
- struct _rspamd_lua_text *t = lua_touserdata(L, idx);
+ ucl_object_t *other_elt = lua_ucl_object_get(L, idx);
- if (t) {
- if (t->len > 0) {
- obj = ucl_object_fromstring_common(t->start, t->len, 0);
- }
- else {
- obj = ucl_object_fromstring_common("", 0, 0);
- }
+ if (other_elt) {
+ return ucl_object_ref(other_elt);
+ }
+ else {
+ /* Assume it is a text like object */
+ struct _rspamd_lua_text *t = lua_touserdata(L, idx);
- /* Binary text */
- if (t->flags & (1u << 5u)) {
- obj->flags |= UCL_OBJECT_BINARY;
+ if (t) {
+ if (t->len > 0) {
+ obj = ucl_object_fromstring_common(t->start, t->len, 0);
+ }
+ else {
+ obj = ucl_object_fromstring_common("", 0, 0);
+ }
+
+ /* Binary text */
+ if (t->flags & (1u << 5u)) {
+ obj->flags |= UCL_OBJECT_BINARY;
+ }
}
}
}
return 1;
}
else {
- return luaL_error(L, "cannot index non-object");
+ return luaL_error(L, "cannot index non-object: %s", ucl_object_type_to_string(ucl_object_type(obj)));
}
}
else if (lua_type(L, 2) == LUA_TNUMBER) {
return 1;
}
else {
- return luaL_error(L, "cannot index non-array");
+ return luaL_error(L, "cannot index non-array: %s", ucl_object_type_to_string(ucl_object_type(obj)));
}
}
else {
- return luaL_error(L, "invalid index type");
+ return luaL_error(L, "invalid index type: %s", lua_typename(L, lua_type(L, 2)));
}
}
ucl_object_replace_key(obj, value_obj, key, keylen, true);
}
else {
- return luaL_error(L, "invalid value type");
+ return luaL_error(L, "invalid value type: %s", lua_typename(L, value_type));
}
}
else {
}
if (value_obj == NULL) {
- return luaL_error(L, "invalid value type");
+ return luaL_error(L, "invalid value type: %s", lua_typename(L, value_type));
}
/* Lua allows sparse arrays and ucl does not
else {
ucl_object_unref(value_obj);
- return luaL_error(L, "invalid index for array");
+ return luaL_error(L, "invalid index for array: %d", (int) idx);
}
return 0;
}
else {
- return luaL_error(L, "invalid index type");
+ return luaL_error(L, "invalid index type: %s (obj type: %s)", lua_typename(L, key_type),
+ ucl_object_type_to_string(ucl_object_type(obj)));
}
}