commit:     43b29c34f682cbde48f23c42fd13d334d7bb425c
Author:     Vadim A. Misbakh-Soloviov <git <AT> mva <DOT> name>
AuthorDate: Wed Sep 30 07:39:45 2015 +0000
Commit:     Vadim A. Misbakh-Soloviov <mva <AT> mva <DOT> name>
CommitDate: Wed Sep 30 07:39:45 2015 +0000
URL:        https://gitweb.gentoo.org/proj/lua.git/commit/?id=43b29c34

some more work about porting to lua eclass

Signed-off-by: Vadim A. Misbakh-Soloviov <git <AT> mva.name>

 app-eselect/eselect-lua/files/lua.eselect-2        |  44 +-
 dev-lang/lua/lua-5.1.5-r101.ebuild                 |   2 +-
 dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild             |   5 -
 dev-lua/captcha/captcha-9999.ebuild                |   2 +-
 dev-lua/cmsgpack/cmsgpack-9999.ebuild              |   4 +-
 dev-lua/cosmo/cosmo-9999.ebuild                    |   2 +-
 dev-lua/iluajit/iluajit-9999.ebuild                |   2 +-
 dev-lua/lapis/lapis-9999.ebuild                    |   1 -
 dev-lua/linotify/linotify-9999.ebuild              |   4 +-
 dev-lua/ljsyscall/ljsyscall-9999.ebuild            |   6 +-
 dev-lua/lpc/lpc-9999.ebuild                        |   7 +-
 dev-lua/lpeg/ChangeLog                             |  27 --
 dev-lua/lpeg/Manifest                              |   2 +-
 ...12-makefile.patch => lpeg-1.0.0-makefile.patch} |   6 +-
 .../lpeg/{lpeg-0.12.ebuild => lpeg-1.0.0.ebuild}   |   4 +-
 dev-lua/lua-cjson/lua-cjson-9999.ebuild            |   6 +-
 dev-lua/lua-curl/lua-curl-9999.ebuild              |   8 +-
 dev-lua/lua-ext/lua-ext-9999.ebuild                |  22 +-
 dev-lua/lua-fann/Manifest                          |   2 +-
 .../{lua-fann-0.4.ebuild => lua-fann-0.5.3.ebuild} |  43 +-
 dev-lua/lua-fann/lua-fann-9999.ebuild              |  50 ++-
 dev-lua/lua-fastcgi/lua-fastcgi-9999.ebuild        |  34 +-
 dev-lua/lua-feeds/lua-feeds-9999.ebuild            |  24 +-
 dev-lua/lua-gd/Manifest                            |   2 +-
 dev-lua/lua-gd/lua-gd-2.0.33.2.ebuild              |  60 ---
 dev-lua/lua-gd/lua-gd-9999.ebuild                  |  53 +--
 dev-lua/lua-geoip/lua-geoip-9999.ebuild            |  38 +-
 dev-lua/lua-getopt/lua-getopt-9999.ebuild          |  21 +-
 dev-lua/lua-html/lua-html-9999.ebuild              |  47 +-
 dev-lua/lua-htmlparser/lua-htmlparser-9999.ebuild  |  20 +-
 dev-lua/lua-iconv/lua-iconv-9999.ebuild            |  34 +-
 dev-lua/lua-json/metadata.xml                      |  14 -
 dev-lua/lua-sendmail/lua-sendmail-9999.ebuild      |  22 +-
 dev-lua/lua-set/lua-set-9999.ebuild                |  20 +-
 dev-lua/lua-stdlib/lua-stdlib-9999.ebuild          |  36 +-
 dev-lua/lua-zip/lua-zip-9999.ebuild                |  27 +-
 dev-lua/luacrypto/luacrypto-9999.ebuild            |  15 +-
 dev-lua/luadbi/luadbi-9999.ebuild                  |   9 +-
 dev-lua/luadoc/ChangeLog                           |  41 --
 dev-lua/luadoc/luadoc-3.0.1.ebuild                 |  33 +-
 dev-lua/luadoc/luadoc-9999.ebuild                  |  41 ++
 dev-lua/luaevent/files/gc-anchoring.patch          | 176 ++++++++
 dev-lua/luaevent/files/lua5.3.patch                |  11 +
 dev-lua/luaevent/luaevent-9999.ebuild              |  36 +-
 dev-lua/luaexpat/luaexpat-9999.ebuild              |  33 +-
 dev-lua/luafilesystem/luafilesystem-9999.ebuild    |  34 +-
 dev-lua/luahpdf/luahpdf-9999.ebuild                |  42 +-
 dev-lua/lualdap/lualdap-9999.ebuild                |  45 +-
 dev-lua/luamacro/luamacro-9999.ebuild              |  32 +-
 dev-lua/luamongo/luamongo-9999.ebuild              |  52 ++-
 dev-lua/luancurses/luancurses-9999.ebuild          |  31 --
 dev-lua/luancurses/metadata.xml                    |  14 -
 dev-lua/luaposix/luaposix-9999.ebuild              |  79 +++-
 dev-lua/luarocks/luarocks-9999.ebuild              |  57 ++-
 dev-lua/luasec/luasec-9999.ebuild                  |  51 ++-
 dev-lua/luasignal/luasignal-9999.ebuild            |  30 --
 dev-lua/luasignal/metadata.xml                     |  14 -
 dev-lua/luasocket/luasocket-9999.ebuild            | 100 +++--
 dev-lua/luaunbound/luaunbound-9999.ebuild          |  44 +-
 dev-lua/luaxml/luaxml-9999.ebuild                  |  25 +-
 dev-lua/luazip/luazip-9999.ebuild                  |  44 +-
 dev-lua/lullaby/lullaby-9999.ebuild                |  26 +-
 dev-lua/lulpeg/lulpeg-9999.ebuild                  |  35 +-
 dev-lua/lunit/lunit-9999.ebuild                    |  43 +-
 dev-lua/lyaml/lyaml-9999.ebuild                    |  63 ++-
 dev-lua/moonscript/moonscript-9999.ebuild          |   2 +-
 dev-lua/toluapp/ChangeLog                          | 110 -----
 eclass/lua.eclass                                  | 500 +++++++++++++++------
 68 files changed, 1337 insertions(+), 1232 deletions(-)

diff --git a/app-eselect/eselect-lua/files/lua.eselect-2 
b/app-eselect/eselect-lua/files/lua.eselect-2
index d3f67ad..05de202 100644
--- a/app-eselect/eselect-lua/files/lua.eselect-2
+++ b/app-eselect/eselect-lua/files/lua.eselect-2
@@ -5,7 +5,7 @@
 inherit config multilib
 
 DESCRIPTION="Manage lua symlinks"
-MAINTAINER="[email protected], [email protected]"
+MAINTAINER="[email protected], [email protected]"
 
 HEADER_FILES="lauxlib.h luaconf.h lua.h lua.hpp lualib.h"
 
@@ -16,24 +16,46 @@ remove_symlinks() {
                rm -f "${EROOT}"${dir}/pkgconfig/lua.pc &>/dev/null
        done
        for f in $HEADER_FILES ; do
-               rm -f "${EROOT}"/usr/include/$f
+               rm -f "${EROOT}"/usr/include/${f}
        done
        rm -f "${EROOT}"/usr/share/man/man1/{lua,luac}.1{,.gz,.bz2,.lzma} 
&>/dev/null
 }
 
