Skip to content

Commit 502a244

Browse files
committed
tests/capi: support bitop in luaL_loadbuffer_proto
The `bit32` library has been deprecated in PUC Rio Lua 5.3 [1]. Missed bitwise functions have been replaced by appropriate bitwise operations [2]. The patch adds support of bitwise operations to the test `luaL_loadbuffer_proto`. 1. https://www.lua.org/manual/5.3/manual.html#8.2 2. https://www.lua.org/manual/5.3/manual.html#3.4.2
1 parent 8964864 commit 502a244

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/capi/luaL_loadbuffer_proto/lua_grammar.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ message BinaryOperator {
386386

387387
/* Arithmetic operators (5.3+). */
388388
uint32 idiv = 16;
389+
390+
/* Bitwise operators (5.3+). */
391+
uint32 band = 17;
392+
uint32 bor = 18;
393+
uint32 bxor = 19;
394+
uint32 shl = 20;
395+
uint32 shr = 21;
389396
}
390397
}
391398

@@ -395,6 +402,9 @@ message UnaryOperator {
395402
uint32 negate = 1;
396403
uint32 not = 2;
397404
uint32 length = 3;
405+
406+
/* Bitwise operators (5.3+). */
407+
uint32 bnot = 4;
398408
}
399409
}
400410

tests/capi/luaL_loadbuffer_proto/preamble.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ local __idiv = load([[
7676
local v1, v2 = ...
7777
return always_number(v1) // always_number(v2)
7878
]])
79+
local __band = load([[
80+
local v1, v2 = ...
81+
return always_number(v1) & always_number(v2)
82+
]])
83+
local __bor = load([[
84+
local v1, v2 = ...
85+
return always_number(v1) | always_number(v2)
86+
]])
87+
local __bxor = load([[
88+
local v1, v2 = ...
89+
return always_number(v1) ~ always_number(v2)
90+
]])
91+
local __bnot = load([[
92+
local v = ...
93+
return ~always_number(v)
94+
]])
95+
local __shl = load([[
96+
local v1, v2 = ...
97+
return always_number(v1) << always_number(v2)
98+
]])
99+
local __shr = load([[
100+
local v1, v2 = ...
101+
return always_number(v1) >> always_number(v2)
102+
]])
79103

80104
debug.setmetatable('string', {
81105
__add = __add,
@@ -89,6 +113,12 @@ debug.setmetatable('string', {
89113
__pow = __pow,
90114
__sub = __sub,
91115
__unm = __unm,
116+
__band = __band,
117+
__bor = __bor,
118+
__bxor = __bxor,
119+
__bnot = __bnot,
120+
__shl = __shl,
121+
__shr = __shr,
92122
})
93123
debug.setmetatable(0, {
94124
__add = __add,

tests/capi/luaL_loadbuffer_proto/serializer.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,19 @@ PROTO_TOSTRING(BinaryOperator, op)
11851185
return "and";
11861186
case BinopType::kOr:
11871187
return "or";
1188+
1189+
#if LUA_VERSION_NUM >= 503
1190+
case BinopType::kBAnd:
1191+
return "&";
1192+
case BinopType::kBOr:
1193+
return "|";
1194+
case BinopType::kBXor:
1195+
return "~";
1196+
case BinopType::kBShl:
1197+
return "<<";
1198+
case BinopType::kBShr:
1199+
return ">>";
1200+
#endif
11881201
default:
11891202
/* Works in most cases. */
11901203
return "==";
@@ -1201,6 +1214,10 @@ PROTO_TOSTRING(UnaryOperator, op)
12011214
return "not ";
12021215
case UnaryopType::kLength:
12031216
return "#";
1217+
#if LUA_VERSION_NUM >= 503
1218+
case UnaryopType::kBNot:
1219+
return "~";
1220+
#endif
12041221
default:
12051222
/* Works in most cases. */
12061223
return "not ";

0 commit comments

Comments
 (0)