Autocast or not autocast, that is the question
Rohacan Hirons
I’m rewriting some of my scripts in SLUA and noticed that strings can sometimes be auto-cast to numbers.
Then if in an old script, I read numeric values from a CSV I won’t explicitly convert them back to integer / number before to use them. The result is that it sometimes works and sometimes doesn’t, depending on the function. (And yes, I know we have JSON_ARRAY that works very well and I rarely use a CSV for numbers) With LSL/Mono in any case we had to cast to integer with llList2Inger(l, x) but with SLUA we can simply get the value from the table:
local data: {} = mess:split(",")
ll.SetColor(vector(0, 1, 0), data[1]) -- data[1] is a string, but this work.
But ll.SetLinkPrimitiveParamsFast() fails with a type error
I’m wondering if this is because, in the second case, the value is inside a table (parameter list), and auto-casting is not applied the same way.
It would be nice if the behavior was consistent: either always auto-cast, or never auto-cast.
-- set white color on all sides
ll.SetColor(vector(1, 1, 1), ALL_SIDES)
local n: string = "0"
-- set green color, "n" is auto-cast to integer
ll.SetColor(vector(0, 1, 0), n)
-- set red color, "n" is not auto-cast:
-- arg #1 (face number) integer expected but string given.
ll.SetLinkPrimitiveParamsFast(LINK_THIS, {PRIM_COLOR, n, vector(1, 0, 0), 1})
Is this expected behavior?
If so, what’s the exact rule for when auto-casting does / doesn’t happen?
Log In