@@ -18,10 +18,6 @@ local _qualifiers_cache = {
18
18
-- },
19
19
}
20
20
21
- local function is_tarantool ()
22
- return rawget (_G , ' _TARANTOOL' ) ~= nil
23
- end
24
-
25
21
--- Check that string (or substring) starts with given string
26
22
-- Optionally restricting the matching with the given offsets
27
23
-- @function startswith
@@ -297,21 +293,35 @@ function checkers.int64(arg)
297
293
return false
298
294
end
299
295
300
- local has_decimal , decimal = pcall ( require , ' decimal ' )
301
- if has_decimal and decimal . is_decimal then
302
- checkers .decimal = decimal . is_decimal
296
+ local has_box = rawget ( _G , ' box ' ) ~= nil
297
+ if has_box and box . tuple ~= nil then
298
+ checkers .tuple = box . tuple . is
303
299
end
304
300
305
- if is_tarantool () == true then
306
- checkers .tuple = box .tuple .is
301
+ local has_decimal , decimal = pcall (require , ' decimal' )
302
+ if has_decimal then
303
+ -- There is a decimal.is_decimal check since 2.4, but we
304
+ -- reimplement it here to support older versions which have decimal.
305
+ local cdata_t = ffi .typeof (decimal .new (0 ))
306
+ checkers .decimal = function (arg )
307
+ return ffi .istype (cdata_t , arg )
308
+ end
309
+ end
307
310
308
- -- https://github.com/tarantool/tarantool/blob/7682d34162be34648172d91008e9185301bce8f6/src/lua/uuid.lua#L29
309
- local uuid_t = ffi .typeof (' struct tt_uuid' )
310
- function checkers .uuid (arg )
311
- return ffi .istype (uuid_t , arg )
311
+ local function add_ffi_type_checker (checks_type , c_type )
312
+ local has_cdata_t , cdata_t = pcall (ffi .typeof , c_type )
313
+ if has_cdata_t then
314
+ checkers [checks_type ] = function (arg )
315
+ return ffi .istype (cdata_t , arg )
316
+ end
312
317
end
313
318
end
314
319
320
+ -- There is a uuid.is_uuid check since 2.6.1, but we
321
+ -- reimplement it here to support older versions which have uuid.
322
+ -- https://github.com/tarantool/tarantool/blob/7682d34162be34648172d91008e9185301bce8f6/src/lua/uuid.lua#L29
323
+ add_ffi_type_checker (' uuid' , ' struct tt_uuid' )
324
+
315
325
function checkers .uuid_str (arg )
316
326
if type (arg ) == ' string' and # arg == 36 then
317
327
local match = arg :match (
0 commit comments