From 71f1dae8463b2b7f27e289e8a3258d6778f4581a Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Sat, 20 Dec 2025 13:06:30 -0800 Subject: [PATCH 1/5] Added a section about casting --- .../docs/script/learn-slua/from-lsl.mdx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index 95b27f7..cf94dfc 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -68,7 +68,7 @@ local health: number = 100 local damage: number = 25.5 local name: string = "Alice" local pos: vector = vector(10, 20, 30) -local rot: quaternion = quaternion(0, 0, 0, 1) +local rot: quaternion = quaternion(0, 0, 0, 1) -- also local rot: rotation = rotation(0, 0, 0, 1) local uuid: string = "..." -- keys are strings local items: {number} = {1, 2, 3} -- tables, not lists ``` @@ -79,6 +79,33 @@ local items: {number} = {1, 2, 3} -- tables, not lists **Type annotations recommended!** While optional, they catch errors before runtime and make code self-documenting. +#### Casting +In many cases, luau does casting automatically. Here's how to do it manually: + + +```lsl +(integer)"-4.4"; +(float)"25.5"; +(string)99.9; +(vector)"<10, 20, 30>"; +(rotation)"<0, 0, 0, 1>"; +(key)"700843d3-0d15-c427-81ab-e9c8a0dcdb1e"; +(list)"hello"; // equivilant to ["hello"] +``` + + +```luau +(math.modf("-4.4")) -- extra parentheses are necessary to discard the second return value +tonumber("25.5") +tostring(99.9) +tovector("<10, 20, 30>") +torotation("<0, 0, 0, 1>") -- also toquaternion("<0, 0, 0, 1>") +"700843d3-0d15-c427-81ab-e9c8a0dcdb1e" -- keys are strings +{"hello"} -- table, not list +``` + + + ### Operators | Operation | LSL | SLua | Notes | From 528d973832f0e65d1c972deb6409249bdf9434c1 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Sat, 20 Dec 2025 16:47:22 -0800 Subject: [PATCH 2/5] Casting -> Typecasting --- src/content/docs/script/learn-slua/from-lsl.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index cf94dfc..53c59de 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -79,8 +79,8 @@ local items: {number} = {1, 2, 3} -- tables, not lists **Type annotations recommended!** While optional, they catch errors before runtime and make code self-documenting. -#### Casting -In many cases, luau does casting automatically. Here's how to do it manually: +#### Typecasting +In many cases, luau does typecasting automatically. Here's how to do it explicitly: ```lsl From 9147d4c20c9bb7b7e89b82a163d5c5fd83143e25 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Sat, 20 Dec 2025 23:23:54 -0800 Subject: [PATCH 3/5] noted that uuid and string are no longer interchangable --- src/content/docs/script/learn-slua/from-lsl.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index 53c59de..bab383e 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -57,7 +57,7 @@ float damage = 25.5; string name = "Alice"; vector pos = <10, 20, 30>; rotation rot = <0, 0, 0, 1>; -key uuid = "..."; +key k = "..."; list items = [1, 2, 3]; ``` @@ -68,8 +68,8 @@ local health: number = 100 local damage: number = 25.5 local name: string = "Alice" local pos: vector = vector(10, 20, 30) -local rot: quaternion = quaternion(0, 0, 0, 1) -- also local rot: rotation = rotation(0, 0, 0, 1) -local uuid: string = "..." -- keys are strings +local rot: quaternion = quaternion(0, 0, 0, 1) +local k: uuid = uuid("...") local items: {number} = {1, 2, 3} -- tables, not lists ``` @@ -95,12 +95,12 @@ In many cases, luau does typecasting automatically. Here's how to do it explicit ```luau -(math.modf("-4.4")) -- extra parentheses are necessary to discard the second return value +(math.modf("-4.4")) -- extra parentheses are necessary tonumber("25.5") tostring(99.9) tovector("<10, 20, 30>") -torotation("<0, 0, 0, 1>") -- also toquaternion("<0, 0, 0, 1>") -"700843d3-0d15-c427-81ab-e9c8a0dcdb1e" -- keys are strings +toquaternion("<0, 0, 0, 1>") +uuid("700843d3-0d15-c427-81ab-e9c8a0dcdb1e") {"hello"} -- table, not list ``` From 4da71c8ec083ed85e7f3f70c153ddea5e01ac5c2 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Wed, 7 Jan 2026 14:50:38 -0800 Subject: [PATCH 4/5] Clarify parentheses necessity in math.modf example --- src/content/docs/script/learn-slua/from-lsl.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index bab383e..39ba74e 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -95,7 +95,7 @@ In many cases, luau does typecasting automatically. Here's how to do it explicit ```luau -(math.modf("-4.4")) -- extra parentheses are necessary +(math.modf("-4.4")) -- extra parentheses sometimes necessary tonumber("25.5") tostring(99.9) tovector("<10, 20, 30>") From e8dbef34260a7a57a7aed591f6c9106c419085f7 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Wed, 7 Jan 2026 16:45:08 -0800 Subject: [PATCH 5/5] Add or expressions to convert nil to the LSL typecast value --- src/content/docs/script/learn-slua/from-lsl.mdx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index 39ba74e..8458122 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -95,16 +95,17 @@ In many cases, luau does typecasting automatically. Here's how to do it explicit ```luau -(math.modf("-4.4")) -- extra parentheses sometimes necessary -tonumber("25.5") +(math.modf(tonumber("-4.4") or 0)) -- extra parentheses sometimes necessary +tonumber("25.5") or 0 tostring(99.9) -tovector("<10, 20, 30>") -toquaternion("<0, 0, 0, 1>") -uuid("700843d3-0d15-c427-81ab-e9c8a0dcdb1e") +tovector("<10, 20, 30>") or ZERO_VECTOR +toquaternion("<0, 0, 0, 1>") or ZERO_ROTATION +uuid("700843d3-0d15-c427-81ab-e9c8a0dcdb1e") or NULL_KEY {"hello"} -- table, not list ``` +LSL and Lua typecasts return different results on invalid input: LSL returns "zero"; lua returns `nil`. The Lua examples include an `or` expressions that converts `nil` to what LSL typecast would have returned ### Operators