diff options
author | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-11 17:32:59 +0400 |
---|---|---|
committer | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-11 17:34:14 +0400 |
commit | d13929706a3b45bd64e0a87e0afc3d45625e888d (patch) | |
tree | d1c846805f127736d1dafb3b3094eaf78d032859 /llthreads2/test/utils.lua | |
parent | 46ed59584e5407c49a02f1ea6bede6487259a92e (diff) | |
download | lua-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.lua | 63 |
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 @@ | |||
1 | local lua_version_t | ||
2 | local 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] | ||
12 | end | ||
13 | |||
14 | local LUA_MAJOR, LUA_MINOR = lua_version() | ||
15 | local IS_LUA_51 = (LUA_MAJOR == 5) and (LUA_MINOR == 1) | ||
16 | local IS_LUA_52 = (LUA_MAJOR == 5) and (LUA_MINOR == 2) | ||
17 | |||
18 | local LUA_INIT = "LUA_INIT" | ||
19 | local LUA_INIT_VER | ||
20 | if not IS_LUA_51 then | ||
21 | LUA_INIT_VER = LUA_INIT .. "_" .. LUA_MAJOR .. "_" .. LUA_MINOR | ||
22 | end | ||
23 | |||
24 | LUA_INIT = LUA_INIT_VER and os.getenv( LUA_INIT_VER ) or os.getenv( LUA_INIT ) or "" | ||
25 | |||
26 | LUA_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 | ||
35 | end;]] | ||
36 | |||
37 | local sleep | ||
38 | local status, socket = pcall(require,"socket") | ||
39 | if status then | ||
40 | sleep = function(secs) | ||
41 | return socket.sleep(secs) | ||
42 | end | ||
43 | end | ||
44 | |||
45 | if 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 | ||
52 | end | ||
53 | |||
54 | if not sleep then | ||
55 | sleep = function(secs) | ||
56 | os.execute("sleep " .. tonumber(secs)) | ||
57 | end | ||
58 | end | ||
59 | |||
60 | return { | ||
61 | thread_init = LUA_INIT, | ||
62 | sleep = sleep, | ||
63 | } | ||