Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
MarkRoddy
Visitor

roGlobal Object

The roGlobal object is listed in the 'Core BrightScript Components and Interfaces' section of the BrightScript reference doc, but there isn't much besides the mention of its existence. The specific line is:

roGlobal (interfaces: ifGlobal; all static member functions)

There's no listing of the members of the ifGlobal interface. Was this intentionally left out? Can this object be used to share state between procedures? Is there any reason for its existence within BrightScript which isn't detailed or is this just a implementation detail?

-Mark
0 Kudos
3 REPLIES 3
RokuKevin
Visitor

Re: roGlobal Object

roGlobal is a special class. It is a placeholder for all the global functions in the BrightScript language. These functions are documented in the following sections of the BrightScript reference manual:

7.0 Global Utility Functions
8.0 Global String Functions
9.0 Global Math Functions

Although the roGlobal object is always in scope (object global) and its methods are available to all procedures, you cannot modify this object. Therefore, it cannot be used to share state between procedures. Note that besides this exception to provide global static methods in the BrightScript language, there are purposely no global variables in BrightScript.
0 Kudos
MarkRoddy
Visitor

Re: roGlobal Object

Kevin,
Thanks for the reply. I don't necessarily need a global variable, but it was one possible means to an end which I was exploring. Effectively this is the code I'm trying to implement:

Sub testOneEqualTwo( )
assertEqual(1, 2)
End Sub

Sub assertEqual(val1 as integer, val2 as integer)
if val1 <> val2 then
'Do something to "signal" test runner that an assert failed
end if
End Sub

Sub runTests()
eval('testOneEqualTwo')
'Check for "signal" from assertEqual to see if failed
End Sub


One of my thought was to set a global attribute in assertEqual( ) and runTests() could check to see if this was set. Your post pretty much confirms that this will not be possible.

Another thought was to be able to throw my own custom error in assertEqual() which runTests() could check for via the GetLastRunRuntimeError() function. Is it possible to declare and purposely trigger your own run time errors? This doesn't seem to be the case from the docs, but I thought I should ask just in case.

The last approach is to make assertEqual() a member function and then set a attribute in the method like such:
Sub assertEqual(val1 as integer, val2 as integer)
if val1 <> val2 then
'Set attribute to be inspected by runner for assertion failure
m.AssertErrorMessage = "Value1 does not equal Value2"

'Cause run time error so test will stop
i = 1/0
end if
End Sub


It's pretty clunky, but it gets the job done. My quible with it though is it requires testOneEqualTwo() to be a member function as well which is a pain since you have to setup a constructor which attaches all the test*() methods to the roAssociativeArray.
0 Kudos
RokuKevin
Visitor

Re: roGlobal Object

You are correct that you cannot define your own runtime errors that GetLastRunRuntimeError() might return.

Rather than forcing a runtime error with i=1/0, you could just use the keyword stop.

When testOneEqualTwo() and assertEqual() are global functions, your setting of m.AssertErrorMessage will make your string available to the Main() function, so that may give you a workaround.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.