Change-Id: I543b531ad4386ce7996e3b7ee061d70e5e564a9e
+function stringArrayAppend(strings, string)
+ if string ~= "" then
+ table.insert(strings, string)
+ end
+end
+
+function generateStringArray(objects, createFunc)
+ local ret = {}
+ for k, target in ipairs(objects) do
+ stringArrayAppend(ret, createFunc(target))
+ end
+ return ret
+end
+
function describeObject(obj)
function describeObject(obj)
- local related_trait = {}
- for k, target in ipairs(obj:inRelation(RELATION_DESCRIBED_BY)) do
- table.insert(related_trait, trait(target))
+ local labels = generateStringArray(obj:inRelation(RELATION_LABELLED_BY), function(x) return x:name() end)
+ local descriptions = generateStringArray(obj:inRelation(RELATION_DESCRIBED_BY), function(x) return x:description() end)
+ local traits = generateStringArray(obj:inRelation(RELATION_DESCRIBED_BY), trait)
+
+ -- use original object name if related objects do not provide other
+ if table.getn(labels) == 0 then
+ stringArrayAppend(labels, obj:name())
- local ret = {obj:name(), trait(obj), obj:description(), table.concat(related_trait, ", ")}
- for i=#ret,1,-1 do
- if ret[i] == nil or ret[i] == "" then
- table.remove(ret, i)
- end
+
+ -- use original object description if related objects do not provide other
+ if table.getn(descriptions) == 0 then
+ stringArrayAppend(descriptions, obj:description())
+
+ -- use original object trait if related objects do not provide other
+ if table.getn(traits) == 0 then
+ stringArrayAppend(traits, trait(obj))
+ end
+
+ local ret = {}
+ stringArrayAppend(ret, table.concat(labels, ", "))
+ stringArrayAppend(ret, table.concat(traits, ", "))
+ stringArrayAppend(ret, table.concat(descriptions, ", "))
+
return table.concat(ret, ", ")
end
return table.concat(ret, ", ")
end
AtspiAccessible *obj = _pop_class_obj(L, 1, 1, ACCESSIBLE_CLASS_NAME);
AtspiRelationType type = lua_tonumber(L, -1);
GError *err = NULL;
AtspiAccessible *obj = _pop_class_obj(L, 1, 1, ACCESSIBLE_CLASS_NAME);
AtspiRelationType type = lua_tonumber(L, -1);
GError *err = NULL;
lua_newtable(L);
if (!obj) return 1;
lua_newtable(L);
if (!obj) return 1;
GERROR_CHECK(err);
if (!rels) return 1;
GERROR_CHECK(err);
if (!rels) return 1;
- for (i = 0; i < rels->len; i++)
+ for (i = 0, idx = 1; i < rels->len; i++)
{
AtspiRelation *rel = g_array_index(rels, AtspiRelation*, i);
if (atspi_relation_get_relation_type(rel) == type)
{
AtspiRelation *rel = g_array_index(rels, AtspiRelation*, i);
if (atspi_relation_get_relation_type(rel) == type)
{
AtspiAccessible *target = atspi_relation_get_target(rel, j);
if (!target) continue;
{
AtspiAccessible *target = atspi_relation_get_target(rel, j);
if (!target) continue;
+ lua_pushinteger(L, idx++);
_push_class_obj(L, target, ACCESSIBLE_CLASS_NAME);
lua_settable(L, -3);
}
_push_class_obj(L, target, ACCESSIBLE_CLASS_NAME);
lua_settable(L, -3);
}