Callfunc Operator
In BrightScript, calling a function on a custom component requires you to use the callfunc function. A standard callfunc expression looks something like this: node.callFunc("functionName", someArg, someOtherArg). This deviates from the conventional object.someMethod() syntax you are used to with standard objects.
Which leads us to the callfunc operator in BrighterScript. This is denoted by an at symbol followed by a period. ( @. ). Whenever BrighterScript encounters the callfunc operator, it will transpile the code into a valid callfunc expression, while allowing you to write mostly the same type of syntax you're used to for object method calls.
Basic usage
node@.someMethod(1,2,3)View the transpiled BrightScript code
node.callfunc("someMethod", 1, 2, 3)Callfunc evaluation with no arguments
It is a well-known issue in BrightScript development that calling callfunc without at least one parameter has the potential to result in the function not being called at all. So to mitigate this issue, BrighterScript will automatically insert invalid as the first argument if you use the callfunc operator with no parameters.
For example, this:
node@.doSomething()View the transpiled BrightScript code
node.callfunc("doSomething")It is the developer's responsibility to ensure that the target function has at least one parameter, and that the type is dynamic, otherwise a type mismatch runtime error will occur.