Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extra/errors.awk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions tests/capi/luaL_loadbuffer_proto/lua_grammar.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -392,6 +402,9 @@ message UnaryOperator {
uint32 negate = 1;
uint32 not = 2;
uint32 length = 3;

/* Bitwise operators (5.3+). */
uint32 bnot = 4;
}
}

Expand Down
42 changes: 42 additions & 0 deletions tests/capi/luaL_loadbuffer_proto/preamble.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,24 +72,60 @@ 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,
__newindex = __newindex,
__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,
Expand All @@ -97,6 +135,7 @@ debug.setmetatable(nil, {
__call = __call,
__concat = __concat,
__div = __div,
__idiv = __idiv,
__index = __index,
__le = __le,
__len = __len,
Expand All @@ -112,6 +151,7 @@ debug.setmetatable(function() end, {
__add = __add,
__concat = __concat,
__div = __div,
__idiv = __idiv,
__index = __index,
__le = __le,
__len = __len,
Expand All @@ -128,6 +168,7 @@ debug.setmetatable(true, {
__call = __call,
__concat = __concat,
__div = __div,
__idiv = __idiv,
__index = __index,
__le = __le,
__len = __len,
Expand All @@ -144,6 +185,7 @@ local table_mt = {
__call = __call,
__concat = __concat,
__div = __div,
__idiv = __idiv,
__le = __le,
__len = __len,
__lt = __lt,
Expand Down
21 changes: 21 additions & 0 deletions tests/capi/luaL_loadbuffer_proto/serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 "==";
Expand All @@ -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 ";
Expand Down