Brightscript library called directly by firmware


It is obvious that main/runUserInterface in a channel, instead of library, is called by firmware.
How to make a function in library, instead of channel, that gets called without involving main/runUserInterface?
Here is a sample library to show how FW call BRS as it does with GrandCentral library.
Firmware loads roku_grandcentral_lib.zip, and calls launchContent.
On Brightscript side:
manifest file:
required: os_markup=1 sg_component_libs_provided=Roku_GrandCentral
sg_component_libs_provided so that FW knows it is a library instead of channel
optional: major_version, hidden=1
.xml file:
required: <field id=”scene” type=”node”/>
optional: base class of ContentLauncher, extends=”Node”, is not required
.brs:
required: the function being caalled by FW: launchContent
optional: init()
Folder structure and file name of xml and brs dont make difference.

On FW side:called in LaunchController.cpp

The way we know the function did get called:
check port 8085, and look for log message “Function launchContent is called by FW.”

BrightScript m variable


BrightScript is the language to program Roku streaming player.
The m keyword can be confusing.
code snippet from source/main.brs tagged with MvsThis, which stands for m vs this.

Function MvsThisCreate() as Object
	print "MvsThisCreate entered"
	obj = CreateObject("roAssociativeArray")
	obj.svc = "MvsThisSvc"
	obj.MvsThisFunc = MvsThisFunc
	obj.MvsThisFunc2 = MvsThisFunc2
	return obj
End Function

Function MvsThisFunc() as Void
	print "MvsThisFunc entered"
	print "MvsThisFunc m.svc="m.svc
	print "MvsThisFunc m.MvsThisFunc2="m.MvsThisFunc2
	print "MvsThisFunc MvsThisFunc2="MvsThisFunc2
	m.MvsThisFunc2("m.MvsThisFunc2")
	MvsThisFunc2("MvsThisFunc2")
End Function

Function MvsThisFunc2(str as String) as Void
	print "MvsThisFunc2 called by: "str
End Function

Function MvsThisTest() as Void
	print "MvsThisTest start"
	MvsThis = MvsThisCreate()
	MvsThis.MvsThisFunc()
	print "MvsThisTest done"
End Function

When we run MvsThisTest(), we get these output:

	MvsThisTest start
	MvsThisCreate entered
	MvsThisFunc entered
	MvsThisFunc m.svc=MvsThisSvc
	MvsThisFunc m.MvsThisFunc2=<Function: mvsthisfunc2>
	MvsThisFunc MvsThisFunc2=<Function: mvsthisfunc2>
	MvsThisFunc2 called by: m.MvsThisFunc2
	MvsThisFunc2 called by: MvsThisFunc2

As shown above, m is for accessing data in roAssociativeArray from roAssociativeArray’s function fields.
Calling m.MvsThisFunc2( and MvsThisFunc2(, without the m. are the same thing when the object is roAssociativeArray.
Calling m.MvsThisFunc2() doesn’t work if the object is SceneGraph node, e.g. loaded as xml file.