diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-25 15:49:29 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-25 15:50:51 -0800 |
| commit | a1b559a3a269bbee1ae9a33061b08a868ea52f5c (patch) | |
| tree | 51f2368c6542efe47dd2a4007ba92e22650236b9 /lib/core/operators.nom | |
| parent | 1713a0e38f12f8ed167575ac5a84a0eb8dd59a44 (diff) | |
Added metatables for bool, number, function, coroutine. Added
run-time check to make sure precompiled code used the same version of
Lua. Methods can now be used in (* compiles to *), etc.
Diffstat (limited to 'lib/core/operators.nom')
| -rw-r--r-- | lib/core/operators.nom | 26 |
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))" |
