1. -- parent script "Node"
  2.  
  3. property _name
  4. property _arity
  5. property _code
  6. property _children
  7.  
  8. ----------------------------------------
  9. -- @constructor
  10. ----------------------------------------
  11. on new (me, name, arity, code, children)
  12.   if voidP(children) then children = []
  13.   me._name = name
  14.   me._arity = arity
  15.   me._code = code
  16.   me._children = children
  17.   return me
  18. end
  19.  
  20. ----------------------------------------
  21. -- Runs a function node, returns result
  22. ----------------------------------------
  23. on call (me, null, arg)
  24.  
  25.   -- evaluate children
  26.   c = []
  27.   repeat with child in me._children
  28.     c.add(call(child, _movie, arg))
  29.   end repeat
  30.  
  31.   -- evaluate node
  32.   res = VOID
  33.   do(me._code)
  34.   return res
  35. end
  36.  
  37. ----------------------------------------
  38. -- Prints a node
  39. ----------------------------------------
  40. on print (me, indent)
  41.   if voidP(indent) then indent = ""
  42.   put indent&me._name
  43.   repeat with c in me._children
  44.     c.print(indent&"  ")
  45.   end repeat
  46. end
  47.  
  48. ----------------------------------------
  49. -- Returns a deep copy
  50. ----------------------------------------
  51. on clone (me)
  52.   children = []
  53.   repeat with c in me._children
  54.     children.add(c.clone())
  55.   end repeat
  56.   return me.script.new(me._name, me._arity, me._code, children)
  57. end
  58.  
  59. ----------------------------------------
  60. --
  61. ----------------------------------------
  62. on getChildren (me)
  63.   return me._children
  64. end
  65.  
[raw code]