Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/content/docs/script/learn-slua/from-lsl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
```
</Fragment>
Expand All @@ -69,7 +69,7 @@ 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 uuid: string = "..." -- keys are strings
local k: uuid = uuid("...")
local items: {number} = {1, 2, 3} -- tables, not lists
```
</Fragment>
Expand All @@ -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.
</Aside>

#### Typecasting
In many cases, luau does typecasting automatically. Here's how to do it explicitly:
<CodeComparison>
<Fragment slot="lsl">
```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"]
```
</Fragment>
<Fragment slot="slua">
```luau
(math.modf("-4.4")) -- extra parentheses are necessary
tonumber("25.5")
tostring(99.9)
tovector("<10, 20, 30>")
toquaternion("<0, 0, 0, 1>")
uuid("700843d3-0d15-c427-81ab-e9c8a0dcdb1e")
{"hello"} -- table, not list
```
</Fragment>
</CodeComparison>

### Operators

| Operation | LSL | SLua | Notes |
Expand Down