Skip to content

Commit 27ee562

Browse files
committed
tests/capi: support bitwise operations 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 in 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 a0d8491 commit 27ee562

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

tests/capi/luaL_loadbuffer_proto/lua_grammar.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ message BinaryOperator {
383383
uint32 notEqual = 13;
384384
uint32 and = 14;
385385
uint32 or = 15;
386+
387+
/* Arithmetic operators (5.3+). */
388+
uint32 idiv = 16;
389+
390+
/* Bitwise operators (5.3+). */
391+
uint32 bor = 17;
392+
uint32 band = 18;
393+
uint32 bxor = 19;
394+
uint32 bnot = 20;
395+
uint32 shl = 21;
396+
uint32 shr = 22;
386397
}
387398
}
388399

@@ -392,6 +403,9 @@ message UnaryOperator {
392403
uint32 negate = 1;
393404
uint32 not = 2;
394405
uint32 length = 3;
406+
407+
/* Bitwise operators (5.3+). */
408+
uint32 bnot = 4;
395409
}
396410
}
397411

tests/capi/luaL_loadbuffer_proto/preamble.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ end
7070
local __unm = function(v)
7171
return - always_number(v)
7272
end
73+
local __idiv = function(v1, v2)
74+
return
75+
end
76+
local __band = function(v1, v2)
77+
return
78+
end
79+
local __bor = function(v1, v2)
80+
return
81+
end
82+
local __bxor = function(v1, v2)
83+
return
84+
end
85+
local __bnot = function(v1, v2)
86+
return
87+
end
88+
local __shl = function(v1, v2)
89+
return
90+
end
91+
local __shr = function(v1, v2)
92+
return
93+
end
7394

7495
debug.setmetatable('string', {
7596
__add = __add,
@@ -82,6 +103,13 @@ debug.setmetatable('string', {
82103
__pow = __pow,
83104
__sub = __sub,
84105
__unm = __unm,
106+
__idiv = __idiv,
107+
__band = __band,
108+
__bor= __bor,
109+
__bxor = __bxor,
110+
__bnot = __bnot,
111+
__shl = __shl,
112+
__shr = __shr,
85113
})
86114
debug.setmetatable(0, {
87115
__add = __add,

tests/capi/luaL_loadbuffer_proto/serializer.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,10 @@ PROTO_TOSTRING(BinaryOperator, op)
11571157
return "*";
11581158
case BinopType::kDiv:
11591159
return "/";
1160+
#if LUA_VERSION_NUM >= 503
1161+
case BinopType::kIDiv:
1162+
return "//";
1163+
#endif
11601164
case BinopType::kExp:
11611165
return "^";
11621166
case BinopType::kMod:
@@ -1181,6 +1185,19 @@ PROTO_TOSTRING(BinaryOperator, op)
11811185
return "and";
11821186
case BinopType::kOr:
11831187
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
11841201
default:
11851202
/* Works in most cases. */
11861203
return "==";
@@ -1197,6 +1214,10 @@ PROTO_TOSTRING(UnaryOperator, op)
11971214
return "not ";
11981215
case UnaryopType::kLength:
11991216
return "#";
1217+
#if LUA_VERSION_NUM >= 503
1218+
case UnaryopType::kBNot:
1219+
return "~";
1220+
#endif
12001221
default:
12011222
/* Works in most cases. */
12021223
return "not ";

0 commit comments

Comments
 (0)