diff --git a/extra/errors.awk b/extra/errors.awk index 1ddffca7..3dc1faaf 100644 --- a/extra/errors.awk +++ b/extra/errors.awk @@ -34,6 +34,8 @@ BEGIN { matched = 0 err_pat["'for' step is zero"] = 0 err_pat["attempt to assign to const variable"] = 0 err_pat["got a non-closable value"] = 0 + err_pat["unfinished string near"] = 0 + err_pat["syntax error near"] = 0 } # String that function report_error() prints with every error message. diff --git a/tests/capi/luaL_loadbuffer_proto/lua_grammar.proto b/tests/capi/luaL_loadbuffer_proto/lua_grammar.proto index 6a4fbfad..c45d247f 100644 --- a/tests/capi/luaL_loadbuffer_proto/lua_grammar.proto +++ b/tests/capi/luaL_loadbuffer_proto/lua_grammar.proto @@ -383,6 +383,16 @@ message BinaryOperator { uint32 notEqual = 13; uint32 and = 14; uint32 or = 15; + + /* Arithmetic operators (5.3+). */ + uint32 idiv = 16; + + /* Bitwise operators (5.3+). */ + uint32 band = 17; + uint32 bor = 18; + uint32 bxor = 19; + uint32 shl = 20; + uint32 shr = 21; } } @@ -392,6 +402,9 @@ message UnaryOperator { uint32 negate = 1; uint32 not = 2; uint32 length = 3; + + /* Bitwise operators (5.3+). */ + uint32 bnot = 4; } } diff --git a/tests/capi/luaL_loadbuffer_proto/preamble.lua b/tests/capi/luaL_loadbuffer_proto/preamble.lua index 92b6b8bd..e41afe5d 100644 --- a/tests/capi/luaL_loadbuffer_proto/preamble.lua +++ b/tests/capi/luaL_loadbuffer_proto/preamble.lua @@ -8,6 +8,8 @@ local not_nan_and_nil = function(val) return (val ~= val or val == nil) and DEFAULT_NUMBER or val end +_G.always_number = always_number + local __add = function(v1, v2) return always_number(v1) + always_number(v2) end @@ -70,11 +72,40 @@ end local __unm = function(v) return - always_number(v) end +local __idiv = load([[ + local v1, v2 = ... + return always_number(v1) // always_number(v2) +]]) +local __band = load([[ + local v1, v2 = ... + return always_number(v1) & always_number(v2) +]]) +local __bor = load([[ + local v1, v2 = ... + return always_number(v1) | always_number(v2) +]]) +local __bxor = load([[ + local v1, v2 = ... + return always_number(v1) ~ always_number(v2) +]]) +local __bnot = load([[ + local v = ... + return ~always_number(v) +]]) +local __shl = load([[ + local v1, v2 = ... + return always_number(v1) << always_number(v2) +]]) +local __shr = load([[ + local v1, v2 = ... + return always_number(v1) >> always_number(v2) +]]) debug.setmetatable('string', { __add = __add, __call = __call, __div = __div, + __idiv = __idiv, __index = __index, __mod = __mod, __mul = __mul, @@ -82,12 +113,19 @@ debug.setmetatable('string', { __pow = __pow, __sub = __sub, __unm = __unm, + __band = __band, + __bor = __bor, + __bxor = __bxor, + __bnot = __bnot, + __shl = __shl, + __shr = __shr, }) debug.setmetatable(0, { __add = __add, __call = __call, __concat = __concat, __div = __div, + __idiv = __idiv, __index = __index, __len = __len, __newindex = __newindex, @@ -97,6 +135,7 @@ debug.setmetatable(nil, { __call = __call, __concat = __concat, __div = __div, + __idiv = __idiv, __index = __index, __le = __le, __len = __len, @@ -112,6 +151,7 @@ debug.setmetatable(function() end, { __add = __add, __concat = __concat, __div = __div, + __idiv = __idiv, __index = __index, __le = __le, __len = __len, @@ -128,6 +168,7 @@ debug.setmetatable(true, { __call = __call, __concat = __concat, __div = __div, + __idiv = __idiv, __index = __index, __le = __le, __len = __len, @@ -144,6 +185,7 @@ local table_mt = { __call = __call, __concat = __concat, __div = __div, + __idiv = __idiv, __le = __le, __len = __len, __lt = __lt, diff --git a/tests/capi/luaL_loadbuffer_proto/serializer.cc b/tests/capi/luaL_loadbuffer_proto/serializer.cc index 312b128f..ea951afd 100644 --- a/tests/capi/luaL_loadbuffer_proto/serializer.cc +++ b/tests/capi/luaL_loadbuffer_proto/serializer.cc @@ -1157,6 +1157,10 @@ PROTO_TOSTRING(BinaryOperator, op) return "*"; case BinopType::kDiv: return "/"; +#if LUA_VERSION_NUM >= 503 + case BinopType::kIDiv: + return "//"; +#endif case BinopType::kExp: return "^"; case BinopType::kMod: @@ -1181,6 +1185,19 @@ PROTO_TOSTRING(BinaryOperator, op) return "and"; case BinopType::kOr: return "or"; + +#if LUA_VERSION_NUM >= 503 + case BinopType::kBAnd: + return "&"; + case BinopType::kBOr: + return "|"; + case BinopType::kBXor: + return "~"; + case BinopType::kBShl: + return "<<"; + case BinopType::kBShr: + return ">>"; +#endif default: /* Works in most cases. */ return "=="; @@ -1197,6 +1214,10 @@ PROTO_TOSTRING(UnaryOperator, op) return "not "; case UnaryopType::kLength: return "#"; +#if LUA_VERSION_NUM >= 503 + case UnaryopType::kBNot: + return "~"; +#endif default: /* Works in most cases. */ return "not ";