From ac9cfc9f31bcc0c6d9d62bbf099ec22956da6c11 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Sat, 20 Dec 2025 16:27:58 -0800 Subject: [PATCH 1/5] Add Bitwise Operators --- src/content/docs/script/learn-slua/from-lsl.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/content/docs/script/learn-slua/from-lsl.mdx b/src/content/docs/script/learn-slua/from-lsl.mdx index 95b27f7..89c8d5f 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -93,6 +93,12 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Power | `llPow(2, 3)` | `2 ^ 3` | Native operator | | Integer division | `7 / 4` → `1` | `7 // 4` → `1` | Use `//` not `/` | | String length | `llStringLength(s)` | `#s` | Native operator | +| Bitwise AND | `llGetAgentInfo(id) & AGENT_TYPING` | `bit32.band(ll.GetAgentInfo(id), AGENT_TYPING)` | No `&` operator | +| Bitwise OR | `PASSIVE | SCRIPTED` | `bit32.bor(PASSIVE | SCRIPTED)` | No `|` operator | +| Bitwise NOT | `~0` | `bit32.bnot(0)` | No `~` operator | +| Bitwise eXclusive OR | `6 ^ 3` | `bit32.bxor(6, 3)` | `^` means Power instead | +| Bitwise Shift Left | `1 << 2` | `bit32.arshift(1, 2)` | No `<<` operator | +| Bitwise Shift Right | `0x80000000 >> 2` | `bit32.arshift(0x80000000, 2)` | No `>>` operator | ### Control Flow From eb69c06530763446e33fd03702c66516f632a687 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Wed, 7 Jan 2026 14:37:50 -0800 Subject: [PATCH 2/5] change bit32.band to bit32.btest. It's more commonly correct --- 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 89c8d5f..635536c 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -93,7 +93,7 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Power | `llPow(2, 3)` | `2 ^ 3` | Native operator | | Integer division | `7 / 4` → `1` | `7 // 4` → `1` | Use `//` not `/` | | String length | `llStringLength(s)` | `#s` | Native operator | -| Bitwise AND | `llGetAgentInfo(id) & AGENT_TYPING` | `bit32.band(ll.GetAgentInfo(id), AGENT_TYPING)` | No `&` operator | +| Bitwise AND | `llGetAgentInfo(id) & AGENT_TYPING` | `bit32.btest(ll.GetAgentInfo(id), AGENT_TYPING)` | No `&` operator | | Bitwise OR | `PASSIVE | SCRIPTED` | `bit32.bor(PASSIVE | SCRIPTED)` | No `|` operator | | Bitwise NOT | `~0` | `bit32.bnot(0)` | No `~` operator | | Bitwise eXclusive OR | `6 ^ 3` | `bit32.bxor(6, 3)` | `^` means Power instead | From 64f29f5e33559640f1765e5551d5382899616835 Mon Sep 17 00:00:00 2001 From: Tapple Gao Date: Wed, 7 Jan 2026 16:21:09 -0800 Subject: [PATCH 3/5] typo in lshift --- 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 635536c..064b64c 100644 --- a/src/content/docs/script/learn-slua/from-lsl.mdx +++ b/src/content/docs/script/learn-slua/from-lsl.mdx @@ -97,7 +97,7 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Bitwise OR | `PASSIVE | SCRIPTED` | `bit32.bor(PASSIVE | SCRIPTED)` | No `|` operator | | Bitwise NOT | `~0` | `bit32.bnot(0)` | No `~` operator | | Bitwise eXclusive OR | `6 ^ 3` | `bit32.bxor(6, 3)` | `^` means Power instead | -| Bitwise Shift Left | `1 << 2` | `bit32.arshift(1, 2)` | No `<<` operator | +| Bitwise Shift Left | `1 << 2` | `bit32.lshift(1, 2)` | No `<<` operator | | Bitwise Shift Right | `0x80000000 >> 2` | `bit32.arshift(0x80000000, 2)` | No `>>` operator | ### Control Flow From 8cdd7ba5eb4738ce230c71e7e960e0d5417db8ec Mon Sep 17 00:00:00 2001 From: tapple Date: Sun, 10 May 2026 07:18:37 -0700 Subject: [PATCH 4/5] Fix review comments --- .../docs/script/learn-lua/from-lsl.mdx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/content/docs/script/learn-lua/from-lsl.mdx b/src/content/docs/script/learn-lua/from-lsl.mdx index eb2ff53..69ca445 100644 --- a/src/content/docs/script/learn-lua/from-lsl.mdx +++ b/src/content/docs/script/learn-lua/from-lsl.mdx @@ -83,7 +83,7 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Operation | LSL | Lua | Notes | |-----------|-----|------|-------| -| Not equal | `!=` | `~=` | Different operator | +| Not equal | `!=` | `~=` | **Different operator** | | Logical AND | `&&` | `and` | Word, not symbol | | Logical OR | `\|\|` | `or` | Word, not symbol | | Logical NOT | `!` | `not` | Word, not symbol | @@ -93,12 +93,19 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Power | `llPow(2, 3)` | `2 ^ 3` | Native operator | | Integer division | `7 / 4` → `1` | `7 // 4` → `1` | Use `//` not `/` | | String length | `llStringLength(s)` | `#s` | Native operator | -| Bitwise AND | `llGetAgentInfo(id) & AGENT_TYPING` | `bit32.btest(ll.GetAgentInfo(id), AGENT_TYPING)` | No `&` operator | -| Bitwise OR | `PASSIVE | SCRIPTED` | `bit32.bor(PASSIVE | SCRIPTED)` | No `|` operator | -| Bitwise NOT | `~0` | `bit32.bnot(0)` | No `~` operator | -| Bitwise eXclusive OR | `6 ^ 3` | `bit32.bxor(6, 3)` | `^` means Power instead | -| Bitwise Shift Left | `1 << 2` | `bit32.lshift(1, 2)` | No `<<` operator | -| Bitwise Shift Right | `0x80000000 >> 2` | `bit32.arshift(0x80000000, 2)` | No `>>` operator | +| Bitwise AND | `llGetAgentInfo(id) & AGENT_TYPING` | `bit32.btest(ll.GetAgentInfo(id), AGENT_TYPING)` | No `&` operator [(1)](#band) | +| Bitwise OR | `PASSIVE \| SCRIPTED` | `bit32.bor(PASSIVE, SCRIPTED)` | No `\|` operator | +| Bitwise NOT | `~0` | `bit32.bnot(0)` | No `~` operator [(2)](#s32) | +| Bitwise eXclusive OR | `6 ^ 3` | `bit32.bxor(6, 3)` | `^` means Power instead [(2)](#s32) | +| Bitwise Shift Left | `1 << 2` | `bit32.lshift(1, 2)` | No `<<` operator [(2)](#s32) | +| Bitwise Shift Right | `0x80000000 >> 2` | `bit32.arshift(0x80000000, 2)` | No `>>` operator [(2)](#s32) | + +Notes: +1. `bit32.btest` returns a boolean; `bit32.band` returns an integer. + Integers (`bit32.band`) don't work inside `if` statements, unlike LSL. Use whichever is most appropriate. +2. Hexadecimal numbers `0x8000000` and above are positive in Lua, but negative in LSL, + due to different number formats (signed 32-bit int vs 64-bit float). Use `bit32.s32` to wrap large numbers + down to the 32-bit signed integer range for LSL compatability. ### Control Flow From e333a7bc8605d41007446c949bafd10ae36974b3 Mon Sep 17 00:00:00 2001 From: tapple Date: Sun, 10 May 2026 14:20:43 -0700 Subject: [PATCH 5/5] more clarification about `bit32.band` --- src/content/docs/script/learn-lua/from-lsl.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/script/learn-lua/from-lsl.mdx b/src/content/docs/script/learn-lua/from-lsl.mdx index 69ca445..2ad0239 100644 --- a/src/content/docs/script/learn-lua/from-lsl.mdx +++ b/src/content/docs/script/learn-lua/from-lsl.mdx @@ -101,7 +101,7 @@ local items: {number} = {1, 2, 3} -- tables, not lists | Bitwise Shift Right | `0x80000000 >> 2` | `bit32.arshift(0x80000000, 2)` | No `>>` operator [(2)](#s32) | Notes: -1. `bit32.btest` returns a boolean; `bit32.band` returns an integer. +1. `bit32.btest` returns a boolean; `bit32.band` returns an integer. Both match the behavior of LSL `&`. Integers (`bit32.band`) don't work inside `if` statements, unlike LSL. Use whichever is most appropriate. 2. Hexadecimal numbers `0x8000000` and above are positive in Lua, but negative in LSL, due to different number formats (signed 32-bit int vs 64-bit float). Use `bit32.s32` to wrap large numbers