+_dup() {
+       dirname ${1}/.
+}
+
 set_symlinks() {
        local ver=$1
-       ln -s "${EROOT}"/usr/bin/lua{$ver,}
-       ln -s "${EROOT}"/usr/bin/luac{$ver,}
+       ln -s lua${ver} $(_dup "${EROOT}"/usr/bin/lua)
+       ln -s luac${ver} $(_dup "${EROOT}"/usr/bin/luac)
        for dir in $(get_libdirs) ; do
-               ln -s "${dir}"/liblua{$ver,}.so
-               ln -s "${dir}"/pkgconfig/lua{$ver,}.pc
+               if has 'jit*' ${ver}; then
+                       type -p lua${ver} &>/dev/null || die -q "It's something 
wrong with your lua${ver} installation: it's binary leads to broken symlink"
+                       local abi=$(lua${ver} -e 
'print(_VERSION:match("%d.%d"))')
+                       local libname=libluajit-${abi}.so.${ver##jit-}
+                       test -f "${EROOT}/${dir}/${libname}" || die -q "Can't 
find libluajit for lua${ver} (lua abi: ${abi})"
+                       ln -s ${libname} $(_dup "${EROOT}/${dir}"/liblua.so)
+               else
+                       ln -s liblua${ver}.so $(_dup 
"${EROOT}/${dir}"/liblua.so)
+               fi
+               ln -s lua${ver}.pc $(_dup "${EROOT}/${dir}"/pkgconfig/lua.pc)
        done
-       for orig in "${EROOT}"/usr/share/man/man1/lua*$ver.1* ; do
-               ln -s "${orig}" "${orig//$ver}"
+       for manpage in "${EROOT}"/usr/share/man/man1/lua*${ver}.1* ; do
+               test -f ${manpage} &&
+               ln -s $(basename "${manpage}") $(_dup "${manpage//${ver}}")
        done
-       for f in $HEADER_FILES ; do
-               ln -s "${EROOT}"/usr/include/lua$ver/$f "${EROOT}"/usr/include
+       for header in $HEADER_FILES ; do
+               local hdr;
+               if has 'jit*' ${ver}; then
+                       type -p lua${ver} &>/dev/null || die -q "lua${ver} 
binary is missing (or leads to broken symlink)"
+                       local jit_v=$(lua${ver} -e 
'print(jit.version:match("%d.%d"))')
+                       hdr=luajit-${jit_v}/${header};
+               else
+                       hdr=lua${ver}/${header};
+               fi
+               test -f "${EROOT}/usr/include/${hdr}" || die -q "Missing 
header: ${header}"
+               ln -s "${hdr}" $(_dup "${EROOT}"/usr/include/${header})
        done
 }
 
@@ -51,7 +73,7 @@ get_libdirs() {
 find_targets() {
        local dirs
        local prefix="${EROOT}/usr/bin/lua"
-       for f in ${prefix}{5,jit-2}* ; do
+       for f in ${prefix}{5,jit-2}.* ; do
                [[ -f "${f}" ]] && dirs="${dirs} ${f##$prefix}"
        done
        echo $dirs

diff --git a/dev-lang/lua/lua-5.1.5-r101.ebuild 
b/dev-lang/lua/lua-5.1.5-r101.ebuild
index bcfd7b1..4803c0d 100644
--- a/dev-lang/lua/lua-5.1.5-r101.ebuild
+++ b/dev-lang/lua/lua-5.1.5-r101.ebuild
@@ -17,7 +17,7 @@ IUSE="+deprecated emacs readline static"
 
 RDEPEND="readline? ( >=sys-libs/readline-6.2_p5-r1[${MULTILIB_USEDEP}] )
        app-eselect/eselect-lua
-       !dev-lang/lua:0"
+       !!dev-lang/lua:0"
 DEPEND="${RDEPEND}
        sys-devel/libtool"
 PDEPEND="emacs? ( app-emacs/lua-mode )"

diff --git a/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild 
b/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
index a364492..0cc551d 100644
--- a/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
+++ b/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
@@ -21,11 +21,6 @@ IUSE="doc"
 READMES=( README )
 HTML_DOCS=( doc/ )
 
-each_lua_compile() {
-       _lua_setCFLAGS
-       emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"
-}
-
 each_lua_test() {
        emake LUA=${LUA} test
 }

diff --git a/dev-lua/captcha/captcha-9999.ebuild 
b/dev-lua/captcha/captcha-9999.ebuild
index a61d2a5..a0ce6de 100644
--- a/dev-lua/captcha/captcha-9999.ebuild
+++ b/dev-lua/captcha/captcha-9999.ebuild
@@ -19,7 +19,7 @@ KEYWORDS=""
 IUSE="jpeg png +examples"
 
 READMES=( README.md )
-EXAMPLES=( examples/* )
+EXAMPLES=( examples/ )
 
 RDEPEND="
        dev-lua/lua-gd

diff --git a/dev-lua/cmsgpack/cmsgpack-9999.ebuild 
b/dev-lua/cmsgpack/cmsgpack-9999.ebuild
index 85cdaf9..1c53394 100644
--- a/dev-lua/cmsgpack/cmsgpack-9999.ebuild
+++ b/dev-lua/cmsgpack/cmsgpack-9999.ebuild
@@ -24,8 +24,8 @@ each_lua_compile() {
        _lua_setCFLAGS
        local MY_PN="lua_${PN}"
 
-       $(tc-getCC) -fPIC ${CFLAGS} -c -o ${MY_PN}.o ${MY_PN}.c || die
-       $(tc-getCC) ${LDFLAGS} -shared -o ${PN}.so ${MY_PN}.o || die
+       ${CC} ${CFLAGS} -c -o ${MY_PN}.o ${MY_PN}.c || die
+       ${CC} ${LDFLAGS} -o ${PN}.so ${MY_PN}.o || die
 }
 
 each_lua_test() {

diff --git a/dev-lua/cosmo/cosmo-9999.ebuild b/dev-lua/cosmo/cosmo-9999.ebuild
index bdd7030..e05e2a2 100644
--- a/dev-lua/cosmo/cosmo-9999.ebuild
+++ b/dev-lua/cosmo/cosmo-9999.ebuild
@@ -21,7 +21,7 @@ IUSE="doc +examples"
 RDEPEND="
        || (
                dev-lua/lpeg
-               dev-lua/lulpeg[lpeg-compat]
+               dev-lua/lulpeg[lpeg_replace]
        )
 "
 

diff --git a/dev-lua/iluajit/iluajit-9999.ebuild 
b/dev-lua/iluajit/iluajit-9999.ebuild
index 8273747..bb0b648 100644
--- a/dev-lua/iluajit/iluajit-9999.ebuild
+++ b/dev-lua/iluajit/iluajit-9999.ebuild
@@ -36,7 +36,7 @@ all_lua_prepare() {
 }
 
 each_lua_install() {
-       dolua *.lua
+       dolua_jit *.lua
 }
 
 all_lua_install() {

diff --git a/dev-lua/lapis/lapis-9999.ebuild b/dev-lua/lapis/lapis-9999.ebuild
index b0ac90e..8e465c0 100644
--- a/dev-lua/lapis/lapis-9999.ebuild
+++ b/dev-lua/lapis/lapis-9999.ebuild
@@ -30,7 +30,6 @@ RDEPEND="
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
 DOCS=( docs/ README.md )

diff --git a/dev-lua/linotify/linotify-9999.ebuild 
b/dev-lua/linotify/linotify-9999.ebuild
index 6a4e2a4..aeed3ce 100644
--- a/dev-lua/linotify/linotify-9999.ebuild
+++ b/dev-lua/linotify/linotify-9999.ebuild
@@ -24,11 +24,9 @@ RDEPEND="virtual/libc"
 READMES=( README.md )
 
 each_lua_compile() {
-       _lua_setCFLAGS
-       emake LUAPKG_CMD="${lua_impl}"
+       lua_default LUAPKG_CMD="${lua_impl}"
 }
 
 each_lua_install() {
        dolua inotify.so
-#      emake LUAPKG_CMD="${lua_impl}" DESTDIR="${D}" install
 }

diff --git a/dev-lua/ljsyscall/ljsyscall-9999.ebuild 
b/dev-lua/ljsyscall/ljsyscall-9999.ebuild
index e652395..693dab3 100644
--- a/dev-lua/ljsyscall/ljsyscall-9999.ebuild
+++ b/dev-lua/ljsyscall/ljsyscall-9999.ebuild
@@ -17,15 +17,15 @@ EGIT_REPO_URI="https://github.com/justincormack/ljsyscall";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc +examples test"
+IUSE="doc +examples"
 
 RDEPEND="
        virtual/libc
 "
 DEPEND="${RDEPEND}"
 
-DOCS=( README.md doc/)
-EXAMPLES=( examples/* )
+DOCS=( README.md doc/ )
+EXAMPLES=( examples/ )
 
 each_lua_install() {
        dolua syscall syscall.lua

diff --git a/dev-lua/lpc/lpc-9999.ebuild b/dev-lua/lpc/lpc-9999.ebuild
index a572f23..cc17b1d 100644
--- a/dev-lua/lpc/lpc-9999.ebuild
+++ b/dev-lua/lpc/lpc-9999.ebuild
@@ -10,18 +10,13 @@ inherit lua
 
 DESCRIPTION="Allows Lua scripts to call external processes while capturing 
both their input and output."
 HOMEPAGE="http://lua.net-core.org/sputnik.lua?p=Telesto:About";
-EGIT_REPO_URI="https://github.com/LuaDist/lpc";
+EGIT_REPO_URI="https://github.com/msva/lpc";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
 IUSE=""
 
-each_lua_compile() {
-       _lua_setCFLAGS
-       emake CC="${CC}" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"
-}
-
 each_lua_install() {
        dolua ${PN}.so
 }

diff --git a/dev-lua/lpeg/ChangeLog b/dev-lua/lpeg/ChangeLog
deleted file mode 100644
index 313239c..0000000
--- a/dev-lua/lpeg/ChangeLog
+++ /dev/null
@@ -1,27 +0,0 @@
-# ChangeLog for dev-lua/lpeg
-# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-lua/lpeg/ChangeLog,v 1.7 2014/06/22 
22:40:01 radhermit Exp $
-
-  22 Jun 2014; Tim Harder <[email protected]> lpeg-0.12.ebuild:
-  Don't hardcode pkg-config.
-
-  16 Jun 2014; Tim Harder <[email protected]> lpeg-0.12.ebuild:
-  Use pkgconfig to determine lua C modules directory (bug #503990).
-
-  04 Mar 2014; Vicente Olivert Riera <[email protected]> lpeg-0.12.ebuild:
-  Add ~mips keyword.
-
-  25 Feb 2014; Markus Meier <[email protected]> lpeg-0.12.ebuild:
-  add ~arm, bug #495254
-
-  23 Feb 2014; Pacho Ramos <[email protected]> lpeg-0.12.ebuild:
-  amd64/x86 stable, bug #501720
-
-  22 Feb 2014; Jeroen Roovers <[email protected]> lpeg-0.12.ebuild:
-  Marked ~hppa (bug #495254).
-
-*lpeg-0.12 (22 May 2013)
-
-  22 May 2013; Tim Harder <[email protected]> +lpeg-0.12.ebuild,
-  +files/lpeg-0.12-makefile.patch, +metadata.xml:
-  Initial import (bug #469300 by Raphaël Droz).

diff --git a/dev-lua/lpeg/Manifest b/dev-lua/lpeg/Manifest
index b6e0248..7704d58 100644
--- a/dev-lua/lpeg/Manifest
+++ b/dev-lua/lpeg/Manifest
@@ -1 +1 @@
-DIST lpeg-0.12.tar.gz 66649 SHA256 
efa545144cd219eee823af7624d90f78c2230677ba740b7151c5d0c303778b76 SHA512 
bf8c4fe486f5e965b793d8526dd1fc5c8905c4b065a1abe52ec8e41ebbe48292315a7460dc56fb7a029b4673057f9da7e53854bb79bb54dd8a4378391efc24a2
 WHIRLPOOL 
3e131da888eff53fbfa6203ed363f34832c52fb0fafca9006dd1da956c89a76528dc9aaf255426a148497c55df74ccb72cf87e234f5c432c4e2c28a5dfd0a9a1
+DIST lpeg-1.0.0.tar.gz 70267 SHA256 
10190ae758a22a16415429a9eb70344cf29cbda738a6962a9f94a732340abf8e SHA512 
a245d2e0b8604121d8b4466052ab5da4f2b1f81c1c4b2579d8d5498920fc351d46fe4159a0b5948d1b377ef9bda410c4bf40ffd228b9f26bf346dfba2a7b9fb7
 WHIRLPOOL 
808b1ddc61402c707a829641051c9321030573e85e863a6463bd8f114e89576dc7566585ae331a8af6d1f970c29b4256141df90fa5fe3616bea5691040262498

diff --git a/dev-lua/lpeg/files/lpeg-0.12-makefile.patch 
b/dev-lua/lpeg/files/lpeg-1.0.0-makefile.patch
similarity index 83%
rename from dev-lua/lpeg/files/lpeg-0.12-makefile.patch
rename to dev-lua/lpeg/files/lpeg-1.0.0-makefile.patch
index 5734de9..96b1d66 100644
--- a/dev-lua/lpeg/files/lpeg-0.12-makefile.patch
+++ b/dev-lua/lpeg/files/lpeg-1.0.0-makefile.patch
@@ -2,7 +2,7 @@
 +++ lpeg-0.12/makefile
 @@ -1,7 +1,7 @@
  LIBNAME = lpeg
- LUADIR = /usr/include/lua5.1/
+ LUADIR = ../lua/
  
 -COPT = -O2
 +#COPT = -O2
@@ -13,8 +13,8 @@
  # -Wunreachable-code \
  
  
--CFLAGS = $(CWARNS) $(COPT) -ansi -I$(LUADIR) -fPIC
-+CFLAGS += $(CWARNS) $(COPT) -ansi -I$(LUADIR) -fPIC
+-CFLAGS = $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC
++CFLAGS += $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC
  CC = gcc
  
  FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o

diff --git a/dev-lua/lpeg/lpeg-0.12.ebuild b/dev-lua/lpeg/lpeg-1.0.0.ebuild
similarity index 89%
rename from dev-lua/lpeg/lpeg-0.12.ebuild
rename to dev-lua/lpeg/lpeg-1.0.0.ebuild
index 7d3d240..3dfe5d9 100644
--- a/dev-lua/lpeg/lpeg-0.12.ebuild
+++ b/dev-lua/lpeg/lpeg-1.0.0.ebuild
@@ -5,6 +5,7 @@
 EAPI="5"
 
 IS_MULTILIB=true
+LUA_COMPAT="lua51 luajit2"
 inherit lua
 
 DESCRIPTION="Parsing Expression Grammars for Lua"
@@ -25,8 +26,7 @@ all_lua_prepare() {
 }
 
 each_lua_compile() {
-       _lua_setCFLAGS
-       emake CC="$(tc-getCC)" DLLFLAGS="${CFLAGS} ${LDFLAGS}" lpeg.so
+       lua_default DLLFLAGS="${CFLAGS} ${LDFLAGS}" lpeg.so
 }
 
 each_lua_test() {

diff --git a/dev-lua/lua-cjson/lua-cjson-9999.ebuild 
b/dev-lua/lua-cjson/lua-cjson-9999.ebuild
index 0c0d662..ea2698d 100644
--- a/dev-lua/lua-cjson/lua-cjson-9999.ebuild
+++ b/dev-lua/lua-cjson/lua-cjson-9999.ebuild
@@ -20,7 +20,7 @@ SLOT="0"
 KEYWORDS=""
 IUSE="+examples"
 
-EXAMPLES=( tests/* lua/{json2lua,lua2json}.lua )
+EXAMPLES=( tests/ lua/{json2lua,lua2json}.lua )
 
 each_lua_configure() {
        mycmakeargs=(
@@ -29,10 +29,6 @@ each_lua_configure() {
        cmake-utils_src_configure
 }
 
-each_lua_compile() {
-       emake
-}
-
 each_lua_install() {
        dolua lua/cjson cjson.so
 #      cmake-utils_src_install

diff --git a/dev-lua/lua-curl/lua-curl-9999.ebuild 
b/dev-lua/lua-curl/lua-curl-9999.ebuild
index 28c65b5..46133d2 100644
--- a/dev-lua/lua-curl/lua-curl-9999.ebuild
+++ b/dev-lua/lua-curl/lua-curl-9999.ebuild
@@ -26,14 +26,14 @@ DEPEND="
        ${RDEPEND}
 "
 
-EXAMPLES=( examples/* )
+EXAMPLES=( examples/ )
 HTML_DOCS=( html/ )
 READMES=( README.md )
 
 each_lua_compile() {
-       _lua_setCFLAGS
-       emake LUA_IMPL="${lua_impl}"
+       lua_default LUA_IMPL="${lua_impl}"
 }
+
 all_lua_compile() {
        use doc && (
                cd doc
@@ -43,5 +43,5 @@ all_lua_compile() {
 
 
 each_lua_install() {
-       emake LUA_IMPL="${lua_impl}" DESTDIR="${D}" install
+       lua_default LUA_IMPL="${lua_impl}"
 }

diff --git a/dev-lua/lua-ext/lua-ext-9999.ebuild 
b/dev-lua/lua-ext/lua-ext-9999.ebuild
index d611c0d..2baa38f 100644
--- a/dev-lua/lua-ext/lua-ext-9999.ebuild
+++ b/dev-lua/lua-ext/lua-ext-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI=5
 
-inherit toolchain-funcs eutils git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Some useful extensions to Lua classes"
 HOMEPAGE="https://github.com/thenumbernine/lua-ext";
@@ -15,20 +16,11 @@ EGIT_REPO_URI="https://github.com/thenumbernine/ext";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-DEPEND="
-       virtual/lua[luajit=]
-       virtual/pkgconfig
-"
-RDEPEND="
-       ${DEPEND}
-"
+READMES=( README )
 
-src_install() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})/ext"
-       doins *.lua
-       dodoc README
+each_lua_install() {
+       _dolua_insdir="ext" \
+       dolua *.lua
 }

diff --git a/dev-lua/lua-fann/Manifest b/dev-lua/lua-fann/Manifest
index b4c922a..8417e37 100644
--- a/dev-lua/lua-fann/Manifest
+++ b/dev-lua/lua-fann/Manifest
@@ -1 +1 @@
-DIST lua-fann-0.4.tgz 18418 SHA256 
e9e698244d291236b6dbc8d452ce2a37b556f372508c3ae94be1dfdbe1f61316 SHA512 
0fc714d6b869f3aa3ae9909c7f4be257459a097dac870b36ab229607201d0c9bcee967c925ef993f1c4de18f5b43157a9a0345a1080f20b8bcc8dcc365c97500
 WHIRLPOOL 
e6ac0333f245fe32e8c118042177822b878e00b11983975ea0c45074746428048b261bf1cdcb03b2a73036caa7286e92923d01c5af572e302f46a40fa3198325
+DIST lua-fann-0.5.3.tgz 18937 SHA256 
575c7fc6282989578cf3dae7bf19e2e56f107d6b38076695fd329f7bb40b1b40 SHA512 
01dcdb13f88705ad6b5ead3d398da56721b2db9faf1c421d9bf743dad4fd26da9d3091fe257d66bf7744575e703add11a9fe95553830f487af3cb14af6eba05d
 WHIRLPOOL 
f0f2f23a8161e4f1f87fbb0bb0c7fae5c903eba7248a2e863bb4adaf59f0bca34cc45976c84f95a3040686c8bc7b093daa5df04ee5e449ac3e762dcf2c7a6f1d

diff --git a/dev-lua/lua-fann/lua-fann-0.4.ebuild 
b/dev-lua/lua-fann/lua-fann-0.5.3.ebuild
similarity index 51%
rename from dev-lua/lua-fann/lua-fann-0.4.ebuild
rename to dev-lua/lua-fann/lua-fann-0.5.3.ebuild
index 92c18eb..1d6ec00 100644
--- a/dev-lua/lua-fann/lua-fann-0.4.ebuild
+++ b/dev-lua/lua-fann/lua-fann-0.5.3.ebuild
@@ -4,44 +4,47 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs
+# fixme when fann will be multilib
+#IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="A set of Lua bindings for the Fast Artificial Neural Network 
(FANN) library."
 HOMEPAGE="https://github.com/msva/lua-fann";
-SRC_URI="https://github.com/msva/{$PN}/archive/${PV}.tar.gz -> ${P}.tgz"
+SRC_URI="https://github.com/msva/${PN}/archive/${PV}.tar.gz -> ${P}.tgz"
 
 LICENSE="LGPL-2.1"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        sci-mathematics/fann
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       default
-       epatch_user
-       export LUA_INCLUDE_DIR="$($(tc-getPKG_CONFIG) --variable includedir 
${lua})"
-       export LUABIN="${lua}"
+READMES=( README.md TODO )
+HTML_DOCS=( doc/luafann.html )
+EXAMPLES=( examples/ )
+
+all_lua_compile() {
+       use doc && (
+               emake docs
+       )
 }
 
-src_test() {
+each_lua_compile() {
+       lua_default \
+               LUA_IMPL="$(lua_get_lua)" \
+               LUA_BIN="${LUA}" \
+               LUA_INC="."
+}
+
+each_lua_test() {
        emake test
 }
 
-src_install() {
-       dodoc README.md TODO || die "dodoc failed"
-       use doc && (
-               emake docs
-               dohtml doc/luafann.html
-       )
-       default
+each_lua_install() {
+       dolua fann.so
 }

diff --git a/dev-lua/lua-fann/lua-fann-9999.ebuild 
b/dev-lua/lua-fann/lua-fann-9999.ebuild
index b9b7401..7396b7c 100644
--- a/dev-lua/lua-fann/lua-fann-9999.ebuild
+++ b/dev-lua/lua-fann/lua-fann-9999.ebuild
@@ -4,43 +4,55 @@
 
 EAPI="5"
 
-inherit eutils git-r3 toolchain-funcs
+# fixme when fann will be multilib
+#IS_MULTILIB=true
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A set of Lua bindings for the Fast Artificial Neural Network 
(FANN) library."
 HOMEPAGE="https://github.com/msva/lua-fann";
 SRC_URI=""
-
-EGIT_REPO_URI="https://github.com/msva/lua-fann";
+EGIT_REPO_URI="https://github.com/msva/${PN}";
 
 LICENSE="LGPL-2.1"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        sci-mathematics/fann
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       echo "LUA_IMPL=${lua}" > .config
-       default
-}
+READMES=( README.md TODO )
+HTML_DOCS=( doc/luafann.html )
+EXAMPLES=( examples/* )
 
-src_install() {
-       docompress -x /usr/share/doc/${PF}/examples
-       dodoc README.md TODO || die "dodoc failed"
+all_lua_compile() {
        use doc && (
                emake docs
-               dohtml doc/luafann.html
-               insinto /usr/share/doc/${PF}/examples
-               doins -r test/*
        )
-       default
+}
+
+each_lua_compile() {
+       _lua_setCFLAGS
+
+       emake \
+               CC="${CC}" \
+               CFLAGS="${CFLAGS}" \
+               LDFLAGS="${LDFLAGS}" \
+               PKG_CONFIG="${PKG_CONFIG}" \
+               LUA_IMPL="$(lua_get_lua)" \
+               LUA_BIN="${LUA}" \
+               LUA_INC="."
+}
+
+each_lua_test() {
+       emake test
+}
+
+each_lua_install() {
+       dolua fann.so
 }

diff --git a/dev-lua/lua-fastcgi/lua-fastcgi-9999.ebuild 
b/dev-lua/lua-fastcgi/lua-fastcgi-9999.ebuild
index c7509f4..82d62fe 100644
--- a/dev-lua/lua-fastcgi/lua-fastcgi-9999.ebuild
+++ b/dev-lua/lua-fastcgi/lua-fastcgi-9999.ebuild
@@ -4,7 +4,10 @@
 
 EAPI="5"
 
-inherit toolchain-funcs eutils git-r3
+VCS="git-r3"
+# FIXME when fcgi will be multilib
+#IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="A FastCGI server for Lua, written in C"
 HOMEPAGE="https://github.com/cramey/lua-fastcgi";
@@ -16,33 +19,32 @@ EGIT_BRANCH="public"
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit]
        dev-libs/fcgi
 "
 DEPEND="${RDEPEND}"
 
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       LUA_LIB="$($(tc-getPKG_CONFIG) libs ${lua})"
+READMES=( README.md TODO )
+EXAMPLES=( ${PN}.lua )
 
+all_lua_prepare() {
        sed -r \
-               -e "s#^(CFLAGS=.*)#\1 $($(tc-getPKG_CONFIG) --variable cflags 
${lua})#" \
-               -e "s/-Wl,[^ ]*//g" \
-               -e "s#-llua5.1#${LUA_LIB}#g" \
+               -e 's#CFLAGS#CF#g' \
+               -e 's#LDFLAGS#LF#g' \
+               -e 's#^(CF=)#\1 $(CFLAGS) #' \
+               -e 's#^(LF=)#\1 $(LDFLAGS) #' \
+               -e 's/-Wl,[^ ]*//g' \
+               -e 's#-llua5.1#$(LUA_LINK_LIB)#g' \
                -i Makefile
+
        sed \
                -e "s#lua5.1/##" \
                -i src/config.c src/lfuncs.c src/lua.c src/lua-fastcgi.c
 }
 
-src_install() {
-       if use doc; then
-               dodoc README.md TODO lua-fastcgi.lua || die "dodoc failed"
-       fi
-       dobin lua-fastcgi
+each_lua_install() {
+       newbin ${PN} ${PN}-${TARGET}
+#-${ABI} #is it needed?
 }

diff --git a/dev-lua/lua-feeds/lua-feeds-9999.ebuild 
b/dev-lua/lua-feeds/lua-feeds-9999.ebuild
index b4c56a6..dac919a 100644
--- a/dev-lua/lua-feeds/lua-feeds-9999.ebuild
+++ b/dev-lua/lua-feeds/lua-feeds-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs flag-o-matic eutils mercurial
+VCS="mercurial"
+inherit lua
 
 DESCRIPTION="Lua feeds parsing library"
 HOMEPAGE="http://code.matthewwild.co.uk/lua-feeds";
@@ -13,26 +14,19 @@ EHG_REPO_URI="http://code.matthewwild.co.uk/lua-feeds";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-"
+IUSE="+examples"
 
 DEPEND="
        ${RDEPEND}
        dev-lua/squish
-       virtual/pkgconfig
 "
 
-DOCS=( "demo.lua" "demo_string.lua" )
+EXAMPLES=( demo.lua demo_string.lua )
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       cd "${S}"
+each_lua_compile() {
        squish
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       newins "feeds.min.lua" "feeds.lua"
-       base_src_install_docs
+}
+
+each_lua_install() {
+       newlua feeds{.min,}.lua
 }

diff --git a/dev-lua/lua-gd/Manifest b/dev-lua/lua-gd/Manifest
index 62c7358..058dadf 100644
--- a/dev-lua/lua-gd/Manifest
+++ b/dev-lua/lua-gd/Manifest
@@ -1 +1 @@
-DIST lua-gd-2.0.33r2.tar.gz 448606 SHA256 
235eceba9b55fd6b6cb6d88b0df676d6f94ff49155a0710363c21e2cc0987ec6
+DIST lua-gd-2.0.33r2.tar.gz 448606 SHA256 
235eceba9b55fd6b6cb6d88b0df676d6f94ff49155a0710363c21e2cc0987ec6 SHA512 
913225411612705b6be77d7023261890d21bf5bf43e4ef694826288933b1bb6d9d5a1790b5974de5e3b688b672f51d930f763c5fb56464932189ec9c27c4b3ab
 WHIRLPOOL 
145200dd76a01aadaf9a6c14592c5c51d63c54c00afc68bc7b287ee4c05e069b17a1fa91231a37996c77e3f7bbc2fe598d62f71a66d61a6faa87147b50c5ce7e

diff --git a/dev-lua/lua-gd/lua-gd-2.0.33.2.ebuild 
b/dev-lua/lua-gd/lua-gd-2.0.33.2.ebuild
deleted file mode 100644
index 3aa56fe..0000000
--- a/dev-lua/lua-gd/lua-gd-2.0.33.2.ebuild
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright 1999-2015 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: This ebuild is from Lua overlay; Bumped by mva; $
-
-EAPI="5"
-
-inherit eutils toolchain-funcs versionator
-
-MY_P=${PN}-$(replace_version_separator 3 'r' )
-
-DESCRIPTION="Lua bindings to Thomas Boutell's gd library"
-HOMEPAGE="http://lua-gd.luaforge.net/";
-SRC_URI="http://luaforge.net/frs/download.php/1592/${MY_P}.tar.gz
-       
mirror://sourceforge/${PN}/${PN}/${MY_P}%20%28for%20Lua%205.1%29/${MY_P}.tar.gz"
-
-LICENSE="MIT"
-SLOT="0"
-KEYWORDS="~amd64 ~x86"
-IUSE="doc examples luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-       media-libs/gd[png]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-S=${WORKDIR}/${MY_P}
-
-src_prepare() {
-       epatch "${FILESDIR}/${P}-makefile.patch"
-}
-
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake LUAPKG="${lua}" LUABIN="${lua}" CC="$(tc-getCC)"
-}
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake \
-               LUAPKG="${lua}"\
-               DESTDIR="${D}"\
-               INSTALL_PATH="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})"\
-               install
-       dodoc README
-
-       if use doc; then
-               dohtml doc/*
-       fi
-
-       if use examples; then
-               insinto /usr/share/doc/${PF}
-               doins -r demos
-       fi
-}

diff --git a/dev-lua/lua-gd/lua-gd-9999.ebuild 
b/dev-lua/lua-gd/lua-gd-9999.ebuild
index 1ce34df..9fb8cdf 100644
--- a/dev-lua/lua-gd/lua-gd-9999.ebuild
+++ b/dev-lua/lua-gd/lua-gd-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3 multilib
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="Lua bindings to Thomas Boutell's gd library"
 HOMEPAGE="http://lua-gd.luaforge.net/";
@@ -14,50 +16,37 @@ EGIT_REPO_URI="https://github.com/ittner/lua-gd.git";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc examples luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        media-libs/gd[png]
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-QA_PREBUILT="usr/$(get_libdir)/*"
-# ^ sorry for that, but upstream prestrips module, and it is impossible to ask
-# pkgconfig here, since lua implementation is unknown atm
+READMES=( README )
+EXAMPLES=( demos/* )
+HTML_DOCS=( doc/ )
 
-src_prepare() {
+all_lua_prepare() {
        sed -r \
-               -e "s/^(CFLAGS=)-O3 -Wall /\1/" \
+               -e 's#CFLAGS#CF#g' \
+               -e 's#LFLAGS#LF#g' \
+               -e 's/^(CF=.*)/\1 $(CFLAGS)/' \
+               -e 's/^(LF=.*)/\1 $(LDFLAGS)/' \
+               -e 's/`pkg-config/`$(PKG_CONFIG)/' \
                -i Makefile
 }
 
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake LUAPKG="${lua}" LUABIN="${lua}" CC="$(tc-getCC)"
+each_lua_compile() {
+       local lua=$(lua_get_lua)
+       lua_default \
+               LUAPKG="${lua}" \
+               LUABIN="${lua}" \
+                       gd.so
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake \
-               LUAPKG="${lua}"\
-               DESTDIR="${D}"\
-               INSTALL_PATH="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})"\
-               install
-
-       dodoc README
-
-       if use doc; then
-               dohtml doc/*
-       fi
-
-       if use examples; then
-               insinto /usr/share/doc/${PF}
-               doins -r demos
-       fi
+each_lua_install() {
+       dolua gd.so
 }

diff --git a/dev-lua/lua-geoip/lua-geoip-9999.ebuild 
b/dev-lua/lua-geoip/lua-geoip-9999.ebuild
index dc66932..73650b6 100644
--- a/dev-lua/lua-geoip/lua-geoip-9999.ebuild
+++ b/dev-lua/lua-geoip/lua-geoip-9999.ebuild
@@ -4,40 +4,36 @@
 
 EAPI="5"
 
-inherit autotools eutils git-r3 toolchain-funcs
+VCS="git-r3"
+
+# FIXME when GeoIP will be multilib
+#IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="Lua GeoIP Library"
-HOMEPAGE="https://github.com/msva/lua-geoip";
+HOMEPAGE="https://agladysh.github.io/lua-geoip";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/msva/lua-geoip 
git://github.com/msva/lua-geoip"
+EGIT_REPO_URI="https://github.com/msva/lua-geoip";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="virtual/lua[luajit=]"
+RDEPEND="
+       dev-libs/geoip
+"
 DEPEND="
        ${RDEPEND}
-       dev-libs/geoip
 "
 
-src_prepare() {
-       local lua="lua"
-       use luajit && lua="luajit";
-       default
-       epatch_user
-       export LUA_INCLUDE_DIR="$($(tc-getPKG_CONFIG) --variable includedir 
${lua})"
-       export LUA="${lua}"
-}
+READMES=( README.md HISTORY TODO )
 
-#Temporarily(?) broken on city database checking
-#src_test() {
-#      ${LUA} test/test.lua
-#}
+src_test() {
+       ${LUA} test/test.lua /usr/share/GeoIP/Geo{IP,LiteCity}.dat
+}
 
-src_install() {
-       default
-       dodoc README.md TODO || die "dodoc failed"
+each_lua_install() {
+       dolua geoip{,.so}
 }

diff --git a/dev-lua/lua-getopt/lua-getopt-9999.ebuild 
b/dev-lua/lua-getopt/lua-getopt-9999.ebuild
index 597fe2e..19a76d9 100644
--- a/dev-lua/lua-getopt/lua-getopt-9999.ebuild
+++ b/dev-lua/lua-getopt/lua-getopt-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Lua getopt module (simplified)"
 HOMEPAGE="https://github.com/jjensen/lua-getopt";
@@ -13,20 +14,8 @@ EGIT_REPO_URI="https://github.com/jjensen/lua-getopt";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins src/getopt.lua
+each_lua_install() {
+       dolua src/getopt.lua
 }

diff --git a/dev-lua/lua-html/lua-html-9999.ebuild 
b/dev-lua/lua-html/lua-html-9999.ebuild
index b3e3810..15a9d05 100644
--- a/dev-lua/lua-html/lua-html-9999.ebuild
+++ b/dev-lua/lua-html/lua-html-9999.ebuild
@@ -2,9 +2,12 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Header: This ebuild is from Lua overlay; Bumped by mva; $
 
-EAPI=5
+EAPI="5"
 
-inherit toolchain-funcs eutils git-r3 multilib-minimal
+LUA_COMPAT="lua52"
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="lua bindings for HTMLParser in libxml2"
 HOMEPAGE="https://github.com/sprhawk/lua-html";
@@ -15,44 +18,42 @@ EGIT_REPO_URI="https://github.com/sprhawk/lua-html";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-DEPEND="
-       virtual/lua[luajit=]
-       virtual/pkgconfig
-"
 RDEPEND="
        ${DEPEND}
        dev-libs/libxml2
 "
 
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit
+READMES=( Readme.md )
 
-       local libs="$($(tc-getPKG_CONFIG) --libs libxml-2.0) 
$($(tc-getPKG_CONFIG) --libs ${lua})"
-       local cflags="$($(tc-getPKG_CONFIG) --cflags libxml-2.0) 
$($(tc-getPKG_CONFIG) --cflags ${lua})"
+all_lua_prepare() {
+       lua_default
 
-#              -e "s#^(LDFLAGS)=.*#\1=${LDFLAGS}#" \
+       # macos thing in linux target
        sed -r \
-               -e "s#^(CFLAGS)=.*#\1=-c ${CFLAGS} ${cflags} -fPIC -DPIC#" \
-               -e "s# -l.* (-o)# ${libs} \1#g" \
+               -e "s#-undefined dynamic_lookup##g" \
                -i Makefile
 
+       # Wrong case of header name
        sed -r \
                -e 's#libxml/HTMLParser.h#libxml/HTMLparser.h#' \
                -i html.c
+}
 
-       multilib_copy_sources
+each_lua_test() {
+       ${LUA} test.lua
 }
 
-multilib_src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})"
-       doins html.so
+each_lua_configure() {
+       myeconfargs=()
+       myeconfargs+=(
+               'CFLAGS+=$(shell $(PKG_CONFIG) --cflags-only-I libxml-2.0)'
+               'LDFLAGS+=$(shell $(PKG_CONFIG) --libs-only-L libxml-2.0)'
+       )
+       lua_default
 }
 
-multilib_src_install_all() {
-       dodoc Readme.md
+each_lua_install() {
+       dolua html.so
 }

diff --git a/dev-lua/lua-htmlparser/lua-htmlparser-9999.ebuild 
b/dev-lua/lua-htmlparser/lua-htmlparser-9999.ebuild
index ea20a48..1508e6f 100644
--- a/dev-lua/lua-htmlparser/lua-htmlparser-9999.ebuild
+++ b/dev-lua/lua-htmlparser/lua-htmlparser-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI=5
 
-inherit toolchain-funcs eutils git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Parse HTML text into a tree of elements with selectors"
 HOMEPAGE="https://github.com/msva/lua-htmlparser";
@@ -15,19 +16,8 @@ EGIT_REPO_URI="https://github.com/msva/lua-htmlparser";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-DEPEND="
-       virtual/lua[luajit=]
-       virtual/pkgconfig
-"
-RDEPEND="
-       ${DEPEND}
-"
-
-src_install() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r src/*
+each_lua_install() {
+       dolua src/*
 }

diff --git a/dev-lua/lua-iconv/lua-iconv-9999.ebuild 
b/dev-lua/lua-iconv/lua-iconv-9999.ebuild
index 08c1aa2..a3dc565 100644
--- a/dev-lua/lua-iconv/lua-iconv-9999.ebuild
+++ b/dev-lua/lua-iconv/lua-iconv-9999.ebuild
@@ -4,39 +4,21 @@
 
 EAPI="5"
 
-inherit eutils git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
-DESCRIPTION="Lua cURL Library"
+DESCRIPTION="Lua bindings for POSIX iconv"
 HOMEPAGE="http://ittner.github.com/lua-iconv";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/ittner/lua-iconv.git";
+EGIT_REPO_URI="https://github.com/ittner/lua-iconv";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_prepare() {
-       epatch_user
-       sed -e "s/install -D -s/install -D/" -i Makefile
-       sed -e "/make test/d" -i Makefile
-}
-
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake LUAPKG="${lua}" || die "Can't compile"
-}
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake DESTDIR="${D}" INSTALL_PATH="$($(tc-getPKG_CONFIG) --variable 
INSTALL_CMOD ${lua})" install || die "Can't install"
+each_lua_install() {
+       dolua iconv.so
 }

diff --git a/dev-lua/lua-json/metadata.xml b/dev-lua/lua-json/metadata.xml
deleted file mode 100644
index 23da526..0000000
--- a/dev-lua/lua-json/metadata.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
-<pkgmetadata>
-<maintainer>
- <email>[email protected]</email>
- <description>
-       If you have any issues, please contact me, or try to find me in IRC on 
Freenode, OFTC or RusNet.
- </description> 
- <name>Vadim A. Misbakh-Soloviov</name>
-</maintainer>
-<longdescription>FIXME</longdescription> 
-<use>
-</use>
-</pkgmetadata>

diff --git a/dev-lua/lua-sendmail/lua-sendmail-9999.ebuild 
b/dev-lua/lua-sendmail/lua-sendmail-9999.ebuild
index a4f6ec1..b954824 100644
--- a/dev-lua/lua-sendmail/lua-sendmail-9999.ebuild
+++ b/dev-lua/lua-sendmail/lua-sendmail-9999.ebuild
@@ -4,9 +4,10 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
-DESCRIPTION="A stream-based HTML template library for Lua."
+DESCRIPTION="Simple wrapper around luasoket smtp.send"
 HOMEPAGE="https://github.com/moteus/lua-sendmail";
 SRC_URI=""
 
@@ -15,25 +16,18 @@ EGIT_REPO_URI="https://github.com/moteus/lua-sendmail";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc"
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-lua/luasocket
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-HTML_DOCS=( "docs/" )
+READMES=( README.md )
+HTML_DOCS=( docs/ )
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins lua/sendmail.lua
-
-       base_src_install_docs
+each_lua_install() {
+       dolua lua/sendmail.lua
 }

diff --git a/dev-lua/lua-set/lua-set-9999.ebuild 
b/dev-lua/lua-set/lua-set-9999.ebuild
index 51b54ac..9c511a4 100644
--- a/dev-lua/lua-set/lua-set-9999.ebuild
+++ b/dev-lua/lua-set/lua-set-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI=5
 
-inherit toolchain-funcs eutils git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Straightforward Set library for Lua"
 HOMEPAGE="https://github.com/wscherphof/lua-set";
@@ -15,19 +16,8 @@ EGIT_REPO_URI="https://github.com/wscherphof/lua-set";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-DEPEND="
-       virtual/lua[luajit=]
-       virtual/pkgconfig
-"
-RDEPEND="
-       ${DEPEND}
-"
-
-src_install() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r src/*
+each_lua_install() {
+       dolua src/*
 }

diff --git a/dev-lua/lua-stdlib/lua-stdlib-9999.ebuild 
b/dev-lua/lua-stdlib/lua-stdlib-9999.ebuild
index 8052ea2..19ee21d 100644
--- a/dev-lua/lua-stdlib/lua-stdlib-9999.ebuild
+++ b/dev-lua/lua-stdlib/lua-stdlib-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit base git-r3 toolchain-funcs eutils
+VCS="git-r3"
+
+inherit lua
 
 DESCRIPTION="Standard Lua libraries"
 HOMEPAGE="https://github.com/lua-stdlib/lua-stdlib";
@@ -15,42 +17,22 @@ EGIT_REPO_URI="https://github.com/lua-stdlib/lua-stdlib";
 LICENSE="GPL"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}"
+IUSE=""
 
-DOCS=( "README.md" "NEWS" )
+READMES=( README.md NEWS.md HACKING )
 
-src_prepare() {
+all_lua_prepare() {
        if [[ -n ${EVCS_OFFLINE} ]]; then
                die "Unfortunately, upstream uses buildsystem which depends on 
external submodules, so you won't be able to build package in offline mode. 
Sorry."
        fi
 
-       local lua=lua
-       use luajit && lua=luajit
-       export LUA="${lua}"
-
        ./bootstrap --skip-rock-checks
 }
 
-src_configure() {
-       myeconfargs=(
-               "--datadir=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${LUA})" \
-               "--libdir=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${LUA})" \
-               "LUA_INCLUDE=-I$($(tc-getPKG_CONFIG) --variable includedir 
${LUA})"
-       )
-       base_src_configure "${myeconfargs[@]}"
-}
-
-src_compile() {
-       cd "${S}"
+each_lua_compile() {
        ./config.status --file=lib/std.lua
 }
 
-src_install() {
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${LUA})"
-       doins -r lib/std lib/std.lua
+each_lua_install() {
+       dolua lib/std lib/std.lua
 }

diff --git a/dev-lua/lua-zip/lua-zip-9999.ebuild 
b/dev-lua/lua-zip/lua-zip-9999.ebuild
index 936a609..0dc1b41 100644
--- a/dev-lua/lua-zip/lua-zip-9999.ebuild
+++ b/dev-lua/lua-zip/lua-zip-9999.ebuild
@@ -4,32 +4,31 @@
 
 EAPI="5"
 
-inherit cmake-utils git-r3
+VCS="git-r3"
+inherit cmake-utils lua
 
 DESCRIPTION="Lua bindings to libzip"
-HOMEPAGE="http://github.com/brimworks/lua-zip";
-EGIT_REPO_URI="git://github.com/brimworks/lua-zip.git"
+HOMEPAGE="https://github.com/brimworks/lua-zip";
+EGIT_REPO_URI="https://github.com/brimworks/lua-zip.git";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
 RDEPEND="
-       virtual/lua[luajit=]
-       dev-libs/libzip"
+       dev-libs/libzip
+"
+
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_prepare() {
-       mv *-${PN}-* "${S}"
-}
+READMES=( README )
 
-src_configure() {
-       local lua="lua"
-       use luajit && lua="luajit"
-       MYCMAKEARGS="-DINSTALL_CMOD='$($(tc-getPKG_CONFIG) --variable 
INSTALL_CMOD ${lua})'"
+each_lua_configure() {
+       mycmakeargs=(
+               -DINSTALL_CMOD="$(lua_get_pkgvar INSTALL_CMOD)"
+       )
        cmake-utils_src_configure
 }

diff --git a/dev-lua/luacrypto/luacrypto-9999.ebuild 
b/dev-lua/luacrypto/luacrypto-9999.ebuild
index 345d841..a4d2c88 100644
--- a/dev-lua/luacrypto/luacrypto-9999.ebuild
+++ b/dev-lua/luacrypto/luacrypto-9999.ebuild
@@ -4,11 +4,10 @@
 
 EAPI="5"
 
-LANGS=" en ru"
+LANGS=( "en" "ru" )
 
 VCS=git-r3
 IS_MULTILIB=true
-LUA_COMPAT="lua51 luajit2"
 
 inherit lua
 
@@ -21,8 +20,7 @@ EGIT_REPO_URI="https://github.com/msva/lua-crypto.git";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc +openssl gcrypt"
-IUSE+="${LANGS// / linguas_}"
+IUSE="doc +openssl gcrypt linguas_en linguas_ru"
 
 RDEPEND="
        openssl? ( >=dev-libs/openssl-0.9.7 )
@@ -35,7 +33,7 @@ READMES=( README )
 HTML_DOCS=()
 
 all_lua_prepare() {
-               for x in ${LANGS}; do
+               for x in ${LANGS[@]}; do
                        if use linguas_${x}; then
                                HTML_DOCS+=( doc/${x} )
                        fi
@@ -43,15 +41,16 @@ all_lua_prepare() {
 }
 
 each_lua_compile() {
-       _lua_setCFLAGS
-
        local engine="openssl";
        if use gcrypt; then
                engine="gcrypt"
                tc-getPROG GCRYPT_CONFIG libgcrypt-config
        fi
 
-       emake LUA_IMPL="${lua_impl}" CC="${CC}" CRYPTO_ENGINE="${engine}" 
CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" PKG_CONFIG="${PKG_CONFIG}" 
GCRYPT_CONFIG="${GCRYPT_CONFIG}"
+       lua_default \
+               LUA_IMPL="${lua_impl}" \
+               CRYPTO_ENGINE="${engine}" \
+               GCRYPT_CONFIG="${GCRYPT_CONFIG}"
 }
 
 each_lua_install() {

diff --git a/dev-lua/luadbi/luadbi-9999.ebuild 
b/dev-lua/luadbi/luadbi-9999.ebuild
index 8f3f922..c94c555 100644
--- a/dev-lua/luadbi/luadbi-9999.ebuild
+++ b/dev-lua/luadbi/luadbi-9999.ebuild
@@ -4,7 +4,7 @@
 
 EAPI="5"
 
-LUA_COMPAT="lua51 lua52 luajit2"
+LUA_COMPAT="lua51 luajit2"
 IS_MULTILIB=true
 VCS="mercurial"
 inherit lua
@@ -30,8 +30,6 @@ DEPEND="${RDEPEND}"
 #S="${WORKDIR}"
 
 each_lua_compile() {
-       _lua_setCFLAGS
-
        local drivers=()
        use mysql && drivers+=( "mysql" )
        use postgres && drivers+=( "psql" )
@@ -56,10 +54,7 @@ each_lua_compile() {
 
 #                      LUA_INC="$($(tc-getPKG_CONFIG) --cflags ${lua_impl})" \
 
-               [[ ${buildme} = "no" ]] || emake \
-                       CC="${CC}" \
-                       LDFLAGS="${LDFLAGS}" \
-                       CFLAGS="${CFLAGS}"  \
+               [[ ${buildme} = "no" ]] || lua_default \
                        PSQL_INC="-I/usr/include/postgresql/server" \
                        MYSQL_INC="-I/usr/include/mysql 
-L/usr/$(get_libdir)/mysql" \
                        ${driver}

diff --git a/dev-lua/luadoc/ChangeLog b/dev-lua/luadoc/ChangeLog
deleted file mode 100644
index 619ba39..0000000
--- a/dev-lua/luadoc/ChangeLog
+++ /dev/null
@@ -1,41 +0,0 @@
-# ChangeLog for dev-lua/luadoc
-# Copyright 1999-2013 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-lua/luadoc/ChangeLog,v 1.4 2013/03/14 
07:15:00 ago Exp $
-
-  14 Mar 2013; Agostino Sarubbo <[email protected]> luadoc-3.0.1.ebuild:
-  Stable for arm, wrt bug #461538
-
-  03 Feb 2013; Pacho Ramos <[email protected]> metadata.xml:
-  Cleanup due #22900
-
-  11 Jun 2011; Markus Meier <[email protected]> luadoc-3.0.1.ebuild:
-  add ~arm, bug #359137
-
-  05 Nov 2010; Rafael G. Martins <[email protected]>
-  +luadoc-3.0.1.ebuild, +metadata.xml:
-  Moved from dev-util to dev-lua. Fixed luafilesystem dependency.
-  Added myself to metadata.xml.
-
-  20 Dec 2008; nixnut <[email protected]> luadoc-3.0.1.ebuild:
-  Stable on ppc wrt bug 250796
-
-  17 Dec 2008; Markus Meier <[email protected]> luadoc-3.0.1.ebuild:
-  amd64/x86 stable, bug #250796
-
-  16 Dec 2008; Brent Baude <[email protected]> luadoc-3.0.1.ebuild:
-  stable ppc64, bug 250796
-
-  23 Sep 2008; Markus Rothe <[email protected]> luadoc-3.0.1.ebuild:
-  Added ~ppc
-
-  24 Aug 2008; Markus Rothe <[email protected]> luadoc-3.0.1.ebuild:
-  Added ~ppc64; bug #234421
-
-  14 Aug 2008; Alexis Ballier <[email protected]> luadoc-3.0.1.ebuild:
-  keyword ~x86-fbsd
-
-*luadoc-3.0.1 (08 Aug 2008)
-
-  08 Aug 2008; MATSUU Takuto <[email protected]> +metadata.xml,
-  +luadoc-3.0.1.ebuild:
-  Initial import.

diff --git a/dev-lua/luadoc/luadoc-3.0.1.ebuild 
b/dev-lua/luadoc/luadoc-3.0.1.ebuild
index f08ae6c..8418102 100644
--- a/dev-lua/luadoc/luadoc-3.0.1.ebuild
+++ b/dev-lua/luadoc/luadoc-3.0.1.ebuild
@@ -4,7 +4,7 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs
+inherit lua
 DESCRIPTION="LuaDoc is a documentation tool for Lua source code"
 HOMEPAGE="http://keplerproject.github.io/luadoc/";
 SRC_URI="http://luaforge.net/frs/download.php/3185/${P}.tar.gz";
@@ -12,35 +12,26 @@ 
SRC_URI="http://luaforge.net/frs/download.php/3185/${P}.tar.gz";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS="amd64 arm ppc ppc64 x86 ~x86-fbsd"
-IUSE="luajit"
+IUSE="doc"
 
 DEPEND=""
 RDEPEND="
-       virtual/lua[luajit=]
        dev-lua/luafilesystem
 "
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
+READMES=( README )
+HTML_DOCS=( doc/us/ )
 
-       echo "
-               PREFIX=/usr
-               LUA_LIBDIR=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})
-               LUA_DIR=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})
-               SYS_BINDIR= ${EROOT}/usr/bin
-       " > "${S}/config"
 
-       sed -r \
-               -e "1s|^(#!.* ) lua|\1 ${lua}|" \
-               -i src/luadoc.lua.in
-
-       # lua-5.1.3
+all_lua_prepare() {
+       # >=lua-5.1.3
        find . -name '*.lua' | xargs sed -e "s/gfind/gmatch/g" -i || die
 }
 
-src_install() {
-       emake DESTDIR="${D}" install || die
-       dodoc README
-       dohtml -r doc/us/*
+each_lua_install() {
+       dolua src/${PN}
+}
+
+all_lua_install() {
+       newbin src/${PN}.lua.in ${PN}
 }

diff --git a/dev-lua/luadoc/luadoc-9999.ebuild 
b/dev-lua/luadoc/luadoc-9999.ebuild
new file mode 100644
index 0000000..a860319
--- /dev/null
+++ b/dev-lua/luadoc/luadoc-9999.ebuild
@@ -0,0 +1,41 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: This ebuild is from Lua overlay; Bumped by mva; $
+
+EAPI="5"
+
+VCS="git-r3"
+inherit lua
+
+DESCRIPTION="LuaDoc is a documentation tool for Lua source code"
+HOMEPAGE="http://keplerproject.github.io/luadoc/";
+SRC_URI=""
+
+EGIT_REPO_URI="https://github.com/keplerproject/luadoc/";
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS=""
+IUSE="doc"
+
+DEPEND=""
+RDEPEND="
+       dev-lua/luafilesystem
+"
+
+READMES=( README )
+HTML_DOCS=( doc/us/ )
+
+
+all_lua_prepare() {
+       # >=lua-5.1.3
+       find . -name '*.lua' | xargs sed -e "s/gfind/gmatch/g" -i || die
+}
+
+each_lua_install() {
+       dolua src/${PN}
+}
+
+all_lua_install() {
+       newbin src/${PN}.lua.in ${PN}
+}

diff --git a/dev-lua/luaevent/files/gc-anchoring.patch 
b/dev-lua/luaevent/files/gc-anchoring.patch
new file mode 100644
index 0000000..37c604e
--- /dev/null
+++ b/dev-lua/luaevent/files/gc-anchoring.patch
@@ -0,0 +1,176 @@
+From f31efa83bd76ac375c00b31c30eb731cf4fd2226 Mon Sep 17 00:00:00 2001
+From: Matthew Wild <[email protected]>
+Date: Sat, 15 Jun 2013 22:51:03 +0100
+Subject: [PATCH] Ensure that callback object is always anchored to prevent the
+ possibility of it being garbage-collected before/while the C callback runs
+
+---
+ include/event_callback.h |   2 +
+ src/event_callback.c     | 110 ++++++++++++++++++++++++-----------------------
+ 2 files changed, 59 insertions(+), 53 deletions(-)
+
+diff --git a/include/event_callback.h b/include/event_callback.h
+index 9d68b26..6d7a2f1 100644
+--- a/include/event_callback.h
++++ b/include/event_callback.h
+@@ -28,7 +28,9 @@
+ typedef struct {
+       struct event ev;
+       le_base* base;
++      int selfRef;
+       int callbackRef;
++      int running;
+       struct timeval timeout;
+ } le_callback;
+ 
+diff --git a/src/event_callback.c b/src/event_callback.c
+index afe8773..9e705be 100644
+--- a/src/event_callback.c
++++ b/src/event_callback.c
+@@ -27,11 +27,10 @@
+ 
+ #define EVENT_CALLBACK_ARG_MT "EVENT_CALLBACK_ARG_MT"
+ 
+-void freeCallbackArgs(le_callback* arg, lua_State* L) {
+-      if(arg->base) {
+-              arg->base = NULL;
+-              event_del(&arg->ev);
+-              luaL_unref(L, LUA_REGISTRYINDEX, arg->callbackRef);
++void freeCallback(le_callback* cb, lua_State* L) {
++      if(cb->callbackRef != LUA_NOREF) {
++              luaL_unref(L, LUA_REGISTRYINDEX, cb->callbackRef);
++              cb->callbackRef = LUA_NOREF;
+       }
+ }
+ /* le_callback is allocated at the beginning of the coroutine in which it
+@@ -40,62 +39,64 @@ is used, no need to manually de-allocate */
+ /* Index for coroutine is fd as integer for *nix, as lightuserdata for Win */
+ void luaevent_callback(int fd, short event, void* p) {
+       le_callback* cb = p;
++      struct event *ev = &cb->ev;
+       lua_State* L;
+-      int ret;
++      int ret = -1;
+       struct timeval new_tv = { 0, 0 };
+-      le_base* base;
+-      assert(cb);
+-      if(!cb->base)
+-              return; /* Event has already been collected + destroyed */
+-      assert(cb->base->loop_L);
+-      L = cb->base->loop_L;
+-      lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef);
+-      lua_pushinteger(L, event);
+-      /* cb->base may be NULL after the pcall, if the event is destroyed */
+-      base = cb->base;
+-      if(lua_pcall(L, 1, 2, 0))
+-      {
+-              base->errorMessage = luaL_ref(L, LUA_REGISTRYINDEX);
+-              event_base_loopbreak(base->base);
+-              lua_pop(L, 1);
+-              return;
+-      }
+-      if(!cb->base) {
+-              lua_pop(L, 2);
+-              return; /* event was destroyed during callback */
+-      }
+-      /* If nothing is returned, re-use the old event value */
+-      ret = luaL_optinteger(L, -2, event);
+-      /* Clone the old timeout value in case a new one wasn't set */
+-      memcpy(&new_tv, &cb->timeout, sizeof(new_tv));
+-      if(lua_isnumber(L, -1)) {
+-              double newTimeout = lua_tonumber(L, -1);
+-              if(newTimeout > 0) {
+-                      load_timeval(newTimeout, &new_tv);
++      if(cb->callbackRef != LUA_NOREF) {
++              L = cb->base->loop_L;
++              lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef);
++              lua_pushinteger(L, event);
++              cb->running = 1;
++              if(lua_pcall(L, 1, 2, 0))
++              {
++                      cb->running = 0;
++                      cb->base->errorMessage = luaL_ref(L, LUA_REGISTRYINDEX);
++                      event_base_loopbreak(cb->base->base);
++                      lua_pop(L, 1); /* Pop the 'false' from pcall */
++                      return;
+               }
++              cb->running = 0;
++              /* If nothing is returned, re-use the old event value */
++              ret = luaL_optinteger(L, -2, event);
+       }
+-      lua_pop(L, 2);
+-      if(ret == -1) {
+-              freeCallbackArgs(cb, L);
+-      } else {
+-              struct event *ev = &cb->ev;
+-              int newEvent = ret;
+-              if( newEvent != event || (cb->timeout.tv_sec != new_tv.tv_sec 
|| cb->timeout.tv_usec != new_tv.tv_usec) ) {
+-                      struct timeval *ptv = &cb->timeout;
+-                      cb->timeout = new_tv;
+-                      if(!cb->timeout.tv_sec && !cb->timeout.tv_usec)
+-                              ptv = NULL;
+-                      event_del(ev);
+-                      event_set(ev, fd, EV_PERSIST | newEvent, 
luaevent_callback, cb);
+-                      /* Assume cannot set a new timeout.. */
+-                      event_add(ev, ptv);
++      if(ret == -1 || cb->callbackRef == LUA_NOREF) {
++              event_del(ev);
++              freeCallback(cb, L);
++              assert(cb->selfRef != LUA_NOREF);
++              luaL_unref(L, LUA_REGISTRYINDEX, cb->selfRef);
++              cb->selfRef = LUA_NOREF;
++      } else if( ret != event || (cb->timeout.tv_sec != new_tv.tv_sec || 
cb->timeout.tv_usec != new_tv.tv_usec) ) {
++              /* Clone the old timeout value in case a new one wasn't set */
++              memcpy(&new_tv, &cb->timeout, sizeof(new_tv));
++              if(lua_isnumber(L, -1)) {
++                      double newTimeout = lua_tonumber(L, -1);
++                      if(newTimeout > 0) {
++                              load_timeval(newTimeout, &new_tv);
++                      }
+               }
++              struct timeval *ptv = &cb->timeout;
++              cb->timeout = new_tv;
++              if(!cb->timeout.tv_sec && !cb->timeout.tv_usec)
++                      ptv = NULL;
++              event_del(ev);
++              event_set(ev, fd, EV_PERSIST | ret, luaevent_callback, cb);
++              /* Assume cannot set a new timeout.. */
++                      event_add(ev, ptv);
+       }
++      lua_pop(L, 2); /* Pop two results from call */
+ }
+ 
+ static int luaevent_cb_gc(lua_State* L) {
+-      le_callback* arg = luaL_checkudata(L, 1, EVENT_CALLBACK_ARG_MT);
+-      freeCallbackArgs(arg, L);
++      freeCallback(luaL_checkudata(L, 1, EVENT_CALLBACK_ARG_MT), L);
++      return 0;
++}
++
++static int luaevent_cb_close(lua_State* L) {
++      le_callback *cb = luaL_checkudata(L, 1, EVENT_CALLBACK_ARG_MT);
++      if(!cb->running)
++              event_del(&cb->ev);
++      freeCallback(cb, L); // Release reference to Lua callback
+       return 0;
+ }
+ 
+@@ -104,6 +105,9 @@ le_callback* event_callback_push(lua_State* L, int 
baseIdx, int callbackIdx) {
+       le_base *base = event_base_get(L, baseIdx);
+       luaL_checktype(L, callbackIdx, LUA_TFUNCTION);
+       cb = lua_newuserdata(L, sizeof(*cb));
++      lua_pushvalue(L, -1);
++      cb->selfRef = luaL_ref(L, LUA_REGISTRYINDEX);
++      cb->running = 0;
+       luaL_getmetatable(L, EVENT_CALLBACK_ARG_MT);
+       lua_setmetatable(L, -2);
+ 
+@@ -119,7 +123,7 @@ void event_callback_register(lua_State* L) {
+       lua_pushcfunction(L, luaevent_cb_gc);
+       lua_setfield(L, -2, "__gc");
+       lua_newtable(L);
+-      lua_pushcfunction(L, luaevent_cb_gc);
++      lua_pushcfunction(L, luaevent_cb_close);
+       lua_setfield(L, -2, "close");
+       lua_setfield(L, -2, "__index");
+       lua_pop(L, 1);

diff --git a/dev-lua/luaevent/files/lua5.3.patch 
b/dev-lua/luaevent/files/lua5.3.patch
new file mode 100644
index 0000000..a098601
--- /dev/null
+++ b/dev-lua/luaevent/files/lua5.3.patch
@@ -0,0 +1,11 @@
+--- include/luaevent.h 2015-09-26 13:26:21.928996805 +0600
++++ include/luaevent.h.new     2015-09-26 13:26:18.427133021 +0600
+@@ -26,7 +26,7 @@
+ #include <lua.h>
+ 
+ /* Workarounds for Lua 5.2 */
+-#if (LUA_VERSION_NUM == 502)
++#if (LUA_VERSION_NUM >= 502)
+ 
+ #undef lua_equal
+ #define lua_equal(L,idx1,idx2) lua_compare(L, (idx1), (idx2), LUA_OPEQ)

diff --git a/dev-lua/luaevent/luaevent-9999.ebuild 
b/dev-lua/luaevent/luaevent-9999.ebuild
index 144c297..7d18b55 100644
--- a/dev-lua/luaevent/luaevent-9999.ebuild
+++ b/dev-lua/luaevent/luaevent-9999.ebuild
@@ -4,43 +4,33 @@
 
 EAPI="5"
 
-inherit toolchain-funcs git-r3
+#LUA_COMPAT="lua51 lua52 luajit2"
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="libevent bindings for Lua"
 HOMEPAGE="http://luaforge.net/projects/luaevent 
http://repo.or.cz/w/luaevent.git";
-EGIT_REPO_URI="https://github.com/harningt/luaevent 
git://github.com/harningt/luaevent.git"
+EGIT_REPO_URI="https://github.com/harningt/luaevent";
 
 LICENSE="LGPL-2.1"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
 RDEPEND="
-       virtual/lua[luajit=]
        >=dev-libs/libevent-1.4
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       sed -i "s:^CFLAGS =:CFLAGS +=:" "${S}/Makefile" \
-               || die "sed failed"
-       sed -i "s:^LDFLAGS =:LDFLAGS +=:" "${S}/Makefile" \
-               || die "sed failed"
-       sed -i "/^LDFLAGS/a CC = $(tc-getCC)" "${S}/Makefile" \
-               || die "sed failed"
-       sed -i "s:^LUA_INC_DIR ?=.*:LUA_INC_DIR ?= $($(tc-getPKG_CONFIG) 
--variable includedir ${lua}):" "${S}/Makefile" \
-               || die "sed failed"
-       sed -i "s:^INSTALL_DIR_LUA ?=.*:INSTALL_DIR_LUA ?= 
$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua}):" "${S}/Makefile" \
-               || die "sed failed"
-       sed -i "s:^INSTALL_DIR_BIN ?=.*:INSTALL_DIR_BIN ?= 
$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua}):" "${S}/Makefile" \
-               || die "sed failed"
-}
+READMES=( README )
+
+PATCHES=( ${FILESDIR}/{gc-anchoring,lua5.3}.patch )
 
-src_install() {
-       emake DESTDIR="${D}" install || die "Install failed"
+each_lua_install() {
+       dolua lua/*
+       _dolua_insdir="${PN}" \
+       dolua core.so
 }

diff --git a/dev-lua/luaexpat/luaexpat-9999.ebuild 
b/dev-lua/luaexpat/luaexpat-9999.ebuild
index 3d06534..0ad94ea 100644
--- a/dev-lua/luaexpat/luaexpat-9999.ebuild
+++ b/dev-lua/luaexpat/luaexpat-9999.ebuild
@@ -4,7 +4,10 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs mercurial eutils
+LUA_COMPAT="lua51 luajit2"
+VCS="mercurial"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="XMPP client library written in Lua."
 HOMEPAGE="http://code.matthewwild.co.uk/";
@@ -14,36 +17,18 @@ EHG_REPO_URI="http://code.matthewwild.co.uk/lua-expat/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc"
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-libs/expat
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit
-       emake \
-               CC="$(tc-getCC)" \
-               LDFLAGS="${LDFLAGS}" \
-               CFLAGS="${CFLAGS}"  \
-               LUA_INC="$($(tc-getPKG_CONFIG) --cflags ${lua})" || die 
"Compiling failed"}
-}
+READMES=( README )
+HTML_DOCS=( doc/ )
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit
-       emake \
-               LUA_LMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})" \
-               LUA_CMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" \
-               DESTDIR="${D}" \
-               install || die "Install failed"
-       dodoc README || die
-       docompress -x "/usr/share/doc/${PF}/html"
-       dohtml -r doc/* || die
+each_lua_install() {
+       dolua src/lxp{,.so}
 }

diff --git a/dev-lua/luafilesystem/luafilesystem-9999.ebuild 
b/dev-lua/luafilesystem/luafilesystem-9999.ebuild
index 1f0191f..17d9d11 100644
--- a/dev-lua/luafilesystem/luafilesystem-9999.ebuild
+++ b/dev-lua/luafilesystem/luafilesystem-9999.ebuild
@@ -3,38 +3,32 @@
 # $Header: This ebuild is from Lua overlay; Bumped by mva; $
 
 EAPI="5"
-inherit multilib eutils git-r3 toolchain-funcs
+
+VCS="git-r3"
+IS_MULTILIB="true"
+inherit lua
 
 DESCRIPTION="File System Library for the Lua Programming Language"
-HOMEPAGE="http://keplerproject.github.com/luafilesystem/";
-EGIT_REPO_URI="git://github.com/keplerproject/luafilesystem.git"
+HOMEPAGE="https://keplerproject.github.io/luafilesystem/";
+EGIT_REPO_URI="https://github.com/keplerproject/luafilesystem.git";
 SRC_URI=""
 #SRC_URI="https://github.com/downloads/keplerproject/luafilesystem/${P}.tar.gz";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
-
-DEPEND="virtual/lua[luajit=]"
-RDEPEND="${DEPEND}"
+IUSE="doc"
 
-DOCS=( README )
+HTML_DOCS=( doc/us/ )
+READMES=( README )
 
-src_prepare() {
+all_lua_prepare() {
        sed \
-               -e "s|/usr/local|/usr|" \
-               -e "s|/lib|/$(get_libdir)|" \
-               -e "s|-O2|${CFLAGS}|" \
-               -e "/^LIB_OPTION/s|= |= ${LDFLAGS} |" \
-               -e "s|gcc|$(tc-getCC)|" \
+               -e 's|-O2|${CFLAGS}|' \
+               -e '/^LIB_OPTION/s|= |= ${LDFLAGS} |' \
                -i config || die "config fix failed"
-       use luajit && sed -r \
-               -e "s|(LUA_INC)=.*|\1 = $($(tc-getPKG_CONFIG) luajit --variable 
includedir)|" \
-               -i config || die "luajit include fix failed"
 }
 
-src_install() {
-       emake PREFIX="${ED}usr" install
-       use doc && dohtml doc/us/*
+each_lua_install() {
+       dolua src/lfs.so
 }

diff --git a/dev-lua/luahpdf/luahpdf-9999.ebuild 
b/dev-lua/luahpdf/luahpdf-9999.ebuild
index 68c5fa4..d680890 100644
--- a/dev-lua/luahpdf/luahpdf-9999.ebuild
+++ b/dev-lua/luahpdf/luahpdf-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="Lua binding to media-libs/libharu (PDF generator)"
 HOMEPAGE="https://github.com/jung-kurt/luahpdf";
@@ -15,27 +17,27 @@ EGIT_REPO_URI="https://github.com/msva/luahpdf";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        media-libs/libharu
 "
-DEPEND="${RDEPEND}
-       virtual/pkgconfig"
-
-DOCS=( README.md )
-
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       echo "\
-               PREFIX=/usr
-               LUALIB=$($(tc-getPKG_CONFIG) --libs ${lua})
-               LUAINC=$($(tc-getPKG_CONFIG) --cflags ${lua})
-               MODDIR=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})
-               DOCDIR=\$(PREFIX)/share/doc/${P}
-               LUA=luajit
-       " > .config
+DEPEND="${RDEPEND}"
+
+DOCS=( README.md doc/text/. )
+HTML_DOCS=( doc/html/. )
+EXAMPLES=( demo/. )
+
+all_lua_prepare() {
+       sed -i -r \
+       -e 's#(_COMPILE=)cc#\1$(CC)#' \
+       -e 's#(_LINK=)cc#\1$(CC)#' \
+       -e 's#(_REPORT=).*#\1#' \
+       Makefile
+
+       lua_default
+}
+
+each_lua_install() {
+       dolua hpdf.so
 }

diff --git a/dev-lua/lualdap/lualdap-9999.ebuild 
b/dev-lua/lualdap/lualdap-9999.ebuild
index 18c193c..7a7b5a6 100644
--- a/dev-lua/lualdap/lualdap-9999.ebuild
+++ b/dev-lua/lualdap/lualdap-9999.ebuild
@@ -4,34 +4,53 @@
 
 EAPI="5"
 
-inherit base git-r3 toolchain-funcs
+VCS="git-r3"
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="Lua driver for LDAP"
 HOMEPAGE="https://github.com/mwild1/lualdap/";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/mwild1/lualdap.git 
git://github.com/mwild1/lualdap.git"
+EGIT_REPO_URI="https://github.com/mwild1/lualdap.git";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        net-nds/openldap
 "
 DEPEND="${RDEPEND}"
 
-DOCS=( "README" )
+READMES=( README )
+EXAMPLES=( tests/ )
+HTML_DOCS=( doc/us/ )
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
+all_lua_prepare() {
+       sed -i -e 'd' config
+       lua_default
+}
+
+each_lua_configure() {
+       local luav="$(lua_get_abi)"
+       luav="${luav//./0}"
+       myeconfargs=()
+       myeconfargs+=(
+               OPENLDAP_LIB="-lldap"
+               LUA_VERSION_LUM="${luav}"
+               LIBNAME="${PN}.so"
+               LIB_OPTION='$(LDFLAGS)'
+       )
+       lua_default
+}
+
+#each_lua_test() {
+#      Requires LDAP server
+#      ${LUA} tests/test.lua <hostname>[:port] <base> [<who> [<password>]]
+#}
 
-       sed -r \
-               -e "s#^(LUA_INC).*#\1=$($(tc-getPKG_CONFIG) --variable 
includedir ${lua})#" \
-               -e "s#^(LUA_LIBDIR).*#\1=$($(tc-getPKG_CONFIG) --variable 
INSTALL_CMOD ${lua})#" \
-               -e "s#^(CC).*#\1=$(tc-getCC)#" \
-               -i config
+each_lua_install() {
+       dolua src/${PN}.so
 }

diff --git a/dev-lua/luamacro/luamacro-9999.ebuild 
b/dev-lua/luamacro/luamacro-9999.ebuild
index 199d467..b9bc786 100644
--- a/dev-lua/luamacro/luamacro-9999.ebuild
+++ b/dev-lua/luamacro/luamacro-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="library and driver script for preprocessing and evaluating Lua 
code"
 HOMEPAGE="https://github.com/stevedonovan/LuaMacro/";
@@ -15,32 +16,19 @@ EGIT_REPO_URI="https://github.com/stevedonovan/LuaMacro/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
 RDEPEND="
-       virtual/lua[luajit=]
+       || (
+               dev-lua/lpeg
+               dev-lua/lulpeg[lpeg_replace]
+       )
 "
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit
 
-       sed -r \
-               -e "1s#(/usr/bin/env) lua#\1 ${lua}#" \
-               -i luam
+each_lua_install() {
+       dolua macro{,.lua}
 }
 
-
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r macro macro.lua
-
+all_lua_install() {
        dobin luam
 }

diff --git a/dev-lua/luamongo/luamongo-9999.ebuild 
b/dev-lua/luamongo/luamongo-9999.ebuild
index 234521a..687c139 100644
--- a/dev-lua/luamongo/luamongo-9999.ebuild
+++ b/dev-lua/luamongo/luamongo-9999.ebuild
@@ -3,39 +3,57 @@
 # $Header: This ebuild is from Lua overlay; Bumped by mva; $
 
 EAPI="5"
+VCS="git-r3"
 
-inherit base git-r3 toolchain-funcs
+# Incompatible with current mongo-driver
+
+# FIXME: when libmongo-drivers will be multilib
+#IS_MULTILIB=true
+
+inherit lua
 
 DESCRIPTION="Lua driver for MongoDB"
 HOMEPAGE="https://github.com/mwild1/luamongo/";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/mwild1/luamongo 
git://github.com/mwild1/luamongo"
+EGIT_REPO_URI="https://github.com/moai/luamongo";
 
 LICENSE="MIT"
 SLOT="0"
-KEYWORDS=""
-IUSE="luajit"
+KEYWORDS="-*"
+IUSE="+examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-libs/boost
-       dev-db/mongodb[sharedclient]
+       dev-libs/mongo-cxx-driver
 "
+#      dev-db/mongodb[sharedclient]
 DEPEND="${RDEPEND}"
 
-DOCS=( "README.md" )
+READMES=( README.md )
+EXAMPLES=( tests/ )
+
+all_lua_prepare() {
+       # Preparing makefile to default_prepare magic fix
+       sed -i -r \
+               -e '/^MONGOFLAGS/d' \
+               -e '/^LUAPKG/d' \
+               -e '/^LUAFLAGS/d' \
+               -e '/if . -z /d' \
+               -e 's#\$\(shell pkg-config --libs \$\(LUAPKG\)\)#-llua#' \
+               Makefile
+
+       lua_default
+}
 
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake LUA_INC="-I$($(tc-getPKG_CONFIG) --variable includedir ${lua})"
+each_lua_configure() {
+       myeconfargs=()
+       myeconfargs+=(
+               LUAPKG="$(lua_get_lua)"
+       )
+       lua_default
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})"
-       doins "mongo.so"
-       base_src_install_docs
+each_lua_install() {
+       dolua mongo.so
 }

diff --git a/dev-lua/luancurses/luancurses-9999.ebuild 
b/dev-lua/luancurses/luancurses-9999.ebuild
deleted file mode 100644
index a19a8da..0000000
--- a/dev-lua/luancurses/luancurses-9999.ebuild
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright 1999-2015 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: This ebuild is from Lua overlay; Bumped by mva; $
-
-EAPI="5"
-
-inherit eutils git-r3
-
-DESCRIPTION="Lua NCurses Library"
-HOMEPAGE="https://github.com/msva/lua-ncurses";
-SRC_URI=""
-
-EGIT_REPO_URI="git://github.com/msva/lua-ncurses.git"
-
-LICENSE="MIT"
-SLOT="0"
-KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-       sys-libs/ncurses
-"
-DEPEND="${RDEPEND}
-       virtual/pkgconfig"
-
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       echo LUA_IMPL="${lua}" > .config
-}

diff --git a/dev-lua/luancurses/metadata.xml b/dev-lua/luancurses/metadata.xml
deleted file mode 100644
index 23da526..0000000
--- a/dev-lua/luancurses/metadata.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
-<pkgmetadata>
-<maintainer>
- <email>[email protected]</email>
- <description>
-       If you have any issues, please contact me, or try to find me in IRC on 
Freenode, OFTC or RusNet.
- </description> 
- <name>Vadim A. Misbakh-Soloviov</name>
-</maintainer>
-<longdescription>FIXME</longdescription> 
-<use>
-</use>
-</pkgmetadata>

diff --git a/dev-lua/luaposix/luaposix-9999.ebuild 
b/dev-lua/luaposix/luaposix-9999.ebuild
index 95c2cf0..44ab46d 100644
--- a/dev-lua/luaposix/luaposix-9999.ebuild
+++ b/dev-lua/luaposix/luaposix-9999.ebuild
@@ -4,7 +4,11 @@
 
 EAPI="5"
 
-inherit base git-r3 toolchain-funcs eutils
+VCS="git-r3"
+IS_MULTILIB=true
+#AT_NOEAUTOMAKE=yes
+
+inherit autotools lua
 
 DESCRIPTION="POSIX binding, including curses, for Lua 5.1 and 5.2"
 HOMEPAGE="https://github.com/luaposix/luaposix";
@@ -15,32 +19,35 @@ EGIT_REPO_URI="https://github.com/luaposix/luaposix.git";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit ncurses"
+IUSE="doc +examples ncurses"
 
 RDEPEND="
-       virtual/lua[bit,luajit=]
+       virtual/lua[bit]
        ncurses? ( sys-libs/ncurses )
 "
-#      dev-lua/ldoc
+
+DEPEND="
+       ${RDEPEND}
+       doc? ( dev-lua/ldoc )
+       dev-libs/gnulib
+"
 #      dev-lua/specl
 #      dev-lua/lyaml
 
-DEPEND="${RDEPEND}"
+READMES=( README.md NEWS.md )
+EXAMPLES=( examples/ )
+HTML_DOCS=( doc/ )
 
-DOCS=( "README.md" "NEWS" )
-
-src_prepare() {
-       if [[ -n ${EVCS_OFFLINE} ]]; then
-               die "Unfortunately, upstream uses buildsystem which depends on 
external submodules, so you won't be able to build package in offline mode. 
Sorry."
-       fi
+all_lua_prepare() {
+       [[ -n "${EGIT_OFFLINE}" ]] && die "Upstream unfortunately uses 
buildsystem, which requires to fetch some git "
 
+       # we'll check for ldoc ourslves
        sed -r \
                -e "s#(AC_PATH_PROG\(\[LDOC\],).*#\1 [echo], [false]\)#" \
                -e "s#(AM_CONDITIONAL\(\[HAVE_LDOC\],).*#\1 [false]\)#" \
                -i configure.ac
 
-# kludgy, but idk, how to drop that f**n broken documentation build
-#              -e 's#^(allhtml =).*#\1#' \
+       # we don't need and install documentation for each target, so we'll 
take care on this ourselves
        sed -r \
                -e 's#doc/.*html##' \
                -e 's#doc/.*css##' \
@@ -49,20 +56,46 @@ src_prepare() {
                -e 's#\$\(dist_.*_DATA\)##g' \
                -i local.mk
 
-       ./bootstrap --skip-rock-checks
+       myeprepareargs=(
+               --skip-rock-checks
+               --gnulib-srcdir=/usr/share/gnulib
+               -Wnone
+       )
+               #--skip-git
+#      AT_NOEAUTOMAKE=yes
+#      gnulib-tool  --no-changelog --avoid=dummy --aux-dir=build-aux 
--m4-base=m4 --source-base=unused --libtool --symlink --import warnings 
manywarnings
+#      eautoreconf
+
+       ./bootstrap "${myeprepareargs[@]}"
+
+       # Unneded wrapper over ./bootstrap+./configure
+       rm GNUmakefile; ls
 }
 
-src_configure() {
-       local lua=lua;
-       use luajit && lua=luajit;
+all_lua_compile() {
+       use doc && (
+               cp build-aux/config.ld.in build-aux/config.ld
+               cp lib/posix.lua.in lib/posix/init.lua
+
+               sed -r \
+                       -e "s/@PACKAGE_STRING@/${P}/" \
+                       -i build-aux/config.ld lib/posix/init.lua
+
+               cd build-aux && ldoc -d ../doc . && cd ..
+
+               rm build-aux/config.ld lib/posix/init.lua
+       )
+}
 
+each_lua_configure() {
        myeconfargs=(
-               "--datadir=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})" \
-               "--libdir=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" \
-               "$(use_with ncurses)"\
-               LUA="${lua}" \
-               LUA_INCLUDE="-I$($(tc-getPKG_CONFIG) --variable includedir 
${lua})"
+               "$(use_with ncurses)" \
+               LUA="$(lua_get_lua)" \
+               LUA_INCLUDE="$(lua_get_pkgvar --cflags --cflags-only-I)" \
+               ax_cv_lua_luadir="$(lua_get_pkgvar INSTALL_LMOD)" \
+               ax_cv_lua_luaexecdir="$(lua_get_pkgvar INSTALL_CMOD)"
+               
        )
-       base_src_configure "${myeconfargs[@]}"
+       base_src_configure
 }
 

diff --git a/dev-lua/luarocks/luarocks-9999.ebuild 
b/dev-lua/luarocks/luarocks-9999.ebuild
index 0bd3579..a82469a 100644
--- a/dev-lua/luarocks/luarocks-9999.ebuild
+++ b/dev-lua/luarocks/luarocks-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A deployment and management system for Lua modules"
 HOMEPAGE="http://www.luarocks.org";
@@ -13,39 +14,51 @@ 
EGIT_REPO_URI="https://github.com/keplerproject/luarocks.git";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="curl openssl luajit"
+IUSE="curl openssl"
 
 DEPEND="
-       virtual/lua[luajit=]
        curl? ( net-misc/curl )
+       !curl? ( net-misc/wget )
        openssl? ( dev-libs/openssl )
+       !openssl? ( sys-apps/coreutils )
 "
-RDEPEND="${DEPEND}
+RDEPEND="
+       ${DEPEND}
        app-arch/unzip
-       virtual/pkgconfig
 "
 
-src_configure() {
-       local lua=lua md5="md5sum" downloader="wget"
+all_lua_prepare() {
+       sed -r \
+               -e "/die.*Unknown flag:/d" \
+               -i configure
+}
+
+each_lua_configure() {
+       local md5 downloader lua incdir
+       md5="md5sum"
+       downloader="wget"
+       lua="$(lua_get_lua)"
+       incdir=$(lua_get_pkgvar includedir)
 
        use curl && downloader="curl"
        use openssl && md5="openssl"
-       use luajit && lua="luajit"
-
-       # econf doesn't work b/c it passes variables the custom configure can't
-       # handle
-       ./configure \
-                       --prefix=/usr \
-                       --with-lua=/usr \
-                       --with-lua-lib=/usr/$(get_libdir) \
-                       --rocks-tree=/usr \
-                       --with-downloader="${downloader}" \
-                       --with-md5-checker="${md5}" \
-                       $(use luajit && echo "--lua-suffix=jit") \
-                       --with-lua-include="$($(tc-getPKG_CONFIG) --variable 
includedir ${lua})" \
-                       --force-config || die "configure failed"
+
+       myeconfargs=()
+       myeconfargs+=(
+               --prefix=/usr
+               --with-lua=/usr
+               --with-lua-lib="/usr/$(get_libdir)"
+               --rocks-tree=/usr
+               --with-downloader="${downloader}"
+               --with-md5-checker="${md5}"
+               --lua-suffix="${lua//lua}"
+               --lua-version="$(lua_get_abi)"
+               --with-lua-include="${incdir}"
+               --sysconfdir=/etc/${PN}
+       )
+       lua_default
 }
 
 pkg_preinst() {
-       find "${D}" -type f | xargs sed -i -e "s:${D}::g" || die "sed failed"
+       find "${D}" -type f | xargs sed -e "s:${D}::g" -i || die "sed failed"
 }

diff --git a/dev-lua/luasec/luasec-9999.ebuild 
b/dev-lua/luasec/luasec-9999.ebuild
index 7350f18..271acc9 100644
--- a/dev-lua/luasec/luasec-9999.ebuild
+++ b/dev-lua/luasec/luasec-9999.ebuild
@@ -4,7 +4,10 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs eutils git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+
+inherit lua
 
 DESCRIPTION="Lua binding for OpenSSL library to provide TLS/SSL communication."
 HOMEPAGE="http://www.inf.puc-rio.br/~brunoos/luasec/";
@@ -15,38 +18,42 @@ EGIT_REPO_URI="https://github.com/brunoos/luasec";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="examples luajit"
+IUSE="+examples"
 
 RDEPEND="
-       virtual/lua[luajit]
        dev-lua/luasocket
        dev-libs/openssl
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-
-src_prepare() {
-       epatch "${FILESDIR}/fix_removed_destdir_support.patch" || die 
"Probably, Upstream finally returned DESTDIR instalation back. Please, report 
that."
+all_lua_prepare() {
+       sed -i -r \
+               -e 's#(MAKE\)).*(install)#\1 \2#' \
+               Makefile
+#      epatch "${FILESDIR}/fix_removed_destdir_support.patch" || die 
"Probably, Upstream finally returned DESTDIR instalation back. Please, report 
that."
+       cd src
+       lua_default
 }
 
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake \
-               CC="$(tc-getCC)" \
-               LD="$(tc-getCC) -shared" \
-               LUAPATH="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})" 
\
-               LUACPATH="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" \
-               INC_PATH="-I$($(tc-getPKG_CONFIG) --variable includedir 
${lua})" \
-               linux \
-               || die
+each_lua_configure() {
+       cd src
+       myeconfargs=()
+       myeconfargs+=(
+               LD='$(CC)'
+               LUAPATH="\$(DESTDIR)/$(lua_get_pkgvar INSTALL_LMOD)"
+               LUACPATH="\$(DESTDIR)/$(lua_get_pkgvar INSTALL_CMOD)"
+       )
+               lua_default
 }
 
-src_install() {
-       emake DESTDIR="${D}" install || die "Install failed"
-       docompress -x /usr/share/doc/${PF}/samples
-       use examples && dodoc -r samples
+each_lua_compile() {
+       lua_default linux
 }
+
+#each_lua_install() {
+#      dolua ssl.so ssl.lua
+#      _dolua_insdir=ssl \
+#      dolua https.lua
+#}

diff --git a/dev-lua/luasignal/luasignal-9999.ebuild 
b/dev-lua/luasignal/luasignal-9999.ebuild
deleted file mode 100644
index 6b175a5..0000000
--- a/dev-lua/luasignal/luasignal-9999.ebuild
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright 1999-2015 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: This ebuild is from Lua overlay; Bumped by mva; $
-
-EAPI="5"
-
-inherit multilib eutils git-r3
-
-DESCRIPTION="Lua signal Library"
-HOMEPAGE="https://github.com/msva/lua-signal";
-SRC_URI=""
-
-EGIT_REPO_URI="https://github.com/msva/lua-signal.git";
-
-LICENSE="MIT"
-SLOT="0"
-KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_configure() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       echo "LUA_IMPL=${lua}" > .config
-}

diff --git a/dev-lua/luasignal/metadata.xml b/dev-lua/luasignal/metadata.xml
deleted file mode 100644
index 23da526..0000000
--- a/dev-lua/luasignal/metadata.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
-<pkgmetadata>
-<maintainer>
- <email>[email protected]</email>
- <description>
-       If you have any issues, please contact me, or try to find me in IRC on 
Freenode, OFTC or RusNet.
- </description> 
- <name>Vadim A. Misbakh-Soloviov</name>
-</maintainer>
-<longdescription>FIXME</longdescription> 
-<use>
-</use>
-</pkgmetadata>

diff --git a/dev-lua/luasocket/luasocket-9999.ebuild 
b/dev-lua/luasocket/luasocket-9999.ebuild
index 3283ce2..f42088f 100644
--- a/dev-lua/luasocket/luasocket-9999.ebuild
+++ b/dev-lua/luasocket/luasocket-9999.ebuild
@@ -4,45 +4,83 @@
 
 EAPI="5"
 
-inherit base multilib toolchain-funcs flag-o-matic eutils git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+
+inherit lua
 
 DESCRIPTION="Networking support library for the Lua language."
 HOMEPAGE="http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/";
-EGIT_REPO_URI="https://github.com/diegonehab/luasocket 
git://github.com/diegonehab/luasocket"
+EGIT_REPO_URI="https://github.com/diegonehab/luasocket";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="debug luajit"
-
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-DOCS=( "NEW" "README" )
-HTML_DOCS=( "doc/" )
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       use debug && export DEBUG="DEBUG"
-
-       emake linux \
-               prefix="/usr" \
-               LUAINC_linux="$($(tc-getPKG_CONFIG) --variable includedir 
${lua})" \
-               LUALIB_linux="/usr/$(get_libdir)" \
-               CC="$(tc-getCC)" \
-               LD="$(tc-getCC) -shared"
+IUSE="doc debug"
+
+DOCS=( NEW README )
+HTML_DOCS=( doc/ )
+
+all_lua_prepare() {
+       lua_default
+
+       # dirty hack for crazy buildsystem
+       sed -r \
+               -e '1iinclude ../.lua_eclass_config' \
+               -e '/^MYCFLAGS=/d' \
+               -e '/^MYLDFLAGS=/d' \
+               -e '/^CC=/d' \
+               -e '/^LD=/d' \
+               -e '/^INSTALL_TOP=/d' \
+               -i src/makefile
+}
+
+each_lua_configure() {
+       local luav="${lua_impl}"
+       luav="${luav##lua}"
+
+       myeconfargs=(
+               "LUAV=${luav}"
+               "CDIR=$(lua_get_pkgvar INSTALL_CMOD)"
+               "LDIR=$(lua_get_pkgvar INSTALL_LMOD)"
+               'INSTALL_TOP=$(DESTDIR)'
+               "COMPAT=COMPAT"
+               LD='$(CC)'
+       )
+
+       use debug && \
+               myeconfargs+=( "DEBUG=DEBUG" )
+
+       use elibc_Winnt && \
+               myeconfargs+=( "PLAT=win32" )
+
+       use elibc_Cygwin && \
+               myeconfargs+=( "PLAT=mingw" )
+
+       use elibc_Darwin && (
+               myeconfargs+=(
+                       "PLAT=macosx"
+                       LDFLAGS="-bundle -undefined dynamic_lookup"
+               )
+               sed \
+                       -e 's#-[fD]PIC#-fno-common#g' \
+                       -i .lua_eclass_config
+       )
+
+       lua_default
+
+       # dirty hack for crazy buildsystem
+       sed -r \
+               -e 's#(^CFLAGS=)#MY\1#' \
+               -e 's#(^LDFLAGS=)#MY\1#' \
+               -i .lua_eclass_config
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake install \
-               INSTALL_TOP_LDIR="${D}/$($(tc-getPKG_CONFIG) --variable 
INSTALL_LMOD ${lua})" \
-               INSTALL_TOP_CDIR="${D}/$($(tc-getPKG_CONFIG) --variable 
INSTALL_CMOD ${lua})"
+each_lua_install() {
+       myeinstallargs=()
+       if ! use elibc_Winnt && ! use elibc_Cygwin; then
+               myeinstallargs+=( "install-unix" )
+       fi
 
-       base_src_install_docs
+       lua_default
 }

diff --git a/dev-lua/luaunbound/luaunbound-9999.ebuild 
b/dev-lua/luaunbound/luaunbound-9999.ebuild
index 063bc16..0ac8958 100644
--- a/dev-lua/luaunbound/luaunbound-9999.ebuild
+++ b/dev-lua/luaunbound/luaunbound-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs flag-o-matic eutils mercurial
+VCS="mercurial"
+
+inherit lua
 
 DESCRIPTION="LuaJIT FFI bindings to net-dns/unbound"
 HOMEPAGE="http://code.zash.se/luaunbound/";
@@ -13,46 +15,44 @@ EHG_REPO_URI="http://code.zash.se/luaunbound/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="prosody luajit"
+IUSE="prosody"
 
 RDEPEND="
-       virtual/lua[luajit=]
        net-dns/unbound
        prosody? ( net-im/prosody )
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-DOCS=( "README.markdown" )
+READMES=( README.markdown )
+
+#all_lua_prepare() {
+#      
+#}
 
-src_compile() {
+each_lua_compile() {
        # If we have LuaJIT in the system — we'd prefer FFI version
-       use luajit || emake
+       if ! lua_is_jit; then
+               lua_default
+       fi
+
+       if use prosody; then
+               lua_default prosody
+       fi
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       if use luajit; then
-               insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})/util/"
-               newins util.lunbound.lua lunbound.lua
-               newins util.dns.lua dns.lua
-# something else to be useful outside prosody?..
+each_lua_install() {
+       if lua_is_jit; then
+               newlua_jit util.lunbound.lua lunbound.lua
        else
-               insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})/util/"
-               doins "lunbound.so"
-               insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})/util/"
-               newins util.dns.lua dns.lua
+               dolua "lunbound.so"
        fi
-# Actually, it is possible to patch prosody ebuild to remove dns utils if 
using it with lubound, just I'm not sure it is a best way.
+
        if use prosody; then
-               ./squish.sh > use_unbound.lua
                insinto "/etc/jabber"
                doins "use_unbound.lua" 
        fi
-       base_src_install_docs
 }
 
 pkg_postinst() {

diff --git a/dev-lua/luaxml/luaxml-9999.ebuild 
b/dev-lua/luaxml/luaxml-9999.ebuild
index 75f852e..feaf2d6 100644
--- a/dev-lua/luaxml/luaxml-9999.ebuild
+++ b/dev-lua/luaxml/luaxml-9999.ebuild
@@ -4,7 +4,12 @@
 
 EAPI="5"
 
-inherit cmake-utils git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+
+LUA_COMPAT="lua51 luajit2"
+
+inherit cmake-utils lua
 
 DESCRIPTION="A minimal set of XML processing function in Lua, with simple 
mapping between XML and Lua tables"
 HOMEPAGE="http://github.com/LuaDist/luaxml";
@@ -13,20 +18,14 @@ EGIT_REPO_URI="https://github.com/msva/luaxml";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}
-               virtual/pkgconfig"
+IUSE=""
 
-src_configure() {
-       local lua="lua"
-       use luajit && lua="luajit"
+each_lua_configure() {
        mycmakeargs=(
-               -DINSTALL_CMOD=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua}) \
-               -DINSTALL_LMOD=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})
+               -DINSTALL_CMOD="$(lua_get_pkgvar INSTALL_CMOD)"
+               -DINSTALL_LMOD="$(lua_get_pkgvar INSTALL_LMOD)"
        )
+
        cmake-utils_src_configure
 }
+

diff --git a/dev-lua/luazip/luazip-9999.ebuild 
b/dev-lua/luazip/luazip-9999.ebuild
index 0196764..cd4cb4e 100644
--- a/dev-lua/luazip/luazip-9999.ebuild
+++ b/dev-lua/luazip/luazip-9999.ebuild
@@ -4,33 +4,47 @@
 
 EAPI="5"
 
-inherit git-r3 toolchain-funcs
+VCS="git-r3"
+
+# FIXME
+#IS_MULTILIB=true
+inherit lua
+
 
 DESCRIPTION="Lua bindings to zziplib"
-HOMEPAGE="https://github.com/luaforge/luazip";
-EGIT_REPO_URI="https://github.com/luaforge/luazip.git";
+HOMEPAGE="https://github.com/msva/luazip";
+EGIT_REPO_URI="https://github.com/msva/luazip";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-libs/zziplib
 "
 DEPEND="
        ${RDEPEND}
-       virtual/pkgconfig
 "
 
-src_configure() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       sed -r \
-               -e "s#(LUA_INC)=.*#\1=$($(tc-getPKG_CONFIG) --variable 
includedir ${lua})#" \
-               -e 's#(PREFIX) =.*#\1=$(DESTDIR)/usr#' \
-               -e "s#(ZZLIB_INC)=.*#\1=/usr/include#" \
-               -e "s#(LUA_VERSION_NUM)=.*#\1=510#" \
-               -i config
+READMES=( README )
+HTML_DOCS=( doc/us/ )
+EXAMPLES=( tests/ )
+
+all_lua_prepare() {
+       sed -i -e 'd' config
+       lua_default
+}
+
+each_lua_configure() {
+       myeconfargs=()
+       myeconfargs+=(
+               'LIB_OPTION=$(LDFLAGS)'
+               'LIBNAME=zip.so'
+       )
+       lua_default
+}
+
+each_lua_install() {
+       dolua src/*.so
 }

diff --git a/dev-lua/lullaby/lullaby-9999.ebuild 
b/dev-lua/lullaby/lullaby-9999.ebuild
index f66660e..4cbb832 100644
--- a/dev-lua/lullaby/lullaby-9999.ebuild
+++ b/dev-lua/lullaby/lullaby-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A stream-based HTML template library for Lua."
 HOMEPAGE="https://github.com/hugomg/lullaby";
@@ -15,24 +16,11 @@ EGIT_REPO_URI="https://github.com/hugomg/lullaby";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc"
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
+READMES=( README.md )
+HTML_DOCS=( htmlspec/. )
 
-HTML_DOCS=( "htmlspec/" )
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r lullaby.lua lullaby
-
-       base_src_install_docs
+each_lua_install() {
+       dolua lullaby.lua lullaby
 }

diff --git a/dev-lua/lulpeg/lulpeg-9999.ebuild 
b/dev-lua/lulpeg/lulpeg-9999.ebuild
index d754b9e..8d499bc 100644
--- a/dev-lua/lulpeg/lulpeg-9999.ebuild
+++ b/dev-lua/lulpeg/lulpeg-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A pure Lua port of LPeg, Roberto Ierusalimschy's Parsing 
Expression Grammars library"
 HOMEPAGE="https://github.com/pygy/LuLPeg";
@@ -15,29 +16,19 @@ EGIT_REPO_URI="https://github.com/pygy/LuLPeg";
 LICENSE="WTFPL"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit +lpeg_replace"
+IUSE="lpeg_replace"
 
-RDEPEND="
-       virtual/lua[luajit=]
-       lpeg_replace? ( !dev-lua/lpeg )
-"
-DEPEND="${RDEPEND}"
+READMES=( README.md TODO.md ABOUT )
 
-src_prepare() {
-       epatch_user
+each_lua_compile() {
+       #paranoid mode:
+       rm "${PN}.lua" && (
+               cd src
+               "${LUA}" ../scripts/pack.lua > ../"${PN}.lua"
+       )
 }
 
-src_install() {
-       local pkg_n=lulpeg
-       local lua=lua
-       use luajit && lua=luajit
-
-       use lpeg_replace && pkg_n=lpeg
-
-       mv src "${pkg_n}"
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r "${pkg_n}"
-
-       dodoc README.md TODO.md ABOUT || die "dodoc failed"
+each_lua_install() {
+       dolua "${PN}".lua
+       use lpeg_replace && newlua "${PN}.lua" lpeg.lua
 }

diff --git a/dev-lua/lunit/lunit-9999.ebuild b/dev-lua/lunit/lunit-9999.ebuild
index 31d755f..ab9756f 100644
--- a/dev-lua/lunit/lunit-9999.ebuild
+++ b/dev-lua/lunit/lunit-9999.ebuild
@@ -4,10 +4,11 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A unit testing framework for Lua"
-HOMEPAGE="https://github.com/dcurrie/${PN}";
+HOMEPAGE="https://github.com/dcurrie/lunit";
 SRC_URI=""
 
 EGIT_REPO_URI="https://github.com/dcurrie/${PN}";
@@ -15,41 +16,15 @@ EGIT_REPO_URI="https://github.com/dcurrie/${PN}";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit +examples"
+IUSE="+examples"
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
+EXAMPLES=( examples/. )
+READMES=( README README.lunitx DOCUMENTATION )
 
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       sed -r \
-               -e "s/^(interpreter)=.*/\1=${lua}/" \
-               -i extra/lunit.sh
+each_lua_install() {
+       dolua lua/*
 }
 
-src_compile() { :; }
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r lua/*
-
+all_lua_install() {
        newbin "extra/${PN}.sh" "${PN}"
-
-       if use samples; then
-               docompress -x "/usr/share/doc/${PF}/examples"
-               dodoc -r examples
-       fi
-
-       dodoc DOCUMENTATION
 }

diff --git a/dev-lua/lyaml/lyaml-9999.ebuild b/dev-lua/lyaml/lyaml-9999.ebuild
index f09c5e6..4dcd0fa 100644
--- a/dev-lua/lyaml/lyaml-9999.ebuild
+++ b/dev-lua/lyaml/lyaml-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs eutils git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="LibYAML binding for Lua."
 HOMEPAGE="https://github.com/gvvaughan/lyaml";
@@ -15,33 +16,69 @@ EGIT_REPO_URI="https://github.com/gvvaughan/lyaml";
 LICENSE="GPL"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE="doc"
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-libs/libyaml
 "
 DEPEND="${RDEPEND}"
 
-DOCS=( "README.md" "NEWS" )
+READMES=( README.md NEWS.md )
+HTML_DOCS=( doc/. )
 
-src_prepare() {
+all_lua_prepare() {
        if [[ -n ${EVCS_OFFLINE} ]]; then
                die "Unfortunately, upstream uses buildsystem which depends on 
external submodules, so you won't be able to build package in offline mode. 
Sorry."
        fi
 
-       local lua=lua
-       use luajit && lua=luajit
-       export LUA="${lua}"
+    # we'll check for ldoc ourslves
+    sed -r \
+        -e "s#(AC_PATH_PROG\(\[LDOC\],).*#\1 [echo], [false]\)#" \
+        -e "s#(AM_CONDITIONAL\(\[HAVE_LDOC\],).*#\1 [false]\)#" \
+        -i configure.ac
 
-       ./bootstrap
+    # we don't need and install documentation for each target, so we'll take 
care on this ourselves
+    sed -r \
+        -e 's#doc/.*html##' \
+        -e 's#doc/.*css##' \
+        -e 's#(mkdir)#\1 -p#' \
+        -e 's#^(doc:).*##' \
+        -e 's#\$\(dist_.*_DATA\)##g' \
+        -i local.mk
+
+       ./bootstrap --skip-rock-checks
+
+       #unneded bootstrap wrapper
+    rm GNUmakefile
+}
+
+all_lua_compile() {
+    use doc && (
+        cp build-aux/config.ld.in build-aux/config.ld
+
+        sed -r \
+            -e "s/@PACKAGE_STRING@/${P}/" \
+            -i build-aux/config.ld
+
+        cd build-aux && ldoc -d ../doc . && cd ..
+
+        rm build-aux/config.ld
+    )
 }
 
-src_configure() {
+each_lua_configure() {
        myeconfargs=(
-               "--datadir=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${LUA})" \
-               "--libdir=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${LUA})" \
-               "LUA_INCLUDE=-I$($(tc-getPKG_CONFIG) --variable includedir 
${LUA})"
+               LUA="$(lua_get_lua)"
+               LUA_INCLUDE="$(lua_get_pkgvar --cflags --cflags-only-I)"
+               ax_cv_lua_luadir="$(lua_get_pkgvar INSTALL_LMOD)"
+               ax_cv_lua_luaexecdir="$(lua_get_pkgvar INSTALL_CMOD)"
+               --datadir="$(lua_get_pkgvar INSTALL_LMOD)"
+               --libdir="$(lua_get_pkgvar INSTALL_CMOD)"
        )
        base_src_configure "${myeconfargs[@]}"
+
+#      )
+#              "LUA_INCLUDE=-I$(lua_get_pkgvar includedir)"
+#      lua_default
+#      econf ${myeconfargs[@]}
 }

diff --git a/dev-lua/moonscript/moonscript-9999.ebuild 
b/dev-lua/moonscript/moonscript-9999.ebuild
index baca13f..88fda81 100644
--- a/dev-lua/moonscript/moonscript-9999.ebuild
+++ b/dev-lua/moonscript/moonscript-9999.ebuild
@@ -21,7 +21,7 @@ IUSE="+doc +inotify"
 RDEPEND="
        || (
                dev-lua/lpeg
-               dev-lua/lulpeg[lpeg-compat]
+               dev-lua/lulpeg[lpeg_replace]
        )
        dev-lua/luafilesystem
        dev-lua/alt-getopt

diff --git a/dev-lua/toluapp/ChangeLog b/dev-lua/toluapp/ChangeLog
deleted file mode 100644
index 7efdd30..0000000
--- a/dev-lua/toluapp/ChangeLog
+++ /dev/null
@@ -1,110 +0,0 @@
-# ChangeLog for dev-lua/toluapp
-# Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-lua/toluapp/ChangeLog,v 1.2 2012/11/18 
23:28:11 rafaelmartins Exp $
-
-  18 Nov 2012; Rafael G. Martins <[email protected]>
-  toluapp-1.0.92.ebuild, toluapp-1.0.93.ebuild:
-  Fix license. bug #443806
-
-  06 Nov 2010; Rafael G. Martins <[email protected]>
-  +toluapp-1.0.92.ebuild, +toluapp-1.0.93.ebuild, +metadata.xml:
-  Moved from dev-lang to dev-lua. Added myself to metadata.xml.
-
-  06 Mar 2010; Raúl Porcel <[email protected]> toluapp-1.0.93.ebuild:
-  alpha/sparc stable wrt #304759
-
-  21 Feb 2010; Christian Faulhammer <[email protected]>
-  toluapp-1.0.93.ebuild:
-  stable x86, bug 304759
-
-  15 Feb 2010; Joseph Jezak <[email protected]> toluapp-1.0.93.ebuild:
-  Marked ppc/ppc64 stable for bug #304759.
-
-  25 Jan 2010; Jeroen Roovers <[email protected]> toluapp-1.0.93.ebuild:
-  Depend on deprecated lua features thanks to pavelo (bug #297241).
-
-  31 Dec 2009; Brent Baude <[email protected]> toluapp-1.0.93.ebuild:
-  Marking toluapp-1.0.93 ~ppc64 for bug 279734
-
-  29 Dec 2009; Raúl Porcel <[email protected]> toluapp-1.0.93.ebuild:
-  Add ~sparc wrt #279734
-
-  28 Aug 2009; Tobias Klausmann <[email protected]> toluapp-1.0.93.ebuild:
-  Keyworded on alpha, bug #279734
-
-  18 Jul 2009; Samuli Suominen <[email protected]> toluapp-1.0.93.ebuild:
-  amd64 stable wrt #277191
-
-*toluapp-1.0.93 (02 Jul 2009)
-
-  02 Jul 2009; Samuli Suominen <[email protected]>
-  +toluapp-1.0.93.ebuild:
-  Version bump. Use shared library wrt #193744.
-
-  01 Jul 2009; Markus Meier <[email protected]> toluapp-1.0.92.ebuild:
-  amd64 stable, bug #255080
-
-  17 May 2008; Samuli Suominen <[email protected]>
-  -files/toluapp-1.0.2-gentoo.patch, -toluapp-1.0.2.ebuild,
-  -toluapp-1.0.7_p1.ebuild, toluapp-1.0.92.ebuild:
-  Move scons to DEPEND wrt #220441. Remove old versions and keyword ~amd64
-  for testing.
-
-  26 Mar 2007; Christian Faulhammer <[email protected]>
-  toluapp-1.0.92.ebuild:
-  stable x86, bug 168792
-
-  25 Mar 2007; Tobias Scherbaum <[email protected]>
-  toluapp-1.0.92.ebuild:
-  Stable on ppc wrt bug #168792.
-
-  22 Feb 2007; Piotr Jaroszyński <[email protected]> ChangeLog:
-  Transition to Manifest2.
-
-*toluapp-1.0.92 (22 Jan 2007)
-
-  22 Jan 2007; Matti Bickel <[email protected]> +toluapp-1.0.92.ebuild:
-  Revision bump
-
-  06 Jan 2007; Danny van Dyk <[email protected]>
-  -toluapp-1.0.5_p1.ebuild:
-  QA: Removed unused versions.
-
-  19 Oct 2006; <[email protected]> metadata.xml:
-  Maintainer wanted.
-
-  19 Oct 2006; <[email protected]> metadata.xml:
-  Now maintained by exg.
-
-  27 Apr 2006; Marien Zwart <[email protected]> files/digest-toluapp-1.0.2,
-  files/digest-toluapp-1.0.5_p1, Manifest:
-  Fixing SHA256 digest, pass four
-
-*toluapp-1.0.7_p1 (05 Apr 2006)
-
-  05 Apr 2006; Tom Payne <[email protected]> +toluapp-1.0.7_p1.ebuild:
-  Version bump. Bug # 128217.
-
-*toluapp-1.0.5_p1 (13 May 2005)
-
-  13 May 2005; Tom Payne <[email protected]> +toluapp-1.0.5_p1.ebuild:
-  Version bump. Bug # 91573.
-
-  24 Apr 2005; Michael Hanselmann <[email protected]> toluapp-1.0.2.ebuild:
-  Stable on ppc.
-
-  26 Oct 2004; Tom Payne <[email protected]> toluapp-1.0.2.ebuild:
-  Use $\(tc-getCC\) from toolchain-funcs.eclass. Bug #68998.
-
-  29 Aug 2004; <[email protected]> toluapp-1.0.2.ebuild:
-  Stable on x86.
-
-  10 May 2004; David Holm <[email protected]> toluapp-1.0.2.ebuild:
-  Added to ~ppc.
-
-*toluapp-1.0.2 (09 May 2004)
-
-  09 May 2004; <[email protected]> +metadata.xml,
-  +files/toluapp-1.0.2-gentoo.patch, +toluapp-1.0.2.ebuild:
-  Initial commit. Bug # 41992. Ebuild submitted by Richard Garand.
-

diff --git a/eclass/lua.eclass b/eclass/lua.eclass
index cf5651f..9328254 100644
--- a/eclass/lua.eclass
+++ b/eclass/lua.eclass
@@ -66,9 +66,16 @@
 # (e.g. selenium's firefox driver extension). When set this argument is
 # passed to "grep -E" to remove reporting of these shared objects.
 
+: ${GLOBAL_CFLAGS-${CFLAGS}}
+: ${GLOBAL_CXXFLAGS-${CXXFLAGS}}
+: ${GLOBAL_LDFLAGS-${LDFLAGS}}
+
+: ${NOCCACHE-false}
+: ${NODISTCC-false}
+
 [[ -n "${IS_MULTILIB}" ]] && multilib="multilib-minimal"
 
-inherit base eutils ${multilib} toolchain-funcs ${VCS}
+inherit base eutils ${multilib} toolchain-funcs flag-o-matic ${VCS}
 
 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install 
pkg_setup
 
@@ -345,6 +352,8 @@ _lua_invoke_environment() {
 
        my_WORKDIR="${WORKDIR}"/${environment}
        S="${my_WORKDIR}"/"${sub_S}"
+       BUILD_DIR="${S}"
+       CMAKE_USE_DIR="${S}"
 
        if [[ -d "${S}" ]]; then
                pushd "$S" &>/dev/null
@@ -368,6 +377,7 @@ _lua_each_implementation() {
                use lua_targets_${_lua_implementation} || continue
 
                LUA=$(lua_implementation_command ${_lua_implementation})
+               TARGET=${_lua_implementation};
                lua_impl=$(basename ${LUA})
                invoked=yes
 
@@ -375,7 +385,7 @@ _lua_each_implementation() {
                        _lua_invoke_environment ${_lua_implementation} "$@"
                fi
 
-               unset LUA lua_impl
+               unset LUA TARGET lua_impl
        done
 
        if [[ ${invoked} == "no" ]]; then
@@ -420,23 +430,6 @@ lua_src_unpack() {
        popd &>/dev/null
 }
 
-_lua_apply_patches() {
-       for patch in "${LUA_PATCHES[@]}"; do
-               if [ -f "${patch}" ]; then
-                       epatch "${patch}"
-               elif [ -f "${FILESDIR}/${patch}" ]; then
-                       epatch "${FILESDIR}/${patch}"
-               else
-                       die "Cannot find patch ${patch}"
-               fi
-       done
-
-       # This is a special case: instead of executing just in the special
-       # "all" environment, this will actually copy the effects on _all_
-       # the other environments, and is thus executed before the copy
-       type all_lua_prepare &>/dev/null && all_lua_prepare
-}
-
 _lua_source_copy() {
        # Until we actually find a reason not to, we use hardlinks, this
        # should reduce the amount of disk space that is wasted by this.
@@ -444,16 +437,43 @@ _lua_source_copy() {
                || die "Unable to copy ${_lua_implementation} environment"
 }
 
-_lua_setCFLAGS() {
+_lua_setFLAGS() {
        local lua=$(readlink -fs $(type -p $(basename ${LUA:-lua} 2>/dev/null)) 
2>/dev/null)
+
+       unset PKG_CONFIG LD
+# CC CXX CFLAGS CXXFLAGS LDFLAGS LUA_CF LUA_LF
+
+       PKG_CONFIG="$(tc-getPKG_CONFIG)"
        CC="$(tc-getCC)"
        CXX="$(tc-getCXX)"
        LD="$(tc-getLD)"
-       PKG_CONFIG="$(tc-getPKG_CONFIG)"
-       CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) --cflags $(basename ${lua})) 
-fPIC -DPIC"
-       CXXFLAGS="${CXXFLAGS} $($(tc-getPKG_CONFIG) --cflags $(basename 
${lua})) -fPIC -DPIC"
-       LDFLAGS="${LDFLAGS} -shared -fPIC"
-       export CC CXX LC CFLAGS CXXFLAGS LDFLAGS PKG_CONFIG
+
+       LUA_CF="$(${PKG_CONFIG} --cflags $(basename ${lua}))"
+       LUA_LF="$(${PKG_CONFIG} --libs $(basename ${lua}))"
+       LUA_LF="${LUA_LF//-llua /-l$(lua_get_lua) }"
+
+       CFLAGS="${GLOBAL_CFLAGS} ${LUA_CF} -fPIC -DPIC"
+       CXXFLAGS="${GLOBAL_CXXFLAGS} ${LUA_CF} -fPIC -DPIC"
+       LDFLAGS="${GLOBAL_LDFLAGS} -shared -fPIC"
+
+       export CC CXX LD CFLAGS CXXFLAGS LDFLAGS PKG_CONFIG LUA_LF
+}
+
+lua_is_jit() {
+       if [[ "${TARGET}" =~ "luajit" ]]; then
+               return 0
+       else
+               return 1
+       fi
+}
+
+lua_default() {
+       local phase rep phase_def_fn;
+       rep=${FUNCNAME[1]%%_lua*};
+       phase=${EBUILD_PHASE};
+       phase_def_fn="_lua_default_${rep}_${phase}"
+
+       declare -f ${phase_def_fn} >/dev/null && "${phase_def_fn}" "${@}"
 }
 
 # @FUNCTION: lua_src_prepare
@@ -462,47 +482,54 @@ _lua_setCFLAGS() {
 # implementation. Also carry out common clean up tasks.
 lua_src_prepare() {
        if [[ -n ${VCS} ]] && declare -f ${VCS}_src_prepare >/dev/null; then
-                       _lua_invoke_environment all ${VCS}_src_prepare
+               _lua_invoke_environment all ${VCS}_src_prepare
        fi
-       _lua_invoke_environment all epatch_user
-       _lua_invoke_environment all _lua_apply_patches
+
+       _lua_invoke_environment all base_src_prepare
+
+       if ! declare -f all_lua_prepare >/dev/null; then
+               all_lua_prepare() {
+                       lua_default
+               }
+       fi
+       _lua_invoke_environment all all_lua_prepare
+
 
        if [[ -n ${IS_MULTILIB} ]]; then
-               _lua_invoke_environment all multilib_copy_sources
+               _PHASE="multilib sources copy" \
+                       _lua_invoke_environment all multilib_copy_sources
        fi
 
-       _PHASE="source copy" \
+       _PHASE="sources copy" \
                _lua_each_implementation _lua_source_copy
 
-       if type each_lua_prepare &>/dev/null; then
-               _lua_each_implementation each_lua_prepare
+
+       if ! declare -f each_lua_prepare >/dev/null; then
+               each_lua_prepare() {
+                       lua_default
+               }
        fi
+
+       _lua_each_implementation each_lua_prepare
 }
 
 # @FUNCTION: lua_src_configure
 # @DESCRIPTION:
 # Configure the package.
 lua_src_configure() {
-       if type each_lua_configure &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_configure() {
-                               each_lua_configure
-                       }
-                       _lua_each_implementation multilib-minimal_src_configure
-               else
-                       _lua_each_implementation each_lua_configure
-               fi
+       if ! declare -f each_lua_configure >/dev/null; then
+               each_lua_configure() {
+                       lua_default
+               }
        fi
 
-       if type all_lua_configure &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_configure() {
-                               all_lua_configure
-                       }
-                       _lua_invoke_environment all 
multilib-minimal_src_configure
-               else
-                       _lua_invoke_environment all all_lua_configure
-               fi
+       if [[ -n ${IS_MULTILIB} ]]; then
+               multilib_src_configure() {
+                       each_lua_configure
+               }
+               _lua_each_implementation multilib-minimal_src_configure
+       else
+               _lua_each_implementation each_lua_configure
        fi
 }
 
@@ -510,80 +537,83 @@ lua_src_configure() {
 # @DESCRIPTION:
 # Compile the package.
 lua_src_compile() {
-       if type each_lua_compile &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_compile() {
-                               each_lua_compile
-                       }
-                       _lua_each_implementation multilib-minimal_src_compile
-               else
-                       _lua_each_implementation each_lua_compile
-               fi
+       if ! declare -f each_lua_compile >/dev/null; then
+               each_lua_compile() {
+                       lua_default
+               }
        fi
 
-       if type all_lua_compile &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_compile() {
-                               all_lua_compile
-                       }
-                       _lua_invoke_environment all multilib-minimal_src_compile
-               else
-                       _lua_invoke_environment all all_lua_compile
-               fi
+       if [[ -n ${IS_MULTILIB} ]]; then
+               multilib_src_compile() {
+                       each_lua_compile
+               }
+               _lua_each_implementation multilib-minimal_src_compile
+       else
+               _lua_each_implementation each_lua_compile
        fi
+
+       if ! declare -f all_lua_compile >/dev/null; then
+               all_lua_compile() {
+                       lua_default
+               }
+       fi
+       _lua_invoke_environment all all_lua_compile
 }
 
 # @FUNCTION: lua_src_test
 # @DESCRIPTION:
 # Run tests for the package.
 lua_src_test() {
-       if type each_lua_test &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_test() {
-                               each_lua_test
-                       }
-                       _lua_each_implementation multilib-minimal_src_test
-               else
-                       _lua_each_implementation each_lua_test
-               fi
+       if ! declare each_lua_test >/dev/null; then
+               each_lua_test() {
+                       lua_default
+               }
        fi
 
-       if type all_lua_test &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_test() {
-                               all_lua_test
-                       }
-                       _lua_invoke_environment all multilib-minimal_src_test
-               else
-                       _lua_invoke_environment all all_lua_test
-               fi
+       if [[ -n ${IS_MULTILIB} ]]; then
+               multilib_src_test() {
+                       each_lua_test
+               }
+               _lua_each_implementation multilib-minimal_src_test
+       else
+               _lua_each_implementation each_lua_test
+       fi
+
+       if ! declare -f all_lua_test >/dev/null; then
+               all_lua_test() {
+                       lua_default
+               }
        fi
+       _lua_invoke_environment all all_lua_test
 }
 
 # @FUNCTION: lua_src_install
 # @DESCRIPTION:
 # Install the package for each lua target implementation.
 lua_src_install() {
-       if type each_lua_install &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_install() {
-                               each_lua_install
-                       }
-                       _lua_each_implementation multilib-minimal_src_install
-               else
-                       _lua_each_implementation each_lua_install
-               fi
+       if ! declare -f each_lua_install >/dev/null; then
+               each_lua_install() {
+                       lua_default
+               }
        fi
 
-       if type all_lua_install &>/dev/null; then
-               if [[ -n ${IS_MULTILIB} ]]; then
-                       multilib_src_install() {
-                               all_lua_install
-                       }
-                       _lua_invoke_environment all multilib-minimal_src_install
-               else
-                       _lua_invoke_environment all all_lua_install
-               fi
+       if ! declare -f all_lua_install >/dev/null; then
+               all_lua_install() {
+                       lua_default
+               }
+       fi
+
+       if [[ -n ${IS_MULTILIB} ]]; then
+               multilib_src_install() {
+                       each_lua_install
+               }
+               multilib_src_install_all() {
+                       all_lua_install
+               }
+               _lua_each_implementation multilib-minimal_src_install
+       else
+               _lua_each_implementation each_lua_install
+               _lua_invoke_environment all all_lua_install
        fi
 
 #### TODO: move this things to more general eclass, like docs or so ####
@@ -591,37 +621,38 @@ lua_src_install() {
 
        README_DOCS=(${DOCS[@]});
        OTHER_DOCS=(${DOCS[@]//README*});
-       MY_S="${WORKDIR}/all/${P}"
+#      MY_S="${WORKDIR}/all/${P}"
        
        unset DOCS;
 
        for r in ${OTHER_DOCS[@]}; do
                README_DOCS=("${README_DOCS[@]//${r}}")
 
-               if [[ -d ${MY_S}/${r} ]]; then
-                       OTHER_DOCS=("${OTHER_DOCS[@]//${r}}")
-                       for od in ${MY_S}/${r}/*; do
-                               OTHER_DOCS+=("${od#${MY_S}/}")
-                       done
-               fi
+#              if [[ -d ${MY_S}/${r} ]]; then
+##                     for case if __strip_duplicate_slashes will be dropped 
from phase-helpers.sh:
+##                     local rd=$(dirname ${r}/i-need-to-remove-trailing-slash)
+#                      OTHER_DOCS=("${OTHER_DOCS[@]//${r}}")
+#                      for od in ${MY_S}/${r}/*; do
+#                              OTHER_DOCS+=("$(__strip_duplicate_slashes 
${od#${MY_S}/})")
+#                      done
+#              fi
        done;
-
        README_DOCS+=(${READMES[@]})
 
        if [[ -n "${README_DOCS}" ]]; then
                export DOCS=(${README_DOCS[@]});
-               _PHASE="install readmes" _lua_invoke_environment all 
base_src_install_docs
+               _PHASE="install readmes" _lua_invoke_environment all 
_lua_src_install_docs
                unset DOCS;
        fi
 
        if [[ -n "${OTHER_DOCS[@]}" || -n "${HTML_DOCS[@]}" ]] && use doc; then
                export DOCS=(${OTHER_DOCS[@]})
-               _PHASE="install docs" _lua_invoke_environment all 
base_src_install_docs
+               _PHASE="install docs" _lua_invoke_environment all 
_lua_src_install_docs
                unset DOCS
        fi
 
        if [[ -n "${EXAMPLES[@]}" ]] && use examples; then
-               _PHASE="install samples" _lua_invoke_environment all 
_lua_src_install_examples
+               _PHASE="install examples" _lua_invoke_environment all 
_lua_src_install_examples
        fi
 #### END  ####
 }
@@ -631,28 +662,69 @@ _lua_src_install_examples() {
        debug-print-function $FUNCNAME "$@"
 
        local x
+       local MY_S="${WORKDIR}/all/${P}"
 
-       pushd "${S}" >/dev/null
+       pushd "${MY_S}" >/dev/null
 
        if [[ "$(declare -p EXAMPLES 2>/dev/null 2>&1)" == "declare -a"* ]]; 
then
                for x in "${EXAMPLES[@]}"; do
                        debug-print "$FUNCNAME: docs: creating examples from 
${x}"
                        docompress -x /usr/share/doc/${PF}/examples
-                       insinto /usr/share/doc/${PF}/examples
-                       if [[ "${x}" = *"/*" ]]; then
-                               pushd $(dirname ${x}) >/dev/null
-                               doins -r *
-                               popd >/dev/null
-                       else
-                               doins -r "${x}"
-                       fi || die "install examples failed"
+                       docinto examples
+                       dodoc -r "${x}"
                done
        fi
 
        popd >/dev/null
 }
+
+_lua_src_install_docs() {
+       debug-print-function $FUNCNAME "$@"
+       local x
+
+       local MY_S="${WORKDIR}/all/${P}"
+       pushd "${MY_S}" >/dev/null
+
+       if [[ "$(declare -p DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then
+               for x in "${DOCS[@]}"; do
+                       debug-print "$FUNCNAME: docs: creating document from 
${x}"
+                       docinto .
+                       dodoc -r "${x}"
+               done
+       fi
+       if [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; 
then
+               for x in "${HTML_DOCS[@]}"; do
+                       debug-print "$FUNCNAME: docs: creating html document 
from ${x}"
+                       docinto html
+                       dodoc -r "${x}"
+               done
+       fi
+
+       popd >/dev/null
+}
+
 #### END ####
 
+
+# @FUNCTION: luainto
+# @USAGE: path
+# @DESCRIPTION:
+# Specifies installation path (under INSTALL_?MOD) for "dolua*" functions
+#luainto() {
+#      _dolua_indir="${1}"
+#}
+
+newlua() {
+       local tmp_S=$(mktemp -d -p ${T} tmp_S.${P}.XXXXX)
+       local src="${1}"
+       local dst="${2}"
+       cp -rl "${src}" "${tmp_S}/${dst}"
+       pushd "${tmp_S}" >/dev/null &&
+       dolua "${dst}" &&
+       popd >/dev/null &&
+       rm -rf "${tmp_S}"
+}
+
 # @FUNCTION: dolua
 # @USAGE: file [file...]
 # @DESCRIPTION:
@@ -663,9 +735,6 @@ dolua() {
        for f in "$@"; do
                base_f="$(basename ${f})"
                case ${base_f} in
-                       *.lua|*.moon)
-                               lmod+=(${f})
-                               ;;
                        *.so)
                                cmod+=(${f})
                                ;;
@@ -674,19 +743,18 @@ dolua() {
                                        local 
insdir="${_dolua_insdir}/${base_f}"
                                        _dolua_insdir="${insdir}" dolua "${f}"/*
                                else
-                                       eerror "${f} is neither pure-lua 
module, nor moonscript library, nor C module, nor directory with them"
+                                       lmod+=(${f})
                                fi
                                ;;
                esac
        done
-       test -n "${lmod}" && _dolua_insdir="${_dolua_insdir}" dolua_lmod 
${lmod[@]}
-       test -n "${cmod}" && _dolua_insdir="${_dolua_insdir}" dolua_cmod 
${cmod[@]}
+       test -n "${lmod}" && _dolua_insdir="${_dolua_insdir}" _lua_install_lmod 
${lmod[@]}
+       test -n "${cmod}" && _dolua_insdir="${_dolua_insdir}" _lua_install_cmod 
${cmod[@]}
 }
 
-dolua_lmod() {
-       [[ -z ${LUA} ]] && die "\$LUA is not set"
+_lua_install_lmod() {
        has "${EAPI}" 2 && ! use prefix && EPREFIX=
-       local insdir="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua_impl})"
+       local insdir="$(lua_get_lmoddir)"
        [[ -n "${_dolua_insdir}" ]] && insdir="${insdir}/${_dolua_insdir}"
        (
                insinto ${insdir#${EPREFIX}}
@@ -695,10 +763,9 @@ dolua_lmod() {
        ) || die "failed to install $@"
 }
 
-dolua_cmod() {
-       [[ -z ${LUA} ]] && die "\$LUA is not set"
+_lua_install_cmod() {
        has "${EAPI}" 2 && ! use prefix && EPREFIX=
-       local insdir="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua_impl})"
+       local insdir="$(lua_get_cmoddir)"
        [[ -n "${_dolua_insdir}" ]] && insdir="${insdir}/${_dolua_insdir}"
        (
                insinto ${insdir#${EPREFIX}}
@@ -707,11 +774,57 @@ dolua_cmod() {
        ) || die "failed to install $@"
 }
 
+_lua_jit_insopts() {
+       [[ "${LUA}" =~ "luajit" ]] || return 0
+       local insdir=$(${LUA} -e 
'print(package.path:match(";(/[^;]+luajit[^;]+)/%?.lua;"))')
+       insinto ${insdir}
+       insopts -m 0644
+}
+
+dolua_jit() {
+       _lua_jit_insopts
+       doins "$@"
+}
+
+newlua_jit() {
+       _lua_jit_insopts
+       newins "$@"
+}
+
+# @FUNCTION: lua_get_pkgvar
+# @RETURN: The value of specified pkg-config variable for Lua interpreter in 
${LUA}.
+lua_get_pkgvar() {
+       local var=$($(tc-getPKG_CONFIG) ${2:---variable} ${@} $(lua_get_lua))
+       echo "${var}"
+}
+
+# @FUNCTION: lua_get_lmoddir
+# @RETURN: The path for pure-lua modules installation for Lua interpreter in 
${LUA}.
+lua_get_lmoddir() {
+       local ldir=$(lua_get_pkgvar INSTALL_LMOD)
+       echo "${ldir}"
+}
+
+# @FUNCTION: lua_get_cmoddir
+# @RETURN: The path for binary modules installation for Lua interpreter in 
${LUA}.
+lua_get_cmoddir() {
+       local cdir=$(lua_get_pkgvar INSTALL_CMOD)
+       echo "${cdir}"
+}
+
+# @FUNCTION: lua_get_lua
+# @RETURN: The name of Lua interpreter in ${LUA}.
+lua_get_lua() {
+       [[ -z ${LUA} ]] && die "\$LUA is not set"
+       local impl="${lua_impl:-$(basename ${LUA})}"
+       echo "${impl}"
+}
+
 # @FUNCTION: lua_get_liblua
 # @RETURN: The location of liblua*.so belonging to the Lua interpreter in 
${LUA}.
 lua_get_liblua() {
-       local libdir="$($(tc-getPKG_CONFIG) --variable libdir ${lua_impl})"
-       local libname="$($(tc-getPKG_CONFIG) --variable libname ${lua_impl})"
+       local libdir="$(lua_get_pkgvar libdir)"
+       local libname="$(lua_get_pkgvar libname)"
        libname="${libname:-lua$(lua_get_abi)}"
        echo "${libdir}/lib${libname}.so"
 }
@@ -719,7 +832,7 @@ lua_get_liblua() {
 # @FUNCTION: lua_get_incdir
 # @RETURN: The location of the header files belonging to the Lua interpreter 
in ${LUA}.
 lua_get_incdir() {
-       local incdir=$($(tc-getPKG_CONFIG) --variable includedir ${lua_impl})
+       local incdir=$(lua_get_pkgvar includedir)
        echo "${incdir}"
 }
 
@@ -747,3 +860,112 @@ lua_get_implementation() {
        esac
 }
 
+
+
+_lua_default_all_prepare() {
+       local prepargs=();
+       prepargs+=(
+               "${myeprepareargs[@]}"
+               "${@}"
+       )
+
+       [[ -x "${BOOTSTRAP}" ]] && ${BOOTSTRAP} "${prepargs[@]}"
+
+       for mf in Makefile GNUmakefile makefile; do
+               if [[ -f "${mf}" ]]; then
+                       sed -i -r \
+                               -e '1iinclude .lua_eclass_config' \
+                               -e '/^CC[[:space:]]*=/d' \
+                               -e '/^LD[[:space:]]*=/d' \
+                               -e 's#(^CFLAGS[[:space:]]*)[[:punct:]]*=#\1+=#' 
\
+                               -e 
's#(^CXXFLAGS[[:space:]]*)[[:punct:]]*=#\1+=#' \
+                               -e 
's#(^LDFLAGS[[:space:]]*)[[:punct:]]*=#\1+=#' \
+                               -e 
's#(^LFLAGS[[:space:]]*)[[:punct:]]*=#\1+=$(LDCONFIG)#' \
+                               -e 's#`pkg-config#`$(PKG_CONFIG)#g' \
+                               -e 
's#(shell[[:space:][:punct:]]*)pkg-config#\1$(PKG_CONFIG)#g' \
+                               -e 's#lua5.[[:digit:]]#$(LUA_IMPL)#g' \
+                               -e 
's#-llua[[:digit:][:punct:]]*#__LESLPH__#g;s#__LESLPH__([[:alpha:]])#-llua\1#g;s#__LESLPH__#$(LUA_LINK_LIB)#g'
 \
+                               "${mf}"
+               fi
+               touch ${T}/.lua_ecl_conf
+       done
+
+}
+
+_lua_default_all_compile() {
+       local doc_target="${DOC_MAKE_TARGET:=doc}"
+       has doc ${IUSE} &&
+       use doc &&
+       grep -qs "${doc_target}[[:space:]]*:" {GNUm,m,M}akefile && (
+               [[ -f ${T}/.lua_ecl_conf ]] && touch .lua_eclass_config
+               base_src_compile "${doc_target[@]}"
+       )
+}
+
+#lua_default_all_install() {
+#      
+#}
+
+_lua_default_each_configure() {
+       _lua_setFLAGS
+       local confargs=();
+       confargs+=("${myeconfargs[@]}")
+       confargs+=("${@}")
+
+       base_src_configure "${confargs[@]}"
+
+       if [[ -f ${T}/.lua_ecl_conf ]]; then
+               touch .lua_eclass_config
+               local ecl_confargs=();
+
+               ecl_confargs+=(
+                       CC="${CC}"
+                       CXX="${CXX}"
+                       LD="${LD}"
+                       CFLAGS="${CFLAGS}"
+                       LDFLAGS="${LDFLAGS}"
+                       CXXFLAGS="${CXXFLAGS}"
+                       PKG_CONFIG="${PKG_CONFIG}"
+                       LUA_IMPL="$(lua_get_lua)"
+                       LUA_LINK_LIB="${LUA_LF}"
+               )
+
+               ecl_confargs+=("${confargs[@]}")
+
+               for carg in "${ecl_confargs[@]}"; do
+                       echo "${carg}" >> .lua_eclass_config
+               done
+       fi
+}
+
+_lua_default_each_compile() {
+       local makeargs=();
+
+       makeargs+=(
+               "${myemakeargs[@]}"
+               "${@}"
+       )
+
+       if has ccache ${FEATURES} && [[ "${NOCCACHE}" = "true" ]]; then
+               export CCACHE_DISABLE=1;
+       fi
+
+       if has distcc ${FEATURES} && [[ "${NODISTCC}" = "true" ]]; then
+               export DISTCC_DISABLE=1;
+       fi
+
+       base_src_compile "${makeargs[@]}"
+}
+
+_lua_default_each_install() {
+       local instargs=();
+       instargs+=(
+               DESTDIR="${D}"
+               "${@}"
+               "${myeinstallargs[@]}"
+               install
+       )
+
+       base_src_make "${instargs[@]}"
+}
+

Reply via email to