aboutsummaryrefslogtreecommitdiff
path: root/lib/core/operators.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/operators.nom')
-rw-r--r--lib/core/operators.nom26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/core/operators.nom b/lib/core/operators.nom
index c2e6b57..4bdb5bc 100644
--- a/lib/core/operators.nom
+++ b/lib/core/operators.nom
@@ -159,6 +159,18 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Bitwise Operators
+# These can break if running the precompiled code from another Lua version:
+lua> ("
+ if \(at compilation $(LUA VERSION)) ~= \$(LUA VERSION) then
+ \(
+ fail ("
+ This code was precompiled with \(at compilation $(LUA VERSION)), but it is being run with \$(LUA VERSION)\
+ ... This will cause problems with bitwise operations.
+ ")
+ )
+ end
+")
+
# TODO: implement OR, XOR, AND for multiple operands?
test:
assume ((~ (~ 5)) == 5)
@@ -170,22 +182,22 @@ test:
# Lua 5.3 introduced bit operators like | and &. Use them when possible, otherwise
fall back to bit.bor(), bit.band(), etc.
-lua> "if \((is jit) or ((Lua version) == "Lua 5.2")) then"
-[NOT $, ~ $] all compile to "bit.bnot(\($ as lua expr))"
+lua> "if \((is jit) or ($(LUA API) == "Lua 5.2")) then"
+[NOT $, ~ $] all compile to "Bit.bnot(\($ as lua expr))"
[$x OR $y, $x | $y] all compile to
- "bit.bor(\($x as lua expr), \($y as lua expr))"
+ "Bit.bor(\($x as lua expr), \($y as lua expr))"
[$x XOR $y, $x ~ $y] all compile to
- "bit.bxor(\($x as lua expr), \($y as lua expr))"
+ "Bit.bxor(\($x as lua expr), \($y as lua expr))"
[$x AND $y, $x & $y] all compile to
- "bit.band(\($x as lua expr), \($y as lua expr))"
+ "Bit.band(\($x as lua expr), \($y as lua expr))"
[$x LSHIFT $shift, $x << $shift] all compile to
- "bit.lshift(\($x as lua expr), \($shift as lua expr))"
+ "Bit.lshift(\($x as lua expr), \($shift as lua expr))"
[$x RSHIFT $shift, $x >> $shift] all compile to
- "bit.rshift(\($x as lua expr), \($shift as lua expr))"
+ "Bit.rshift(\($x as lua expr), \($shift as lua expr))"
lua> "else"
[NOT $, ~ $] all compile to "~(\($ as lua expr))"