aboutsummaryrefslogtreecommitdiff
path: root/llthreads2/test/utils.lua
diff options
context:
space:
mode:
authorAlexey Melnichuk <mimir@newmail.ru>2014-02-11 17:32:59 +0400
committerAlexey Melnichuk <mimir@newmail.ru>2014-02-11 17:34:14 +0400
commitd13929706a3b45bd64e0a87e0afc3d45625e888d (patch)
treed1c846805f127736d1dafb3b3094eaf78d032859 /llthreads2/test/utils.lua
parent46ed59584e5407c49a02f1ea6bede6487259a92e (diff)
downloadlua-llthreads2-d13929706a3b45bd64e0a87e0afc3d45625e888d.tar.gz
lua-llthreads2-d13929706a3b45bd64e0a87e0afc3d45625e888d.tar.bz2
lua-llthreads2-d13929706a3b45bd64e0a87e0afc3d45625e888d.zip
Init LuaDist for llthreads2 module.
Diffstat (limited to '')
-rw-r--r--llthreads2/test/utils.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/llthreads2/test/utils.lua b/llthreads2/test/utils.lua
new file mode 100644
index 0000000..d9b5fe5
--- /dev/null
+++ b/llthreads2/test/utils.lua
@@ -0,0 +1,63 @@
1local lua_version_t
2local function lua_version()
3 if not lua_version_t then
4 local version = rawget(_G,"_VERSION")
5 local maj,min = version:match("^Lua (%d+)%.(%d+)$")
6 if maj then lua_version_t = {tonumber(maj),tonumber(min)}
7 elseif not math.mod then lua_version_t = {5,2}
8 elseif table.pack and not pack then lua_version_t = {5,2}
9 else lua_version_t = {5,2} end
10 end
11 return lua_version_t[1], lua_version_t[2]
12end
13
14local LUA_MAJOR, LUA_MINOR = lua_version()
15local IS_LUA_51 = (LUA_MAJOR == 5) and (LUA_MINOR == 1)
16local IS_LUA_52 = (LUA_MAJOR == 5) and (LUA_MINOR == 2)
17
18local LUA_INIT = "LUA_INIT"
19local LUA_INIT_VER
20if not IS_LUA_51 then
21 LUA_INIT_VER = LUA_INIT .. "_" .. LUA_MAJOR .. "_" .. LUA_MINOR
22end
23
24LUA_INIT = LUA_INIT_VER and os.getenv( LUA_INIT_VER ) or os.getenv( LUA_INIT ) or ""
25
26LUA_INIT = [[do
27 local lua_init = ]] .. ("%q"):format(LUA_INIT) .. [[
28 if lua_init and #lua_init > 0 then
29 if lua_init:sub(1,1) == '@' then
30 dofile(lua_init:sub(2))
31 else
32 assert((loadstring or load)(lua_init))()
33 end
34 end
35end;]]
36
37local sleep
38local status, socket = pcall(require,"socket")
39if status then
40 sleep = function(secs)
41 return socket.sleep(secs)
42 end
43end
44
45if not sleep then
46 local status, ztimer = pcall(require, "lzmq.timer")
47 if status then
48 sleep = function(secs)
49 ztimer.sleep(secs * 1000)
50 end
51 end
52end
53
54if not sleep then
55 sleep = function(secs)
56 os.execute("sleep " .. tonumber(secs))
57 end
58end
59
60return {
61 thread_init = LUA_INIT,
62 sleep = sleep,
63}