@@ -7,12 +7,27 @@ Test helpers.
77
88-- The function determines a Lua version.
99local function lua_version ()
10+ local major , minor = _VERSION :match (" ([%d]+)%.(%d+)" )
11+ local version = {
12+ major = tonumber (major ),
13+ minor = tonumber (minor ),
14+ }
1015 local is_luajit , _ = pcall (require , " jit" )
11- if is_luajit then
12- return " LuaJIT"
16+ local lua_name = is_luajit and " LuaJIT" or " PUC Rio Lua"
17+ return lua_name , version
18+ end
19+
20+ local function version_ge (version1 , version2 )
21+ if version1 .major ~= version2 .major then
22+ return version1 .major > version2 .major
23+ else
24+ return version1 .minor > version2 .minor
1325 end
26+ end
1427
15- return _VERSION
28+ local function lua_current_version_ge_than (major , minor )
29+ local _ , current_version = lua_version ()
30+ return version_ge (current_version , { major = major , minor = minor })
1631end
1732
1833-- By default `lua_Integer` is ptrdiff_t in Lua 5.1 and Lua 5.2
@@ -56,9 +71,21 @@ local function bitwise_op(op_name)
5671 end
5772end
5873
74+ local function math_pow (x , y )
75+ return x ^ y
76+ end
77+
78+ local function approx_equal (a , b , epsilon )
79+ local abs = math.abs
80+ return abs (a - b ) <= ((abs (a ) < abs (b ) and abs (b ) or abs (a )) * epsilon )
81+ end
82+
5983return {
60- lua_version = lua_version ,
84+ approx_equal = approx_equal ,
6185 bitwise_op = bitwise_op ,
86+ lua_version = lua_version ,
87+ lua_current_version_ge_than = lua_current_version_ge_than ,
88+ math_pow = math_pow ,
6289 MAX_INT64 = MAX_INT64 ,
6390 MIN_INT64 = MIN_INT64 ,
6491 MAX_INT = MAX_INT ,
0 commit comments