MarkRoddy
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2010
06:43 PM
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
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
3 REPLIES 3

RokuKevin
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2010
10:25 AM
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.
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.
MarkRoddy
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2010
11:47 AM
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:
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:
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.
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.

RokuKevin
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2010
04:06 PM
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.
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.