2 -- Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 -- This program is free software: you can redistribute it and/or
7 -- modify it under the terms of the GNU Affero General Public
8 -- License as published by the Free Software Foundation, either
9 -- version 3 of the License, or (at your option) any later version.
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU Affero General Public License for more details.
16 -- You should have received a copy of the GNU Affero General
17 -- Public License along with this program. If not, see
18 -- <http://www.gnu.org/licenses/>.
22 -- Checks the availability of a Lua module.
25 -- * Exits with either 0 (success) or 1 (failure)
26 -- * Informative messages are printed to stdout
29 local EXIT_SUCCESS
= 0
30 local EXIT_FAILURE
= 1
32 local function _chk_input()
34 print(string.format('Usage: %s <modname> <reqver>', arg
[0]))
35 print(' Exit status: 0=success, 1=failure')
36 print(string.format('Example: %s lxp 1.2.0', arg
[0]))
41 local function _chk_form(a
,b
,c
,s
)
42 if not a
or not b
or not c
then
43 print(string.format('error: %s must be in the x.y.z form', s
))
48 local function _to_n(a
,b
,c
)
49 return tonumber(string.format('%d%d%d',
50 tonumber(a
), tonumber(b
), tonumber(c
)))
53 local function _chk_mod(m
,r
)
54 local p
= '(%d+).(%d+).(%d+)'
56 local ra
,rb
,rc
= r
:match(p
)
57 _chk_form(ra
,rb
,rc
,'reqver')
61 local fa
,fb
,fc
= M
._VERSION
:match(p
)
62 _chk_form(fa
,fb
,fc
,'modver')
64 print('require', ra
,rb
,rc
)
65 print('found', fa
,fb
,fc
)
67 return (_to_n(fa
,fb
,fc
) >= _to_n(ra
,rb
,rc
))
68 and EXIT_SUCCESS
or EXIT_FAILURE
72 os
.exit(_chk_mod(arg
[1], arg
[2]))