EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2014
01:48 PM
roString vs String - which is when?
Reading doco:
That does not seem to be the case though:
Is documentation wrong? What's the relation between the two?
"3.2 Types" wrote:
... Internally there are two intrinsic string states. The first is for constant strings. For example, s="astring", will create an intrinsic constant string. But once a string is used in an expression, it becomes an "roString". For example: s=s+"more", results in s becoming an "roString".
That does not seem to be the case though:
BrightScript Debugger> s="astring"The result was String again. Yet roString exists:
BrightScript Debugger> ? type(s)
String
BrightScript Debugger> s=s+"more"
BrightScript Debugger> ? type(s)
String
BrightScript Debugger> ss = createobject("roString")
BrightScript Debugger> ? type(ss)
roString
BrightScript Debugger> ss.setString(s)
BrightScript Debugger> ? ss
astringmore
BrightScript Debugger> ? type(ss)
roString
Is documentation wrong? What's the relation between the two?
4 REPLIES 4

NewManLiving
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2014
02:17 PM
Re: roString vs String - which is when?
If my memory serves me correctly it may have something to do with
Wrapping or boxing of the intrinsic types with their
Object wrappers. Esp when sending intrinsic
To functions. I believe there is something in the docs under wrappers
Wrapping or boxing of the intrinsic types with their
Object wrappers. Esp when sending intrinsic
To functions. I believe there is something in the docs under wrappers
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2014
02:43 PM
Re: roString vs String - which is when?
Not an answer to your question, but kind of on-topic... I've found explicitly creating an roString allows you to update multiple objects with a single call. For example:
This will update the Title attribute on both object1 and object2. I find it particularly useful when maintaining the same data on multiple layers of an image canvas or roScreen (e.g., for button focus states).
titleString = CreateObject("roString")
titleString.SetString("Title")
object1 = {
Title: titleString
}
object2 = {
Title: titleString
}
titleString.SetString("NewTitle")
This will update the Title attribute on both object1 and object2. I find it particularly useful when maintaining the same data on multiple layers of an image canvas or roScreen (e.g., for button focus states).
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2014
03:03 PM
Re: roString vs String - which is when?
That makes sense. roString is an object, and like all objects, assignment just copies a pointer to the object. String is a literal, so copying one copies its contents, like copying an integer copies its contents. I certainly agree, it's not always easy to see when a variable contains a String or an roString. There is a sense in which what the doc says is true, Strings are converted to roStrings when necessary, but it's not always easy to predict when it's necessary. It's best to explicitly convert to roString if you need an object.
--Mark
--Mark
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2014
11:57 AM
Re: roString vs String - which is when?
"RokuMarkn" wrote:Well, when in doubt we can always check with `type()`, right? How come the example above, taken literally from the RTFM does not work?! It should have returned "roString" and it didn't.
I certainly agree, it's not always easy to see when a variable contains a String or an roString. There is a sense in which what the doc says is true, Strings are converted to roStrings when necessary, but it's not always easy to predict when it's necessary. It's best to explicitly convert to roString if you need an object.
Something sinister seems to happen though:
BrightScript Debugger> s = "foo": ?type(s),s, : s.setString("bar"): ?type(s),s '#1
String foo String foo
BrightScript Debugger> s = "f"+"oo": ?type(s),s, : s.setString("bar"): ?type(s),s '#2
String foo String bar
BrightScript Debugger> s= ["foo"][0]: ?type(s),s, : s.setString("bar"): ?type(s),s '#3
roString foo roString foo
One of those things is not like the other. Actually none are like the other, this is utterly befuddling! First, we see that sometimes mutator setString() does not change String (#1, as expected) - and sometimes it does (#2, wha?). And second, it does not change roString, which it should (#3, military grade "wtf?")
I was thinking boxed values can be used - after theEndless example - for passing function params "by reference" but now don't know what to think, massaraksh.