Casting. 🔼

There are various inconsistencies between SL and various OS version about how casting works.  It doesn't help that SL doesn't define these well.


http://wiki.secondlife.com/wiki/Typecast

Only mentions implicit casts string -> key and Integer -> float

Doesn't mention double casts, which happens in SL sometimes, but is an error in OS.

Doesn't mention implicit integer -> string, though uses that in examples elsewhere.

http://wiki.secondlife.com/wiki/LSL101/LSLinFocus:Integers

Includes a "Integers to other types" section, which is blank.


reported=2019-06-08 07:39:15

reporter=onefang

priority=high

category=Bug

severity=major

resolution=no change required


2019-06-13 16:01:40 onefang: [url=http://wiki.secondlife.com/wiki/List]Includes an example of using a list to avoid explicit casting, [/url] notable coz it is using integers and strings.

[code=LSL]

integer min; integer max; integer total;

llSay(0, (string) ["Minimum: ", min, " Maximum: ", max, " Total: ", total] ); // requires 1 explicit cast instead of 3

[/code]


2019-06-13 16:10:55 onefang: [url=http://wiki.secondlife.com/wiki/LSL_Operators]LSL_Operators[/url] includes the text about not being sure if boolean operator precedence is a bug or a feature.  SL's own description of LSL isn't a proper specification of the language.  Pffft

"[b]Note:[/b] The order of precedence of boolean operators is unclear. It is possible that there is a [url=http://jira.secondlife.com/browse/SVC-779]bug[/url] in the expression parser, making precedence inconsistent, or it may simply be that || and && have equal precedence; testing is inconclusive. Thus, when in doubt, parenthesize. [b]SubNote:[/b] As the above bug has been closed as expected behavior, one can only assume the boolean operators have equal precedence."


2019-06-13 16:12:26 onefang: I was sure I had seen an example in SL's LSL portal of implicit casting integer to string, can't find it now.  It has always worked for me anyway.


2019-06-17 04:10:01 onefang: This form works fine in OpenSim 0.8 and 0.9, but not in current SL -

[code=LSL]

"string " + 1

[/code]

In current SL it has to be -

[code=LSL]

"string " + (string)1

[/code]


2019-06-17 06:14:55 onefang: Note - Lua will implicitly cast "numbers" to strings and strings to "numbers" when they are mixed.


2019-06-18 01:54:31 onefang: Going forward we'll want to use the Lua friendly way.


2019-07-23 15:15:15 onefang: The two child bugs are resolved, and the main issue with this one already works correctly in both versions of OpenSim.  SO lets close this one to.