Permalink
Browse files

Added parents/chparents and deprecated parent/chparent.

  • Loading branch information...
1 parent d296f61 commit 2c3109806a36cf85fad35e2dcb9c52a211ed5303 @toddsundsted committed May 24, 2011
Showing with 192 additions and 116 deletions.
  1. +1 −11 db_objects.c
  2. +2 −0 execute.c
  3. +34 −5 objects.c
  4. +8 −0 test/lib/moo_support.rb
  5. +147 −100 test/test_objects.rb
View
@@ -495,17 +495,7 @@ db_change_parent(Objid oid, Var new_parents)
free_var(objects[oid]->parents);
- /* Clean up the representation.
- * {#X} becomes #X
- * {} becomes NOTHING
- */
- if (new_parents.type == TYPE_LIST && new_parents.v.list[0].v.num == 0)
- objects[oid]->parents = nothing;
- else if (new_parents.type == TYPE_LIST && new_parents.v.list[0].v.num == 1)
- objects[oid]->parents = var_dup(new_parents.v.list[1]);
- else
- objects[oid]->parents = var_dup(new_parents);
-
+ objects[oid]->parents = var_dup(new_parents);
Var new_ancestors = db_ancestors(oid, true);
dbpriv_fix_properties_after_chparent(oid, old_ancestors, new_ancestors);
View
@@ -607,6 +607,8 @@ call_verb2(Objid this, const char *vname, Var args, int do_pass)
Var parents = db_object_parent(RUN_ACTIV.vloc);
if (TYPE_LIST == parents.type) {
+ if (listlength(parents) == 0)
+ return E_INVIND;
/* Loop over each parent, looking for the first parent
* that defines a suitable verb that we can pass to.
*/
View
@@ -389,7 +389,7 @@ bf_create_read(void)
}
static package
-bf_chparent(Var arglist, Byte next, void *vdata, Objid progr)
+bf_chparent_chparents(Var arglist, Byte next, void *vdata, Objid progr)
{ /* (OBJ what, OBJ|LIST new_parent) */
if (!is_obj_or_list_of_objs(arglist.v.list[2])) {
free_var(arglist);
@@ -435,19 +435,46 @@ bf_chparent(Var arglist, Byte next, void *vdata, Objid progr)
}
}
+/* bf_parent is DEPRECATED! It returns only the first parent in the
+ * set of parents. Use bf_parents!
+ */
static package
bf_parent(Var arglist, Byte next, void *vdata, Objid progr)
{ /* (OBJ object) */
- Var r;
Objid obj = arglist.v.list[1].v.obj;
free_var(arglist);
if (!valid(obj))
return make_error_pack(E_INVARG);
else {
- r = db_object_parent(obj);
- return make_var_pack(var_dup(r));
+ Var r = db_object_parent(obj);
+ if (r.type == TYPE_LIST && listlength(r) == 0)
+ return make_var_pack(new_obj(NOTHING));
+ else if (r.type == TYPE_LIST)
+ return make_var_pack(var_ref(r.v.list[1]));
+ else
+ return make_var_pack(var_ref(r));
+ }
+}
+
+static package
+bf_parents(Var arglist, Byte next, void *vdata, Objid progr)
+{ /* (OBJ object) */
+ Objid obj = arglist.v.list[1].v.obj;
+
+ free_var(arglist);
+
+ if (!valid(obj))
+ return make_error_pack(E_INVARG);
+ else {
+ Var r = db_object_parent(obj);
+ if (r.type == TYPE_OBJ && r.v.obj == NOTHING)
+ return make_var_pack(new_list(0));
+ if (r.type == TYPE_OBJ)
+ return make_var_pack(enlist_var(var_ref(r)));
+ else
+ return make_var_pack(var_ref(r));
}
}
@@ -756,7 +783,9 @@ register_objects(void)
TYPE_OBJ);
register_function("object_bytes", 1, 1, bf_object_bytes, TYPE_OBJ);
register_function("valid", 1, 1, bf_valid, TYPE_OBJ);
- register_function("chparent", 2, 2, bf_chparent, TYPE_OBJ, TYPE_ANY);
+ register_function("chparents", 2, 2, bf_chparent_chparents, TYPE_OBJ, TYPE_LIST);
+ register_function("chparent", 2, 2, bf_chparent_chparents, TYPE_OBJ, TYPE_OBJ);
+ register_function("parents", 1, 1, bf_parents, TYPE_OBJ);
register_function("parent", 1, 1, bf_parent, TYPE_OBJ);
register_function("children", 1, 1, bf_children, TYPE_OBJ);
register_function("ancestors", 1, 1, bf_ancestors, TYPE_OBJ);
@@ -151,10 +151,18 @@ def chparent(*args)
simplify command %Q|; return chparent(#{args.map{|a| value_ref(a)}.join(', ')});|
end
+ def chparents(*args)
+ simplify command %Q|; return chparents(#{args.map{|a| value_ref(a)}.join(', ')});|
+ end
+
def parent(*args)
simplify command %Q|; return parent(#{args.map{|a| value_ref(a)}.join(', ')});|
end
+ def parents(*args)
+ simplify command %Q|; return parents(#{args.map{|a| value_ref(a)}.join(', ')});|
+ end
+
def children(object)
simplify command %Q|; return children(#{obj_ref(object)});|
end
Oops, something went wrong.

0 comments on commit 2c31098

Please sign in to comment.