
coopdaddyswag
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018
08:32 AM
Pass Anonymous Function as a Parameter?
I am trying to create a bunch of callback functions that are in an Associative Array, which then is saved to another Scenegraph object's interface field.
However, when accessing the interface field in the same object, it states that the function is invalid.
Object 1:
Object 2:
When accessing the callbacks field in Object 2, I can see the added object but the function that was defined inside it, is invalid.
Is this allowed? Or do I have to pass the function through a `setter` method?
However, when accessing the interface field in the same object, it states that the function is invalid.
Object 1:
callbacks = {
afterchildcreatecallback: function ()
print "THIS IS A CALLBACK FUNCTION"
return 1
end function
}
m.contentReader = createObject("roSGNode", "ContentReader")
m.contentReader.observeField("content", "setLists")
m.contentReader.contenturi = "pkg:/data/contentLists/" + settingFocused.id + "Data.xml"
m.contentReader.callbacks = callbacks
m.contentReader.control = "RUN"
Object 2:
<component name = "ContentReader" extends = "Task" >
<script type = "text/brightscript" uri="pkg:/components/taskRunners/contentReader.brs"></script>
<interface>
<field id = "contenturi" type = "uri"></field>
<field id = "content" type = "node"></field>
<field id = "callbacks" type = "assocarray"></field>
</interface>
</component>
When accessing the callbacks field in Object 2, I can see the added object but the function that was defined inside it, is invalid.
Is this allowed? Or do I have to pass the function through a `setter` method?
1 REPLY 1


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018
02:08 PM
Re: Pass Anonymous Function as a Parameter?
"coopdaddyswag" wrote:
I am trying to create a bunch of callback functions that are in an Associative Array, which then is saved to another Scenegraph object's interface field.
However, when accessing the interface field in the same object, it states that the function is invalid.
...
Is this allowed? Or do I have to pass the function through a `setter` method?
There are limitations as to what types of nested data may be stored in a field of type array or associative array, though I don't know where the documentation is that I might point you to. As far as I know, you can't store any values of type Function, nor most non-primitive Object types other then Array, Associative Array, and I think roSGNode. Any values of non-supported type are silently dropped from the container when assigning to the field.