Skip to content

Feature request: bitwise operators & | ~ << >> (Lua 5.3+) #336

Description

@timkrueger1993-lab

Summary

The bitwise operators introduced in Lua 5.3 (&, |, ~ binary xor and unary not, <<, >>) are rejected by the parser:

var state = LuaState.Create();
state.Load("local a = 5 & 3", "chunk");  // chunk:1: unexpected symbol near '&'
state.Load("local a = 5 | 3", "chunk");  // chunk:1: unexpected symbol near '|'
state.Load("local a = 5 ~ 3", "chunk");  // chunk:1: unexpected symbol near '~'
state.Load("local a = 1 << 4", "chunk"); // chunk:1: unexpected symbol near <

Reproduced on 0.5.5 and 0.5.6.

As with the floor-division request, the README states Lua 5.2, so this is a feature request and effectively a concrete sub-item of #25 (Lua 5.3/5.4 support). The bitwise library (#17) covers the functional side; the operators are the remaining syntax-level gap for scripts written against the Lua 5.3/5.4 reference.

Context

We embed LuaCSharp in a server runtime (Limes) whose application authors write against the Lua 5.4 manual. Together with // (filed separately) these operators are the only 5.4 syntax gaps we have hit in practice — closing them would let 5.4-targeted scripts load unchanged even while the semantics stay 5.2 elsewhere. Happy to test prereleases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions