Passing an assocarray with function fields through callFunc on an interface functional field
Hi all,
Back with another question š
I'm noticing that when I try to pass an assocarray through callFunc on an interface's functional field, the assocarray keeps all its key values (nodes, primitive values) but it loses any function values, these becoming `Invalid`. For example, if I have this `FooFactory` component:
<component name="FooFactory" extends="Node">
<interface>
<function name="makeFoo" />
</interface>
<script type="text/brightscript"><![CDATA[
function makeFoo() as Object
foo = {}
foo.bar = 123
foo.baz = "hello"
foo.stringify = function()
return "bar: " + m.bar.toStr() + " baz: " + m.baz
end function
return foo
end function
]]></script>
</component>
and then I use this in another component, like so:
<component name="MyScene" extends="Scene">
<script type="text/brightscript"><![CDATA[
sub init()
factory = createObject("roSGNode", "FooFactory")
foo = factory.callFunc("makeFoo")
print foo.bar ' This works!
print foo.baz ' This works!
print foo.stringify() ' This crashes!
end sub
]]></script>
</component>
And this crashes because `foo.stringify` has become `Invalid` (though still present as a key) while the other int and string members, are still there. Specifically, the error is:
Member function not found in BrightScript Component or interface.
Any advice on how to make this work, or how to achieve something similar, where one component can return an "object" with methods to another component?