Skip to content

Commit ce9d849

Browse files
committed
tests/capi: support floor division operation
The PUC Rio Lua 5.3 has introduced a floor division (//) operation. It is a division that rounds the quotient towards minus infinity, that is, the floor of the division of its operands. The patch adds aforementioned operation to a protobuf schema, serializer and preamble.
1 parent a0d8491 commit ce9d849

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

tests/capi/luaL_loadbuffer_proto/lua_grammar.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ message BinaryOperator {
383383
uint32 notEqual = 13;
384384
uint32 and = 14;
385385
uint32 or = 15;
386+
387+
/* Arithmetic operators (5.3+). */
388+
uint32 idiv = 16;
386389
}
387390
}
388391

tests/capi/luaL_loadbuffer_proto/preamble.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ end
7070
local __unm = function(v)
7171
return - always_number(v)
7272
end
73+
local __idiv = function(v1, v2)
74+
return always_number(v1) // always_number(v2)
75+
end
7376

7477
debug.setmetatable('string', {
7578
__add = __add,
7679
__call = __call,
7780
__div = __div,
81+
__idiv = __idiv,
7882
__index = __index,
7983
__mod = __mod,
8084
__mul = __mul,
@@ -88,6 +92,7 @@ debug.setmetatable(0, {
8892
__call = __call,
8993
__concat = __concat,
9094
__div = __div,
95+
__idiv = __idiv,
9196
__index = __index,
9297
__len = __len,
9398
__newindex = __newindex,
@@ -97,6 +102,7 @@ debug.setmetatable(nil, {
97102
__call = __call,
98103
__concat = __concat,
99104
__div = __div,
105+
__idiv = __idiv,
100106
__index = __index,
101107
__le = __le,
102108
__len = __len,
@@ -112,6 +118,7 @@ debug.setmetatable(function() end, {
112118
__add = __add,
113119
__concat = __concat,
114120
__div = __div,
121+
__idiv = __idiv,
115122
__index = __index,
116123
__le = __le,
117124
__len = __len,
@@ -128,6 +135,7 @@ debug.setmetatable(true, {
128135
__call = __call,
129136
__concat = __concat,
130137
__div = __div,
138+
__idiv = __idiv,
131139
__index = __index,
132140
__le = __le,
133141
__len = __len,
@@ -144,6 +152,7 @@ local table_mt = {
144152
__call = __call,
145153
__concat = __concat,
146154
__div = __div,
155+
__idiv = __idiv,
147156
__le = __le,
148157
__len = __len,
149158
__lt = __lt,

tests/capi/luaL_loadbuffer_proto/serializer.cc

Lines changed: 4 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:

0 commit comments

Comments
 (0)