From 78339241ad764f456dc664882b337b72d6b2f134 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Wed, 21 Nov 2012 11:16:43 +0200 Subject: [PATCH] Add chk_mod.lua This Lua script will check the availability of a Lua module. It will be used by configure(.ac). Signed-off-by: Toni Gundogdu --- Makefile.am | 2 +- chk_mod.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 chk_mod.lua diff --git a/Makefile.am b/Makefile.am index 73810ab..8da4db0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS=-I m4 -EXTRA_DIST= gen-ver.sh libquvi-scripts-0.9.pc.in VERSION +EXTRA_DIST= gen-ver.sh libquvi-scripts-0.9.pc.in VERSION chk_mod.lua SUBDIRS= share if WITH_MANUAL diff --git a/chk_mod.lua b/chk_mod.lua new file mode 100644 index 0000000..e1923f5 --- /dev/null +++ b/chk_mod.lua @@ -0,0 +1,72 @@ +-- libquvi-scripts +-- Copyright (C) 2012 Toni Gundogdu +-- +-- This file is part of libquvi-scripts . +-- +-- This program is free software: you can redistribute it and/or +-- modify it under the terms of the GNU Affero General Public +-- License as published by the Free Software Foundation, either +-- version 3 of the License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General +-- Public License along with this program. If not, see +-- . +-- + +-- +-- Checks the availability of a Lua module. +-- +-- NOTES: +-- * Exits with either 0 (success) or 1 (failure) +-- * Informative messages are printed to stdout +-- + +local EXIT_SUCCESS = 0 +local EXIT_FAILURE = 1 + +local function _chk_input() + if #arg <2 then + print(string.format('Usage: %s ', arg[0])) + print(' Exit status: 0=success, 1=failure') + print(string.format('Example: %s lxp 1.2.0', arg[0])) + os.exit(EXIT_FAILURE) + end +end + +local function _chk_form(a,b,c,s) + if not a or not b or not c then + print(string.format('error: %s must be in the x.y.z form', s)) + os.exit(EXIT_FAILURE) + end +end + +local function _to_n(a,b,c) + return tonumber(string.format('%d%d%d', + tonumber(a), tonumber(b), tonumber(c))) +end + +local function _chk_mod(m,r) + local p = '(%d+).(%d+).(%d+)' + + local ra,rb,rc = r:match(p) + _chk_form(ra,rb,rc,'reqver') + + local M = require(m) + + local fa,fb,fc = M._VERSION:match(p) + _chk_form(fa,fb,fc,'modver') + + print('require', ra,rb,rc) + print('found', fa,fb,fc) + + return (_to_n(fa,fb,fc) >= _to_n(ra,rb,rc)) + and EXIT_SUCCESS or EXIT_FAILURE +end + +_chk_input() +os.exit(_chk_mod(arg[1], arg[2])) -- 2.11.4.GIT