commit:     e81d4e9013537aaadc792c1265f94931c8c5bc0a
Author:     Vadim A. Misbakh-Soloviov <git <AT> mva <DOT> name>
AuthorDate: Sat Sep 12 13:17:11 2015 +0000
Commit:     Vadim A. Misbakh-Soloviov <mva <AT> mva <DOT> name>
CommitDate: Sat Sep 12 13:17:11 2015 +0000
URL:        https://gitweb.gentoo.org/proj/lua.git/commit/?id=e81d4e90

eclass/lua: added; dev-lua/*: moving to lua eclass

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

 dev-lang/lua/Manifest                              |   4 +-
 .../{lua-5.3-make.patch => lua-5.1-make-r2.patch}  |  61 +-
 dev-lang/lua/files/lua-5.1-make_static-r1.patch    |  12 +
 dev-lang/lua/files/lua-5.1-module_paths.patch      |  30 +
 dev-lang/lua/files/lua-5.1-readline.patch          |  10 +
 dev-lang/lua/files/lua-5.1.4-deprecated.patch      |  46 ++
 dev-lang/lua/files/lua-5.1.4-test.patch            |  11 +
 .../{lua-5.3-make.patch => lua-5.2-make-r1.patch}  |   7 +-
 dev-lang/lua/files/lua-5.3-make.patch              |  23 +-
 .../{lua-5.3.0.ebuild => lua-5.1.5-r101.ebuild}    |  94 +--
 .../lua/{lua-5.3.0.ebuild => lua-5.2.4.ebuild}     |  24 +-
 .../lua/{lua-5.3.0.ebuild => lua-5.3.1.ebuild}     |   8 +-
 dev-lang/luajit/luajit-2.0.9999.ebuild             |  51 +-
 dev-lang/luajit/luajit-2.1.9999.ebuild             |  53 +-
 dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild             |  36 +-
 dev-lua/alt-getopt/alt-getopt-0.7.0.ebuild         |  36 +-
 dev-lua/ansicolors/ansicolors-9999.ebuild          |  25 +-
 dev-lua/captcha/captcha-9999.ebuild                |  34 +-
 dev-lua/cmsgpack/cmsgpack-9999.ebuild              |  34 +-
 dev-lua/cosmo/cosmo-9999.ebuild                    |  38 +-
 dev-lua/coxpcall/coxpcall-9999.ebuild              |  21 +-
 dev-lua/iluajit/iluajit-9999.ebuild                |  25 +-
 dev-lua/lahttp/lahttp-9999.ebuild                  |  22 +-
 dev-lua/lapis/lapis-9999.ebuild                    |  31 +-
 dev-lua/ldoc/ldoc-9999.ebuild                      |  37 +-
 dev-lua/linotify/linotify-9999.ebuild              |  33 +-
 dev-lua/ljsyscall/ljsyscall-9999.ebuild            |  27 +-
 dev-lua/lpc/lpc-9999.ebuild                        |  22 +-
 dev-lua/lpeg/lpeg-0.12.ebuild                      |  50 +-
 dev-lua/lsysstats/lsysstats-9999.ebuild            |  32 +-
 dev-lua/lua-cjson/lua-cjson-9999.ebuild            |  31 +-
 dev-lua/lua-csv/lua-csv-9999.ebuild                |  24 +-
 dev-lua/lua-curl/lua-curl-9999.ebuild              |  42 +-
 dev-lua/lua2html/lua2html-9999.ebuild              |  19 +-
 dev-lua/luacrypto/luacrypto-9999.ebuild            |  51 +-
 dev-lua/luadbi/luadbi-9999.ebuild                  |  73 +-
 dev-lua/lunit/lunit-9999.ebuild                    |   2 +-
 dev-lua/moonscript/moonscript-9999.ebuild          |  55 +-
 dev-lua/squish/squish-9999.ebuild                  |  19 +-
 eclass/lua.eclass                                  | 749 +++++++++++++++++++++
 profiles/make.defaults                             |   2 +-
 profiles/updates/2Q-2015                           |   2 -
 profiles/updates/3Q-2015                           |   3 +
 virtual/lua/lua-5.ebuild                           |   9 +-
 44 files changed, 1390 insertions(+), 628 deletions(-)

diff --git a/dev-lang/lua/Manifest b/dev-lang/lua/Manifest
index d9ea152..78e7891 100644
--- a/dev-lang/lua/Manifest
+++ b/dev-lang/lua/Manifest
@@ -1 +1,3 @@
-DIST lua-5.3.0.tar.gz 278045 SHA256 
ae4a5eb2d660515eb191bfe3e061f2b8ffe94dce73d32cfd0de090ddcc0ddb01 SHA512 
2b423e70c4c992a08d28ef12f1d0b078f2ee7043cda302d93e9d59ff6ab79152bb4971455d37666a98cf5cfe3cafd3d16e30b33a11fd585743d5d817424a2d51
 WHIRLPOOL 
bae9f472f61d45fc6a2f20119a947de5719ca911c3c90d85cd93e82dd95538a421e1d35c1d4726f1544f12a4285f9548612f9ac255cce3617ee6bc092f352a40
+DIST lua-5.1.5.tar.gz 221213 SHA256 
2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333 SHA512 
0142fefcbd13afcd9b201403592aa60620011cc8e8559d4d2db2f92739d18186860989f48caa45830ff4f99bfc7483287fd3ff3a16d4dec928e2767ce4d542a9
 WHIRLPOOL 
9dac93b73b9ad1ef6c69e0aa11fb53d5efe89274b65c55a1ac30bab23e8a255851b0e44306db54212b1d481e658cecd38e5ff22a25e1fa974858b7b03fb45b75
+DIST lua-5.2.4.tar.gz 252651 SHA256 
b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b SHA512 
cd77148aba4b707b6c159758b5e8444e04f968092eb98f6b4c405b2fb647e709370d5a8dcf604176101d3407e196a7433b5dcdce4fe9605c76191d3649d61a8c
 WHIRLPOOL 
4ddd1aefa63ea2df5d7e2a774aa89a427fa6753c11db26c70ebf82eece7b05807b7ada2c0966057fe2ddebf8ab792c0060aa51b0d29cd58572b2a0ba9dbabfdc
+DIST lua-5.3.1.tar.gz 282401 SHA256 
072767aad6cc2e62044a66e8562f51770d941e972dc1e4068ba719cd8bffac17 SHA512 
94c5e77d25172c1f5de0ea5457fe62f2bea618e573659df989297d1a8cb1b062c4b0133b88ffa9ce74cdbe98d0d1ea356c69115cae308030e1f989a3f6f26321
 WHIRLPOOL 
4530bb7623b754e5736af6b98538ec17931237f38d66acf0845707da09e3ced241a431c7dfb41718000a9295ca1489e8478e10f99d46b71a61c49db229e01ae2

diff --git a/dev-lang/lua/files/lua-5.3-make.patch 
b/dev-lang/lua/files/lua-5.1-make-r2.patch
similarity index 54%
copy from dev-lang/lua/files/lua-5.3-make.patch
copy to dev-lang/lua/files/lua-5.1-make-r2.patch
index f84176d..2905a62 100644
--- a/dev-lang/lua/files/lua-5.3-make.patch
+++ b/dev-lang/lua/files/lua-5.1-make-r2.patch
@@ -1,5 +1,6 @@
---- lua-5.1.1.orig/Makefile    2006-06-02 12:53:38.000000000 +0200
-+++ lua-5.1.1/Makefile 2006-11-16 02:16:53.000000000 +0100
+diff -ru lua-5.1.5.orig/Makefile lua-5.1.5/Makefile
+--- lua-5.1.5.orig/Makefile    2014-04-15 17:43:34.845435031 +0200
++++ lua-5.1.5/Makefile 2014-04-15 19:05:08.669304987 +0200
 @@ -11,7 +11,7 @@
  # so take care if INSTALL_TOP is not an absolute path.
  INSTALL_TOP= /usr/local
@@ -9,45 +10,64 @@
  INSTALL_LIB= $(INSTALL_TOP)/lib
  INSTALL_MAN= $(INSTALL_TOP)/man/man1
  #
-@@ -127,3 +127,18 @@
- .PHONY: all $(PLATS) clean install local none dummy echo pecho lecho newer
+@@ -126,3 +126,21 @@
+ .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
  
  # (end of Makefile)
 +
 +# Use libtool for binary installs, etc.
 +
 +export V
-+export LIBTOOL = $(EROOT)usr/bin/libtool --quiet --tag=CC
++export LIBTOOL = libtool --quiet --tag=CC
 +# See libtool manual about how to set this
 +
 +gentoo_clean:
 +      cd src; $(MAKE) $@
 +
++gentoo_test: gentoo_linux
++      test/lua.static test/hello.lua
++
 +gentoo_install:
 +      mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB)
 +      cd src; $(LIBTOOL) --mode=install $(INSTALL_EXEC) lua$V luac$V 
$(INSTALL_BIN)
 +      cd src; $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
 +      cd src; $(LIBTOOL) --mode=install $(INSTALL_DATA) liblua$V.la 
$(INSTALL_LIB)
---- lua-5.1.1.orig/src/Makefile        2006-03-22 01:41:49.000000000 +0100
-+++ lua-5.1.1/src/Makefile     2006-11-16 02:10:27.000000000 +0100
-@@ -39,1 +39,1 @@
+diff -ru lua-5.1.5.orig/src/Makefile lua-5.1.5/src/Makefile
+--- lua-5.1.5.orig/src/Makefile        2014-04-15 17:43:34.844435031 +0200
++++ lua-5.1.5/src/Makefile     2014-04-15 18:07:21.427397122 +0200
+@@ -29,10 +29,10 @@
+ LIB_O=        lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o 
ltablib.o \
+       lstrlib.o loadlib.o linit.o
+ 
 -LUA_T=        lua
 +LUA_T= lua$V
-@@ -42,1 +42,1 @@
+ LUA_O=        lua.o
+ 
 -LUAC_T=       luac
 +LUAC_T=       luac$V
-@@ -54,1 +54,1 @@
+ LUAC_O=       luac.o print.o
+ 
+ ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
+@@ -51,10 +51,10 @@
+       $(AR) $@ $(CORE_O) $(LIB_O)     # DLL needs all object files
+       $(RANLIB) $@
+ 
 -$(LUA_T): $(LUA_O) $(LUA_A)
 +origin$(LUA_T): $(LUA_O) $(LUA_A)
-@@ -57,1 +57,1 @@
+       $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+ 
 -$(LUAC_T): $(LUAC_O) $(LUA_A)
 +origin$(LUAC_T): $(LUAC_O) $(LUA_A)
-@@ -185,3 +185,30 @@
- lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \
-   lobject.h ltm.h lzio.h
+       $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
+ 
+ clean:
+@@ -180,3 +180,33 @@
+   ltm.h lzio.h lmem.h lopcodes.h lundump.h
+ 
+ # (end of Makefile)
 +
-+export LIBTOOL = $(EROOT)usr/bin/libtool --quiet --tag=CC
-+export LIB_VERSION = 6:1:1
++export LIBTOOL = libtool --tag=CC
++export LIB_VERSION = 5:1:5
 +
 +# The following rules use libtool for compiling and linking in order to
 +# provide shared library support.
@@ -59,18 +79,19 @@
 +      $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 +
 +$(LIB_NAME): $(LIB_OBJS)
-+      $(LIBTOOL) --mode=link $(CC) -version-info $(LIB_VERSION) \
++      $(LIBTOOL) --mode=link $(CC) -version-info 0:0:0 \
 +            -rpath $(RPATH) $(LDFLAGS) -o $(LIB_NAME) $(LIB_OBJS) $(LIB_LIBS)
 +
 +$(LUA_T): $(LUA_O:.o=.lo) $(LIB_NAME)
 +      $(LIBTOOL) --mode=link $(CC) -export-dynamic $(LDFLAGS) -o $@ 
$(LUA_O:.o=.lo) $(LIB_NAME) $(LUA_LIBS)
 +
++lua_test: $(LUA_O:.o=.lo) $(LIB_NAME)
++      $(LIBTOOL) --mode=link $(CC) -static -export-dynamic $(LDFLAGS) -o $@ 
$(LUA_O:.o=.lo) $(LIB_NAME) $(LUA_LIBS)
++
 +$(LUAC_T): $(LUAC_O:.o=.lo) $(LIB_NAME)
 +      $(LIBTOOL) --mode=link $(CC) -static $(LDFLAGS) -o $@ $(LUAC_O:.o=.lo) 
$(LIB_NAME)
 +
 +gentoo_clean:
 +      $(LIBTOOL) --mode=clean $(RM) $(ALL_O:.o=.lo) $(LIB_NAME) lua$V luac$V
 +
-+gentoo_all: $(LIB_NAME) $(LUA_T) $(LUAC_T)
- 
- # (end of Makefile)
++gentoo_all: $(LIB_NAME) $(LUA_T) lua_test $(LUAC_T)

diff --git a/dev-lang/lua/files/lua-5.1-make_static-r1.patch 
b/dev-lang/lua/files/lua-5.1-make_static-r1.patch
new file mode 100644
index 0000000..e5fdc3a
--- /dev/null
+++ b/dev-lang/lua/files/lua-5.1-make_static-r1.patch
@@ -0,0 +1,12 @@
+diff -ru lua-5.1.1.orig/src/Makefile lua-5.1.1/src/Makefile
+--- lua-5.1.1.orig/src/Makefile        2006-11-21 07:19:31 +0000
++++ lua-5.1.1/src/Makefile     2006-11-21 07:19:52 +0000
+@@ -196,7 +196,7 @@
+             -rpath $(RPATH) $(LDFLAGS) -o $(LIB_NAME) $(LIB_OBJS) $(LIB_LIBS)
+ 
+ $(LUA_T): $(LUA_O:.o=.lo) $(LIB_NAME)
+-      $(LIBTOOL) --mode=link $(CC) -export-dynamic $(LDFLAGS) -o $@ 
$(LUA_O:.o=.lo) $(LIB_NAME) $(LUA_LIBS)
++      $(LIBTOOL) --mode=link $(CC) -static -export-dynamic $(LDFLAGS) -o $@ 
$(LUA_O:.o=.lo) $(LIB_NAME) $(LUA_LIBS)
+ 
+ $(LUAC_T): $(LUAC_O:.o=.lo) $(LIB_NAME)
+       $(LIBTOOL) --mode=link $(CC) -static -o $@ $(LUAC_O:.o=.lo) $(LIB_NAME)

diff --git a/dev-lang/lua/files/lua-5.1-module_paths.patch 
b/dev-lang/lua/files/lua-5.1-module_paths.patch
new file mode 100644
index 0000000..29ac4c3
--- /dev/null
+++ b/dev-lang/lua/files/lua-5.1-module_paths.patch
@@ -0,0 +1,30 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## src_luaconf.h.dpatch by John V. Belmonte <[email protected]>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: Set Lua's default PATH and CPATH.
+
+@DPATCH@
+diff -urNad trunk~/src/luaconf.h trunk/src/luaconf.h
+--- trunk~/src/luaconf.h       2006-02-10 12:44:06.000000000 -0500
++++ trunk/src/luaconf.h        2006-02-17 21:32:55.000000000 -0500
+@@ -83,13 +83,17 @@
+ 
+ #else
+ #define LUA_ROOT      "/usr/local/"
++#define LUA_ROOT2     "/usr/"
+ #define LUA_LDIR      LUA_ROOT "share/lua/5.1/"
++#define LUA_LDIR2     LUA_ROOT2 "share/lua/5.1/"
+ #define LUA_CDIR      LUA_ROOT "lib/lua/5.1/"
++#define LUA_CDIR2     LUA_ROOT2 "lib/lua/5.1/"
+ #define LUA_PATH_DEFAULT  \
+               "./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
+-                          LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
++                          LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua;" \
++                          LUA_LDIR2"?.lua;"  LUA_LDIR2"?/init.lua"
+ #define LUA_CPATH_DEFAULT \
+-      "./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
++      "./?.so;" LUA_CDIR"?.so;" LUA_CDIR2"?.so;" LUA_CDIR"loadall.so"
+ #endif
+ 
+ 

diff --git a/dev-lang/lua/files/lua-5.1-readline.patch 
b/dev-lang/lua/files/lua-5.1-readline.patch
new file mode 100644
index 0000000..f144861
--- /dev/null
+++ b/dev-lang/lua/files/lua-5.1-readline.patch
@@ -0,0 +1,10 @@
+--- lua-5.1.1.orig/src/luaconf.h       2006-04-10 20:27:23.000000000 +0200
++++ lua-5.1.1/src/luaconf.h    2006-11-15 14:53:07.000000000 +0100
+@@ -36,7 +36,6 @@
+ #if defined(LUA_USE_LINUX)
+ #define LUA_USE_POSIX
+ #define LUA_USE_DLOPEN                /* needs an extra library: -ldl */
+-#define LUA_USE_READLINE      /* needs some extra libraries */
+ #endif
+ 
+ #if defined(LUA_USE_MACOSX)

diff --git a/dev-lang/lua/files/lua-5.1.4-deprecated.patch 
b/dev-lang/lua/files/lua-5.1.4-deprecated.patch
new file mode 100644
index 0000000..a88a991
--- /dev/null
+++ b/dev-lang/lua/files/lua-5.1.4-deprecated.patch
@@ -0,0 +1,46 @@
+diff -rdu lua-5.1.3.orig/src/luaconf.h lua-5.1.3/src/luaconf.h
+--- lua-5.1.3.orig/src/luaconf.h       2008-02-12 17:00:03.000000000 +0000
++++ lua-5.1.3/src/luaconf.h    2008-02-12 17:07:55.000000000 +0000
+@@ -340,14 +340,14 @@
+ ** CHANGE it to undefined as soon as your programs use only '...' to
+ ** access vararg parameters (instead of the old 'arg' table).
+ */
+-#define LUA_COMPAT_VARARG
++#undef LUA_COMPAT_VARARG
+ 
+ /*
+ @@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
+ ** CHANGE it to undefined as soon as your programs use 'math.fmod' or
+ ** the new '%' operator instead of 'math.mod'.
+ */
+-#define LUA_COMPAT_MOD
++#undef LUA_COMPAT_MOD
+ 
+ /*
+ @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
+@@ -355,14 +355,14 @@
+ ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
+ ** off the advisory error when nesting [[...]].
+ */
+-#define LUA_COMPAT_LSTR               1
++#undef LUA_COMPAT_LSTR
+ 
+ /*
+ @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
+ ** CHANGE it to undefined as soon as you rename 'string.gfind' to
+ ** 'string.gmatch'.
+ */
+-#define LUA_COMPAT_GFIND
++#undef LUA_COMPAT_GFIND
+ 
+ /*
+ @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
+@@ -370,7 +370,7 @@
+ ** CHANGE it to undefined as soon as you replace to 'luaL_register'
+ ** your uses of 'luaL_openlib'
+ */
+-#define LUA_COMPAT_OPENLIB
++#undef LUA_COMPAT_OPENLIB
+ 
+ 
+ 

diff --git a/dev-lang/lua/files/lua-5.1.4-test.patch 
b/dev-lang/lua/files/lua-5.1.4-test.patch
new file mode 100644
index 0000000..99b4ad6
--- /dev/null
+++ b/dev-lang/lua/files/lua-5.1.4-test.patch
@@ -0,0 +1,11 @@
+--- test/sieve.lua~    2002-10-31 03:52:58.000000000 +0100
++++ test/sieve.lua     2008-02-20 17:44:22.468281121 +0100
+@@ -14,7 +14,7 @@
+     while 1 do
+       local n = g()
+       if n == nil then return end
+-      if math.mod(n, p) ~= 0 then coroutine.yield(n) end
++      if math.fmod(n, p) ~= 0 then coroutine.yield(n) end
+     end
+   end)
+ end

diff --git a/dev-lang/lua/files/lua-5.3-make.patch 
b/dev-lang/lua/files/lua-5.2-make-r1.patch
similarity index 95%
copy from dev-lang/lua/files/lua-5.3-make.patch
copy to dev-lang/lua/files/lua-5.2-make-r1.patch
index f84176d..a0624af 100644
--- a/dev-lang/lua/files/lua-5.3-make.patch
+++ b/dev-lang/lua/files/lua-5.2-make-r1.patch
@@ -43,8 +43,9 @@
 -$(LUAC_T): $(LUAC_O) $(LUA_A)
 +origin$(LUAC_T): $(LUAC_O) $(LUA_A)
 @@ -185,3 +185,30 @@
- lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \
-   lobject.h ltm.h lzio.h
+ lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
+  lzio.h
+
 +
 +export LIBTOOL = $(EROOT)usr/bin/libtool --quiet --tag=CC
 +export LIB_VERSION = 6:1:1
@@ -72,5 +73,3 @@
 +      $(LIBTOOL) --mode=clean $(RM) $(ALL_O:.o=.lo) $(LIB_NAME) lua$V luac$V
 +
 +gentoo_all: $(LIB_NAME) $(LUA_T) $(LUAC_T)
- 
- # (end of Makefile)

diff --git a/dev-lang/lua/files/lua-5.3-make.patch 
b/dev-lang/lua/files/lua-5.3-make.patch
index f84176d..ed22597 100644
--- a/dev-lang/lua/files/lua-5.3-make.patch
+++ b/dev-lang/lua/files/lua-5.3-make.patch
@@ -1,16 +1,16 @@
 --- lua-5.1.1.orig/Makefile    2006-06-02 12:53:38.000000000 +0200
 +++ lua-5.1.1/Makefile 2006-11-16 02:16:53.000000000 +0100
-@@ -11,7 +11,7 @@
- # so take care if INSTALL_TOP is not an absolute path.
+@@ -12,7 +12,7 @@
+ # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
  INSTALL_TOP= /usr/local
  INSTALL_BIN= $(INSTALL_TOP)/bin
 -INSTALL_INC= $(INSTALL_TOP)/include
 +INSTALL_INC= $(INSTALL_TOP)/include/lua$V
  INSTALL_LIB= $(INSTALL_TOP)/lib
  INSTALL_MAN= $(INSTALL_TOP)/man/man1
- #
-@@ -127,3 +127,18 @@
- .PHONY: all $(PLATS) clean install local none dummy echo pecho lecho newer
+ INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
+@@ -112,3 +112,18 @@
+ .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
  
  # (end of Makefile)
 +
@@ -36,15 +36,16 @@
 @@ -42,1 +42,1 @@
 -LUAC_T=       luac
 +LUAC_T=       luac$V
-@@ -54,1 +54,1 @@
+@@ -62,1 +62,1 @@
 -$(LUA_T): $(LUA_O) $(LUA_A)
 +origin$(LUA_T): $(LUA_O) $(LUA_A)
-@@ -57,1 +57,1 @@
+@@ -65,1 +65,1 @@
 -$(LUAC_T): $(LUAC_O) $(LUA_A)
 +origin$(LUAC_T): $(LUAC_O) $(LUA_A)
-@@ -185,3 +185,30 @@
- lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \
-   lobject.h ltm.h lzio.h
+@@ -195,3 +195,30 @@
+  lobject.h ltm.h lzio.h
+ 
+ # (end of Makefile)
 +
 +export LIBTOOL = $(EROOT)usr/bin/libtool --quiet --tag=CC
 +export LIB_VERSION = 6:1:1
@@ -72,5 +73,3 @@
 +      $(LIBTOOL) --mode=clean $(RM) $(ALL_O:.o=.lo) $(LIB_NAME) lua$V luac$V
 +
 +gentoo_all: $(LIB_NAME) $(LUA_T) $(LUAC_T)
- 
- # (end of Makefile)

diff --git a/dev-lang/lua/lua-5.3.0.ebuild b/dev-lang/lua/lua-5.1.5-r101.ebuild
similarity index 59%
copy from dev-lang/lua/lua-5.3.0.ebuild
copy to dev-lang/lua/lua-5.1.5-r101.ebuild
index 45e8629..bcfd7b1 100644
--- a/dev-lang/lua/lua-5.3.0.ebuild
+++ b/dev-lang/lua/lua-5.1.5-r101.ebuild
@@ -1,46 +1,56 @@
 # 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; $
+# $Id$
 
-EAPI="5"
+EAPI=5
 
-inherit eutils autotools multilib multilib-minimal portability toolchain-funcs 
versionator
+inherit eutils multilib multilib-minimal portability toolchain-funcs 
versionator
 
 DESCRIPTION="A powerful light-weight programming language designed for 
extending applications"
 HOMEPAGE="http://www.lua.org/";
 SRC_URI="http://www.lua.org/ftp/${P}.tar.gz";
 
 LICENSE="MIT"
-SLOT="5.3"
+SLOT="5.1"
 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc 
~x86 ~amd64-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
 IUSE="+deprecated emacs readline static"
 
-RDEPEND="readline? ( sys-libs/readline )
-       app-admin/eselect-lua
+RDEPEND="readline? ( >=sys-libs/readline-6.2_p5-r1[${MULTILIB_USEDEP}] )
+       app-eselect/eselect-lua
        !dev-lang/lua:0"
 DEPEND="${RDEPEND}
        sys-devel/libtool"
 PDEPEND="emacs? ( app-emacs/lua-mode )"
 
+SAN_SLOT="${SLOT//.}"
+
 MULTILIB_WRAPPED_HEADERS=(
        /usr/include/lua${SLOT}/luaconf.h
 )
 
 src_prepare() {
-       local PATCH_PV=$(get_version_component_range 1-2)
+       local PATCH_PV=${SLOT}
 
-       epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make.patch
+       epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r2.patch
+       epatch "${FILESDIR}"/${PN}-${PATCH_PV}-module_paths.patch
 
        [ -d "${FILESDIR}/${PV}" ] && \
                EPATCH_SOURCE="${FILESDIR}/${PV}" 
EPATCH_SUFFIX="upstream.patch" epatch
 
-       sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html || die
+       # correct lua versioning
+       sed -i -e 's/\(LIB_VERSION = \)6:1:1/\16:5:1/' src/Makefile
 
-       if ! use readline ; then
-               sed -i -e '/#define LUA_USE_READLINE/d' src/luaconf.h || die
+       sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html
+
+       if ! use deprecated ; then
+               # patches from 5.1.4 still apply
+               epatch "${FILESDIR}"/${PN}-5.1.4-deprecated.patch
+               epatch "${FILESDIR}"/${PN}-5.1.4-test.patch
        fi
 
-       sed -i -e 's/\(LIB_VERSION = \)6:1:1/\10:0:0/' src/Makefile || die
+       if ! use readline ; then
+               epatch "${FILESDIR}"/${PN}-${PATCH_PV}-readline.patch
+       fi
 
        # Using dynamic linked lua is not recommended for performance
        # reasons. http://article.gmane.org/gmane.comp.lang.lua.general/18519
@@ -49,63 +59,49 @@ src_prepare() {
        # compiler (built statically) nor the lua libraries (both shared and 
static
        # are installed)
        if use static ; then
-               sed -i -e 's:\(-export-dynamic\):-static \1:' src/Makefile || 
die
+               epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make_static-r1.patch
        fi
 
-       # upstream does not use libtool, but we do (see bug #336167)
-       cp "${FILESDIR}/configure.in" "${S}"/ || die
-       eautoreconf
-
        # custom Makefiles
        multilib_copy_sources
 }
 
 multilib_src_configure() {
+       # We want packages to find our things...
        sed -i \
-               -e 's:\(define LUA_ROOT\s*\).*:\1"'${EPREFIX}'/usr/":' \
-               -e "s:\(define LUA_CDIR\s*LUA_ROOT \"\)lib:\1$(get_libdir):" \
-               src/luaconf.h \
-       || die "failed patching luaconf.h"
-
-       econf
+               -e 's:/usr/local:'${EPREFIX}'/usr:' \
+               -e "s:\([/\"]\)\<lib\>:\1$(get_libdir):g" \
+               etc/lua.pc src/luaconf.h || die
 }
 
 multilib_src_compile() {
        tc-export CC
-
+       myflags=
        # what to link to liblua
        liblibs="-lm"
        liblibs="${liblibs} $(dlopen_lib)"
 
        # what to link to the executables
        mylibs=
-       use readline && mylibs="-lreadline"
+       if use readline; then
+               mylibs="-lreadline"
+       fi
 
        cd src
-
-       local myCFLAGS=""
-       use deprecated && myCFLAGS="-DLUA_COMPAT_5_2 -DLUA_COMPAT_5_1"
-# -DLUA_COMPAT_FLOATSTRING"
-
-       case "${CHOST}" in
-               *-mingw*) : ;;
-               *) myCFLAGS+=" -DLUA_USE_LINUX" ;;
-       esac
-
-       emake CC="${CC}" CFLAGS="${myCFLAGS} ${CFLAGS}" \
-                       SYSLDFLAGS="${LDFLAGS}" \
+       emake CC="${CC}" CFLAGS="-DLUA_USE_LINUX ${CFLAGS}" \
                        RPATH="${EPREFIX}/usr/$(get_libdir)/" \
                        LUA_LIBS="${mylibs}" \
                        LIB_LIBS="${liblibs}" \
                        V=$(get_version_component_range 1-2) \
                        gentoo_all
+
+       mv lua_test ../test/lua.static
 }
 
 multilib_src_install() {
        emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
                        V=${SLOT} gentoo_install
 
-       # We want packages to find our things...
        cp "${FILESDIR}/lua.pc" "${WORKDIR}"
        sed \
                -e "s:^V=.*:V= ${SLOT}:" \
@@ -118,13 +114,27 @@ multilib_src_install() {
 }
 
 multilib_src_install_all() {
-       dodoc README
+       dodoc HISTORY README
        dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
 
+       doicon etc/lua.ico
+
        newman doc/lua.1 lua${SLOT}.1
        newman doc/luac.1 luac${SLOT}.1
 }
 
-# Makefile contains a dummy target that doesn't do tests
-# but causes issues with slotted lua (bug #510360)
-src_test() { :; }
+multilib_src_test() {
+       local positive="bisect cf echo env factorial fib fibfor hello printf 
sieve
+       sort trace-calls trace-globals"
+       local negative="readonly"
+       local test
+
+       cd "${BUILD_DIR}" || die
+       for test in ${positive}; do
+               test/lua.static test/${test}.lua || die "test $test failed"
+       done
+
+       for test in ${negative}; do
+               test/lua.static test/${test}.lua && die "test $test failed"
+       done
+}

diff --git a/dev-lang/lua/lua-5.3.0.ebuild b/dev-lang/lua/lua-5.2.4.ebuild
similarity index 89%
copy from dev-lang/lua/lua-5.3.0.ebuild
copy to dev-lang/lua/lua-5.2.4.ebuild
index 45e8629..d3d989d 100644
--- a/dev-lang/lua/lua-5.3.0.ebuild
+++ b/dev-lang/lua/lua-5.2.4.ebuild
@@ -1,22 +1,22 @@
 # 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; $
+# $Id$
 
-EAPI="5"
+EAPI=5
 
-inherit eutils autotools multilib multilib-minimal portability toolchain-funcs 
versionator
+inherit eutils autotools multilib multilib-minimal portability toolchain-funcs
 
 DESCRIPTION="A powerful light-weight programming language designed for 
extending applications"
 HOMEPAGE="http://www.lua.org/";
 SRC_URI="http://www.lua.org/ftp/${P}.tar.gz";
 
 LICENSE="MIT"
-SLOT="5.3"
+SLOT="5.2"
 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc 
~x86 ~amd64-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
 IUSE="+deprecated emacs readline static"
 
 RDEPEND="readline? ( sys-libs/readline )
-       app-admin/eselect-lua
+       app-eselect/eselect-lua
        !dev-lang/lua:0"
 DEPEND="${RDEPEND}
        sys-devel/libtool"
@@ -27,21 +27,22 @@ MULTILIB_WRAPPED_HEADERS=(
 )
 
 src_prepare() {
-       local PATCH_PV=$(get_version_component_range 1-2)
+       local PATCH_PV=${SLOT}
 
-       epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make.patch
+       epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r1.patch
 
        [ -d "${FILESDIR}/${PV}" ] && \
                EPATCH_SOURCE="${FILESDIR}/${PV}" 
EPATCH_SUFFIX="upstream.patch" epatch
 
+       # correct lua versioning
+       sed -i -e 's/\(LIB_VERSION = \)6:1:1/\10:0:0/' src/Makefile || die
+
        sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html || die
 
        if ! use readline ; then
                sed -i -e '/#define LUA_USE_READLINE/d' src/luaconf.h || die
        fi
 
-       sed -i -e 's/\(LIB_VERSION = \)6:1:1/\10:0:0/' src/Makefile || die
-
        # Using dynamic linked lua is not recommended for performance
        # reasons. http://article.gmane.org/gmane.comp.lang.lua.general/18519
        # Mainly, this is of concern if your arch is poor with GPRs, like x86
@@ -84,8 +85,7 @@ multilib_src_compile() {
        cd src
 
        local myCFLAGS=""
-       use deprecated && myCFLAGS="-DLUA_COMPAT_5_2 -DLUA_COMPAT_5_1"
-# -DLUA_COMPAT_FLOATSTRING"
+       use deprecated && myCFLAGS="-DLUA_COMPAT_ALL"
 
        case "${CHOST}" in
                *-mingw*) : ;;
@@ -97,7 +97,7 @@ multilib_src_compile() {
                        RPATH="${EPREFIX}/usr/$(get_libdir)/" \
                        LUA_LIBS="${mylibs}" \
                        LIB_LIBS="${liblibs}" \
-                       V=$(get_version_component_range 1-2) \
+                       V=${SLOT} \
                        gentoo_all
 }
 

diff --git a/dev-lang/lua/lua-5.3.0.ebuild b/dev-lang/lua/lua-5.3.1.ebuild
similarity index 95%
rename from dev-lang/lua/lua-5.3.0.ebuild
rename to dev-lang/lua/lua-5.3.1.ebuild
index 45e8629..04f3437 100644
--- a/dev-lang/lua/lua-5.3.0.ebuild
+++ b/dev-lang/lua/lua-5.3.1.ebuild
@@ -4,7 +4,7 @@
 
 EAPI="5"
 
-inherit eutils autotools multilib multilib-minimal portability toolchain-funcs 
versionator
+inherit eutils autotools multilib multilib-minimal portability toolchain-funcs
 
 DESCRIPTION="A powerful light-weight programming language designed for 
extending applications"
 HOMEPAGE="http://www.lua.org/";
@@ -16,7 +16,7 @@ KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 
~s390 ~sh ~sparc ~x86
 IUSE="+deprecated emacs readline static"
 
 RDEPEND="readline? ( sys-libs/readline )
-       app-admin/eselect-lua
+       app-eselect/eselect-lua
        !dev-lang/lua:0"
 DEPEND="${RDEPEND}
        sys-devel/libtool"
@@ -27,7 +27,7 @@ MULTILIB_WRAPPED_HEADERS=(
 )
 
 src_prepare() {
-       local PATCH_PV=$(get_version_component_range 1-2)
+       local PATCH_PV=${SLOT}
 
        epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make.patch
 
@@ -97,7 +97,7 @@ multilib_src_compile() {
                        RPATH="${EPREFIX}/usr/$(get_libdir)/" \
                        LUA_LIBS="${mylibs}" \
                        LIB_LIBS="${liblibs}" \
-                       V=$(get_version_component_range 1-2) \
+                       V=${SLOT} \
                        gentoo_all
 }
 

diff --git a/dev-lang/luajit/luajit-2.0.9999.ebuild 
b/dev-lang/luajit/luajit-2.0.9999.ebuild
index 67c9fb0..ff280a5 100644
--- a/dev-lang/luajit/luajit-2.0.9999.ebuild
+++ b/dev-lang/luajit/luajit-2.0.9999.ebuild
@@ -10,7 +10,7 @@ DESCRIPTION="Just-In-Time Compiler for the Lua programming 
language"
 HOMEPAGE="http://luajit.org/";
 SRC_URI=""
 EGIT_REPO_URI="git://repo.or.cz/luajit-2.0.git"
-SLOT="2.0"
+SLOT="2"
 
 LICENSE="MIT"
 KEYWORDS=""
@@ -53,28 +53,36 @@ pkg_setup() {
 
 src_prepare(){
        # fixing prefix and version
+#      sed -r \
+#              -e 's|^(VERSION)=.*|\1=$(MAJVER).$(MINVER)|' \
+#              -e 's|\$\(MAJVER\)\.\$\(MINVER\)\.\$\(RELVER\)|$(VERSION)|' \
+#              -e 's|^(FILE_MAN)=.*|\1=${PN}-$(VERSION).1|' \
+#              -e 's|^(INSTALL_PCNAME)=.*|\1=${PN}-$(VERSION).pc|' \
+#              -e 's|^(INSTALL_SOSHORT)=.*|\1=lib${PN}-${SLOT}.so|' \
+#              -e 's|^(INSTALL_ANAME)=.*|\1=lib${PN}-${SLOT}.a|' \
+#              -e 's|^(INSTALL_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+#              -e 's|( PREFIX)=.*|\1=/usr|' \
+#              -e '/\$\(SYMLINK\)\ \$\(INSTALL_TNAME\)\ \$\(INSTALL_TSYM\)/d' \
+#              -i Makefile || die "failed to fix prefix in Makefile"
+
        sed -r \
-               -e 's|^(VERSION)=.*|\1=$(MAJVER).$(MINVER)|' \
-               -e 's|^(FILE_MAN)=.*|\1=${PN}-$(VERSION).1|' \
+               -e 's|^(VERSION)=.*|\1=${PV}|' \
                -e 's|\$\(MAJVER\)\.\$\(MINVER\)\.\$\(RELVER\)|$(VERSION)|' \
-               -e 's|^(INSTALL_PCNAME)=.*|\1=${PN}-$(VERSION).pc|' \
-               -e 's|^(INSTALL_SOSHORT)=.*|\1=lib${PN}-${SLOT}.so|' \
-               -e 's|^(INSTALL_ANAME)=.*|\1=lib${PN}-${SLOT}.a|' \
-               -e 's|^(INSTALL_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+               -e 's|^(INSTALL_PCNAME)=.*|\1=${P}.pc|' \
                -e 's|( PREFIX)=.*|\1=/usr|' \
-               -e '/\$\(SYMLINK\)\ \$\(INSTALL_TNAME\)\ \$\(INSTALL_TSYM\)/d' \
+               -e 's|^(FILE_MAN)=.*|\1=${P}.1|' \
                -i Makefile || die "failed to fix prefix in Makefile"
 
-       sed -r \
-               -e 's|^(libname=.*-)\$\{abiver\}|\1${majver}.${minver}|' \
-               -i "etc/${PN}.pc" || die "Failed to slottify"
+#      sed -r \
+#              -e 's|^(libname=.*-)\$\{abiver\}|\1${majver}.${minver}|' \
+#              -i "etc/${PN}.pc" || die "Failed to slottify"
 
-       sed -r \
-               -e 's|^(TARGET_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
-               -i src/Makefile || die "Failed to slottify"
+#      sed -r \
+#              -e 's|^(TARGET_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+#              -i src/Makefile || die "Failed to slottify"
 
        sed -r \
-               -e 's|^(#define LUA_LJDIR).*|\1 "/'${PN}-${SLOT}'/"|' \
+               -e 's|^(#define LUA_LJDIR).*|\1 "/'${P}'/"|' \
                -i src/luaconf.h || die "Failed to slotify"
 
        use debug && (
@@ -82,7 +90,7 @@ src_prepare(){
                        -e 's/#(CCDEBUG= -g)/\1 -ggdb/' \
                        -i src/Makefile || die "Failed to enable debug"
        )
-       mv "${S}"/etc/${PN}.1 "${S}"/etc/${PN}-${SLOT}.1
+       mv "${S}"/etc/${PN}.1 "${S}"/etc/${P}.1
 
        multilib_copy_sources
 }
@@ -120,16 +128,17 @@ multilib_src_install() {
 
        base_src_install_docs
 
-       host-is-pax && pax-mark m "${ED}usr/bin/${PN}-${SLOT}"
-       newman "etc/${PN}-${SLOT}.1" "luacjit-${SLOT}.1"
-       newbin "${FILESDIR}/luac.jit" "luacjit-${SLOT}"
+       host-is-pax && pax-mark m "${ED}usr/bin/${P}"
+       newman "etc/${P}.1" "luacjit-${PV}.1"
+       newbin "${FILESDIR}/luac.jit" "luacjit-${PV}"
+       ln -s "${P}" "${ED}usr/bin/${PN}-${SLOT}"
 }
 
 pkg_postinst() {
        if [[ ! -n $(readlink "${ROOT}"usr/bin/luajit) ]] ; then
-               eselect luajit set luajit-${SLOT}
+               eselect luajit set luajit-${PV}
        fi
        if [[ ! -n $(readlink "${ROOT}"usr/bin/lua) ]] ; then
-               eselect lua set jit-${SLOT}
+               eselect lua set jit-${PV}
        fi
 }

diff --git a/dev-lang/luajit/luajit-2.1.9999.ebuild 
b/dev-lang/luajit/luajit-2.1.9999.ebuild
index ba75be0..9d5a682 100644
--- a/dev-lang/luajit/luajit-2.1.9999.ebuild
+++ b/dev-lang/luajit/luajit-2.1.9999.ebuild
@@ -10,8 +10,8 @@ DESCRIPTION="Just-In-Time Compiler for the Lua programming 
language"
 HOMEPAGE="http://luajit.org/";
 SRC_URI=""
 EGIT_REPO_URI="git://repo.or.cz/luajit-2.0.git"
-SLOT="2.1"
-EGIT_BRANCH="v${SLOT}"
+SLOT="2"
+EGIT_BRANCH="v2.1"
 
 LICENSE="MIT"
 KEYWORDS=""
@@ -54,28 +54,36 @@ pkg_setup() {
 
 src_prepare(){
        # fixing prefix and version
+#      sed -r \
+#              -e 's|^(VERSION)=.*|\1=$(MAJVER).$(MINVER)|' \
+#              -e 's|\$\(MAJVER\)\.\$\(MINVER\)\.\$\(RELVER\)|$(VERSION)|' \
+#              -e 's|^(FILE_MAN)=.*|\1=${PN}-$(VERSION).1|' \
+#              -e 's|^(INSTALL_PCNAME)=.*|\1=${PN}-$(VERSION).pc|' \
+#              -e 's|^(INSTALL_SOSHORT)=.*|\1=lib${PN}-${SLOT}.so|' \
+#              -e 's|^(INSTALL_ANAME)=.*|\1=lib${PN}-${SLOT}.a|' \
+#              -e 's|^(INSTALL_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+#              -e 's|( PREFIX)=.*|\1=/usr|' \
+#              -e '/\$\(SYMLINK\)\ \$\(INSTALL_TNAME\)\ \$\(INSTALL_TSYM\)/d' \
+#              -i Makefile || die "failed to fix prefix in Makefile"
+
        sed -r \
-               -e 's|^(VERSION)=.*|\1=$(MAJVER).$(MINVER)|' \
-               -e 's|^(FILE_MAN)=.*|\1=${PN}-$(VERSION).1|' \
+               -e 's|^(VERSION)=.*|\1=${PV}|' \
                -e 's|\$\(MAJVER\)\.\$\(MINVER\)\.\$\(RELVER\)|$(VERSION)|' \
-               -e 's|^(INSTALL_PCNAME)=.*|\1=${PN}-$(VERSION).pc|' \
-               -e 's|^(INSTALL_SOSHORT)=.*|\1=lib${PN}-${SLOT}.so|' \
-               -e 's|^(INSTALL_ANAME)=.*|\1=lib${PN}-${SLOT}.a|' \
-               -e 's|^(INSTALL_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+               -e 's|^(INSTALL_PCNAME)=.*|\1=${P}.pc|' \
                -e 's|( PREFIX)=.*|\1=/usr|' \
-               -e '/\$\(SYMLINK\)\ \$\(INSTALL_TNAME\)\ \$\(INSTALL_TSYM\)/d' \
+               -e 's|^(FILE_MAN)=.*|\1=${P}.1|' \
                -i Makefile || die "failed to fix prefix in Makefile"
 
-       sed -r \
-               -e 's|^(libname=.*-)\$\{abiver\}|\1${majver}.${minver}|' \
-               -i "etc/${PN}.pc" || die "Failed to slottify"
+#      sed -r \
+#              -e 's|^(libname=.*-)\$\{abiver\}|\1${majver}.${minver}|' \
+#              -i "etc/${PN}.pc" || die "Failed to slottify"
 
-       sed -r \
-               -e 's|^(TARGET_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
-               -i src/Makefile || die "Failed to slottify"
+#      sed -r \
+#              -e 's|^(TARGET_SONAME)=.*|\1=lib${PN}-${SLOT}.so.${PV}|' \
+#              -i src/Makefile || die "Failed to slottify"
 
        sed -r \
-               -e 's|^(#define LUA_LJDIR).*|\1 "/'${PN}-${SLOT}'/"|' \
+               -e 's|^(#define LUA_LJDIR).*|\1 "/'${P}'/"|' \
                -i src/luaconf.h || die "Failed to slotify"
 
        use debug && (
@@ -83,7 +91,7 @@ src_prepare(){
                        -e 's/#(CCDEBUG= -g)/\1 -ggdb/' \
                        -i src/Makefile || die "Failed to enable debug"
        )
-       mv "${S}"/etc/${PN}.1 "${S}"/etc/${PN}-${SLOT}.1
+       mv "${S}"/etc/${PN}.1 "${S}"/etc/${P}.1
 
        multilib_copy_sources
 }
@@ -121,16 +129,17 @@ multilib_src_install() {
 
        base_src_install_docs
 
-       host-is-pax && pax-mark m "${ED}usr/bin/${PN}-${SLOT}"
-       newman "etc/${PN}-${SLOT}.1" "luacjit-${SLOT}.1"
-       newbin "${FILESDIR}/luac.jit" "luacjit-${SLOT}"
+       host-is-pax && pax-mark m "${ED}usr/bin/${P}"
+       newman "etc/${P}.1" "luacjit-${PV}.1"
+       newbin "${FILESDIR}/luac.jit" "luacjit-${PV}"
+       ln -s "${P}" "${ED}usr/bin/${PN}-${SLOT}"
 }
 
 pkg_postinst() {
        if [[ ! -n $(readlink "${ROOT}"usr/bin/luajit) ]] ; then
-               eselect luajit set luajit-${SLOT}
+               eselect luajit set luajit-${PV}
        fi
        if [[ ! -n $(readlink "${ROOT}"usr/bin/lua) ]] ; then
-               eselect lua set jit-${SLOT}
+               eselect lua set jit-${PV}
        fi
 }

diff --git a/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild 
b/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
index 8f4faad..a364492 100644
--- a/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
+++ b/dev-lua/LuaBitOp/LuaBitOp-1.0.2.ebuild
@@ -3,7 +3,11 @@
 # $Header: This ebuild is from Lua overlay; Bumped by mva; $
 
 EAPI="5"
-inherit eutils multilib toolchain-funcs
+
+IS_MULTILIB=true
+#LUA_COMPAT="lua51" #actually. But lj, l52 and l53 can load it too
+
+inherit lua
 
 DESCRIPTION="Bit Operations Library for the Lua Programming Language"
 HOMEPAGE="http://bitop.luajit.org";
@@ -12,30 +16,20 @@ SRC_URI="http://bitop.luajit.org/download/${P}.tar.gz";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS="~amd64 ~x86"
-IUSE="luajit"
+IUSE="doc"
 
-DEPEND="virtual/lua[luajit=]"
-RDEPEND="${DEPEND}"
-
-src_prepare() {
-       sed -i \
-               -e '/^CFLAGS.*=/s/=/ +=/' \
-               -e '/^CFLAGS/s/-O2 -fomit-frame-pointer //' \
-               Makefile || die "sed failed"
-}
+READMES=( README )
+HTML_DOCS=( doc/ )
 
-src_compile() {
-       emake CC="$(tc-getCC)"
+each_lua_compile() {
+       _lua_setCFLAGS
+       emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"
 }
 
-src_test() {
-       make test
+each_lua_test() {
+       emake LUA=${LUA} test
 }
 
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
-       exeinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})"
-       doexe bit.so
-       dohtml -r doc/*
+each_lua_install() {
+       dolua bit.so
 }

diff --git a/dev-lua/alt-getopt/alt-getopt-0.7.0.ebuild 
b/dev-lua/alt-getopt/alt-getopt-0.7.0.ebuild
index f1bf451..d63617f 100644
--- a/dev-lua/alt-getopt/alt-getopt-0.7.0.ebuild
+++ b/dev-lua/alt-getopt/alt-getopt-0.7.0.ebuild
@@ -4,41 +4,27 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs
+inherit lua
 
 DESCRIPTION="Lua bindings to getopt_long"
 HOMEPAGE="http://luaforge.net/projects/alt-getopt";
-SRC_URI="mirror://luaforge/${PN}/${PN}/${PN}-${PV}/lua-${PN}-${PV}.tar.gz"
+MY_P="lua-${P}"
+SRC_URI="mirror://luaforge/${PN}/${PN}/${P}/${MY_P}.tar.gz"
 
 LICENSE="MIT"
 SLOT="0"
-KEYWORDS="x86 amd64"
-IUSE="luajit"
+KEYWORDS="~x86 ~amd64"
+IUSE=""
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
+READMES=( README )
 
-DOCS=( "README" )
+S="${WORKDIR}/all/${MY_P}"
+LUA_S="${MY_P}"
 
-S="${WORKDIR}/lua-${P}"
-
-src_compile() {
-       :
+each_lua_install() {
+       dolua alt_getopt.lua
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins alt_getopt.lua
-
+all_lua_install() {
        dobin alt_getopt
-
-       base_src_install_docs
 }

diff --git a/dev-lua/ansicolors/ansicolors-9999.ebuild 
b/dev-lua/ansicolors/ansicolors-9999.ebuild
index e79aa3f..e2ac7aa 100644
--- a/dev-lua/ansicolors/ansicolors-9999.ebuild
+++ b/dev-lua/ansicolors/ansicolors-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS=git-r3
+inherit lua
 
 DESCRIPTION="A simple Lua function for printing to the console in color."
 HOMEPAGE="https://github.com/kikito/ansicolors.lua";
@@ -15,24 +16,10 @@ EGIT_REPO_URI="https://github.com/kikito/ansicolors.lua";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
+READMES=( "README.textile" )
 
-HTML_DOCS=( "README.textile" )
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r ansicolors.lua
-
-       base_src_install_docs
+each_lua_install() {
+       dolua ansicolors.lua
 }

diff --git a/dev-lua/captcha/captcha-9999.ebuild 
b/dev-lua/captcha/captcha-9999.ebuild
index 2e93aa4..a61d2a5 100644
--- a/dev-lua/captcha/captcha-9999.ebuild
+++ b/dev-lua/captcha/captcha-9999.ebuild
@@ -4,10 +4,11 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A small lua module to generate CAPTCHA images using lua-gd"
-HOMEPAGE="https://github.com/mrDoctorWho/lua-${PN}";
+HOMEPAGE="https://github.com/mrDoctorWho/lua-captcha";
 SRC_URI=""
 
 EGIT_REPO_URI="https://github.com/mrDoctorWho/lua-${PN}";
@@ -15,32 +16,19 @@ EGIT_REPO_URI="https://github.com/mrDoctorWho/lua-${PN}";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="jpeg luajit png +samples"
+IUSE="jpeg png +examples"
+
+READMES=( README.md )
+EXAMPLES=( examples/* )
 
 RDEPEND="
-       virtual/lua[luajit=]
-       dev-lua/lua-gd[luajit=]
+       dev-lua/lua-gd
        media-libs/gd[jpeg=,truetype,png=]
 "
 
 REQUIRED_USE="|| ( jpeg png )"
 
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_compile() { :; }
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r src/*
-
-       if use samples; then
-               docompress -x /usr/share/doc/${PF}/examples
-               dodoc -r examples
-       fi
+each_lua_install() {
+       dolua src/*
 }
+

diff --git a/dev-lua/cmsgpack/cmsgpack-9999.ebuild 
b/dev-lua/cmsgpack/cmsgpack-9999.ebuild
index b44942b..85cdaf9 100644
--- a/dev-lua/cmsgpack/cmsgpack-9999.ebuild
+++ b/dev-lua/cmsgpack/cmsgpack-9999.ebuild
@@ -4,42 +4,34 @@
 
 EAPI="5"
 
-inherit toolchain-funcs git-r3
+IS_MULTILIB=true
+VCS="git-r3"
+
+inherit lua
 
 DESCRIPTION="A self contained Lua MessagePack C implementation"
 HOMEPAGE="https://github.com/antirez/lua-cmsgpack";
 
-MY_PN="lua_${PN}"
-
 EGIT_REPO_URI="https://github.com/antirez/lua-cmsgpack";
 KEYWORDS=""
-DOCS=( README.md )
+READMES=( README.md )
 
 LICENSE="BSD-2"
 SLOT="0"
-IUSE="luajit test"
+IUSE="test"
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}"
+each_lua_compile() {
+       _lua_setCFLAGS
+       local MY_PN="lua_${PN}"
 
-src_compile() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       export CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) --cflags ${lua})"
        $(tc-getCC) -fPIC ${CFLAGS} -c -o ${MY_PN}.o ${MY_PN}.c || die
        $(tc-getCC) ${LDFLAGS} -shared -o ${PN}.so ${MY_PN}.o || die
 }
 
-src_test() {
-       lua test.lua || die
+each_lua_test() {
+       ${LUA} test.lua || die
 }
 
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
-       default
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})"
-       doins "${PN}".so
+each_lua_install() {
+       dolua "${PN}.so"
 }

diff --git a/dev-lua/cosmo/cosmo-9999.ebuild b/dev-lua/cosmo/cosmo-9999.ebuild
index 6b85277..bdd7030 100644
--- a/dev-lua/cosmo/cosmo-9999.ebuild
+++ b/dev-lua/cosmo/cosmo-9999.ebuild
@@ -4,52 +4,32 @@
 
 EAPI="5"
 
-inherit multilib eutils git-r3 toolchain-funcs
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="safe-template engine for lua"
 HOMEPAGE="https://github.com/mascarenhas/cosmo";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/msva/cosmo.git";
+EGIT_REPO_URI="https://github.com/mascarenhas/cosmo.git";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        || (
                dev-lua/lpeg
                dev-lua/lulpeg[lpeg-compat]
        )
 "
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-src_prepare() {
-    local lua=lua
-    use luajit && lua=luajit
-    echo "
-        LUA_DIR=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})
-        DESTDIR=${ED}
-    " > "${S}/config"
-}
 
-src_configure() {
-    :
-}
+DOCS=( README doc/cosmo.md )
+HTML_DOCS=( doc/index.html doc/cosmo.png )
+EXAMPLES=( samples/sample.lua )
 
-src_install() {
-    docompress -x /usr/share/doc
-    default
-    use doc && (
-        insinto /usr/share/doc/${PF}/examples
-        doins -r samples/*
-        insinto /usr/share/doc/${PF}
-        doins -r doc/*
-    )
+each_lua_install() {
+       dolua src/*
 }
 

diff --git a/dev-lua/coxpcall/coxpcall-9999.ebuild 
b/dev-lua/coxpcall/coxpcall-9999.ebuild
index 3d05e24..83f9f18 100644
--- a/dev-lua/coxpcall/coxpcall-9999.ebuild
+++ b/dev-lua/coxpcall/coxpcall-9999.ebuild
@@ -4,30 +4,23 @@
 
 EAPI="5"
 
-inherit multilib eutils git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Lua coxpcall Library"
 HOMEPAGE="https://github.com/keplerproject/coxpcall";
 SRC_URI=""
 
 #s/msva/keplerproject/ when they apply pull-request
-EGIT_REPO_URI="git://github.com/msva/coxpcall.git 
https://github.com/msva/coxpcall.git";
+EGIT_REPO_URI="https://github.com/msva/coxpcall.git";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc"
 
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="${RDEPEND}"
+HTML_DOCS=( doc/us/ )
 
-src_configure() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       ./configure "${lua}"
-}
-
-src_install() {
-       emake DESTDIR="${D}" install
-       use doc && emake DESTDIR="${D}" DOC_PREFIX=/usr/share/doc/${PF}/ 
install-doc
+each_lua_install() {
+       dolua src/*
 }

diff --git a/dev-lua/iluajit/iluajit-9999.ebuild 
b/dev-lua/iluajit/iluajit-9999.ebuild
index f888097..8273747 100644
--- a/dev-lua/iluajit/iluajit-9999.ebuild
+++ b/dev-lua/iluajit/iluajit-9999.ebuild
@@ -4,7 +4,10 @@
 
 EAPI="5"
 
-inherit eutils git-r3 toolchain-funcs
+LUA_COMPAT="luajit2"
+VCS="git-r3"
+
+inherit lua
 
 DESCRIPTION="Readline powered shell for LuaJIT"
 HOMEPAGE="https://github.com/jdesgats/ILuaJIT";
@@ -19,26 +22,24 @@ IUSE="doc +completion"
 
 RDEPEND="
        doc? ( dev-lua/luadoc )
-       virtual/lua[luajit]
        dev-lua/penlight
        sys-libs/readline
        completion? ( dev-lua/luafilesystem )
-       virtual/pkgconfig
 "
 DEPEND="${RDEPEND}"
 
-src_install() {
-       local lmod="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD luajit)"
+READMES=( README.md )
+HTML_DOCS=( html/ )
 
-       dodoc README.md || die "dodoc failed"
-       use doc && (
-               luadoc . -d html
-               dohtml -r html
-       )
+all_lua_prepare() {
+       use doc && luadoc . -d html
+}
 
-       insinto "${lmod}"
-       doins *.lua
+each_lua_install() {
+       dolua *.lua
+}
 
+all_lua_install() {
 #      make_wrapper "${PN}" "luajit -l ${PN}"
        dobin ${FILESDIR}/${PN}
 }

diff --git a/dev-lua/lahttp/lahttp-9999.ebuild 
b/dev-lua/lahttp/lahttp-9999.ebuild
index 1fef463..301b60b 100644
--- a/dev-lua/lahttp/lahttp-9999.ebuild
+++ b/dev-lua/lahttp/lahttp-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs flag-o-matic mercurial eutils
+VCS="mercurial"
+inherit lua
 
 DESCRIPTION="Lua Asynchronous HTTP Library."
 HOMEPAGE="http://code.matthewwild.co.uk/";
@@ -13,22 +14,25 @@ EHG_REPO_URI="http://code.matthewwild.co.uk/${PN}/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-lua/squish
        dev-lua/luasocket
 "
 DEPEND="${RDEPEND}"
 
-src_compile() {
+all_lua_prepare() {
+#              -e "s#net/httpclient#libs/httpclient#" \ #why it there?
+       sed -r \
+               -e 's#(AutoFetchURL 
").*/prosody.im.*(/\?")#\1https://hg.prosody.im/0.8/raw-file/278489ee6e34\2#' \
+               -i squishy
+}
+
+each_lua_compile() {
        squish --use-http
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins lahttp.lua || die
+each_lua_install() {
+       dolua lahttp.lua
 }

diff --git a/dev-lua/lapis/lapis-9999.ebuild b/dev-lua/lapis/lapis-9999.ebuild
index f5bc8e6..b0ac90e 100644
--- a/dev-lua/lapis/lapis-9999.ebuild
+++ b/dev-lua/lapis/lapis-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A web framework for Lua/MoonScript."
 HOMEPAGE="https://github.com/leafo/lapis";
@@ -15,10 +16,9 @@ EGIT_REPO_URI="https://github.com/leafo/lapis";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit moonscript"
+IUSE="doc moonscript"
 
 RDEPEND="
-       virtual/lua[luajit=]
        moonscript? ( dev-lua/moonscript )
        dev-lua/ansicolors
        dev-lua/luasocket
@@ -33,24 +33,21 @@ DEPEND="
        virtual/pkgconfig
 "
 
-HTML_DOCS=( "docs/" "README.md" )
+DOCS=( docs/ README.md )
 
-src_compile() {
-       use moonscript && emake build
+all_lua_prepare() {
+       use moonscript || find "${S}" -type -name '*.moon' -delete
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-
-       use moonscript || find "${S}" -type -name '*.moon' -delete
+each_lua_compile() {
+       use moonscript && emake build
+}
 
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r lapis
+each_lua_install() {
+       use moonscript && dolua lapis.moon
+       dolua lapis
+}
 
+all_lua_install() {
        dobin bin/lapis
-
-       use moonscript && doins lapis.moon
-
-       base_src_install_docs
 }

diff --git a/dev-lua/ldoc/ldoc-9999.ebuild b/dev-lua/ldoc/ldoc-9999.ebuild
index cb39915..4eed4ed 100644
--- a/dev-lua/ldoc/ldoc-9999.ebuild
+++ b/dev-lua/ldoc/ldoc-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit eutils toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A LuaDoc-compatible documentation generation system"
 HOMEPAGE="https://github.com/stevedonovan/LDoc/";
@@ -15,33 +16,29 @@ EGIT_REPO_URI="https://github.com/stevedonovan/LDoc/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit doc"
+IUSE="doc"
 
 RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
+       dev-lua/penlight
 "
 
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit
+DOCS=( doc/doc.md readme.md )
 
-       sed -r \
-               -e "1s#(/usr/bin/env).*#\1 ${lua}#" \
-               -i ldoc.lua
-}
+HTML_DOCS=( doc_html/ ldoc_html/ )
 
-src_compile() { :; }
+all_lua_prepare() {
+       local lua="$(lua_get_implementation)"
 
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
+       cd doc; ${lua} ../ldoc.lua . -d ../doc_html; cd ..
+       cd ldoc; ${lua} ../ldoc.lua . -d ../ldoc_html; cd ..
 
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r ldoc ldoc.lua
+       rm ldoc/{SciTE.properties,config.ld}
+}
+
+each_lua_install() {
+       dolua ldoc ldoc.lua
+}
 
+all_lua_install() {
        newbin ldoc.lua ldoc
 }

diff --git a/dev-lua/linotify/linotify-9999.ebuild 
b/dev-lua/linotify/linotify-9999.ebuild
index 8896ccc..6a4e2a4 100644
--- a/dev-lua/linotify/linotify-9999.ebuild
+++ b/dev-lua/linotify/linotify-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit autotools eutils git-r3
+IS_MULTILIB=true
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="inotify bindings for Lua"
 HOMEPAGE="https://github.com/hoelzro/linotify";
@@ -15,29 +17,18 @@ EGIT_REPO_URI="https://github.com/hoelzro/linotify.git";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="${RDEPEND}"
+RDEPEND="virtual/libc"
 
-src_prepare() {
-       epatch_user
-}
+READMES=( README.md )
 
-src_compile() {
-       LUAPKG_CMD="lua";
-       use luajit && LUAPKG_CMD="luajit";
-       export LUAPKG_CMD;
-       emake \
-               CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) ${LUAPKG_CMD} --cflags) 
-fPIC" \
-               || die "emake failed"
+each_lua_compile() {
+       _lua_setCFLAGS
+       emake LUAPKG_CMD="${lua_impl}"
 }
 
-src_install() {
-       insinto /usr/share/doc/"${P}";
-       doins README.md
-       emake install \
-               DESTDIR="${D}" \
-               INSTALL_PATH="$($(tc-getPKG_CONFIG) ${LUAPKG_CMD} 
--variable=INSTALL_CMOD)" \
-       || die "emake failed"
+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 c56f894..e652395 100644
--- a/dev-lua/ljsyscall/ljsyscall-9999.ebuild
+++ b/dev-lua/ljsyscall/ljsyscall-9999.ebuild
@@ -4,34 +4,29 @@
 
 EAPI="5"
 
-inherit git-r3 eutils
+VCS="git-r3"
+LUA_COMPAT="luajit2"
+inherit lua
 
-DESCRIPTION="Lua JSON Library, written in C"
+DESCRIPTION="LuaJIT Unix syscall FFI"
 HOMEPAGE="https://github.com/justincormack/ljsyscall";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/justincormack/ljsyscall 
git://github.com/justincormack/ljsyscall"
+EGIT_REPO_URI="https://github.com/justincormack/ljsyscall";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="test"
+IUSE="doc +examples test"
 
 RDEPEND="
-       virtual/lua[luajit]
-       || (
-               sys-libs/glibc[arm=,x86=,amd64=,ppc=,mips=]
-               sys-libs/musl[arm=,x86=,amd64=,ppc=,mips=]
-               sys-libs/uclibc[arm=,x86=,amd64=,ppc=,mips=]
-       )
+       virtual/libc
 "
-REQUIRED_USE="^^ ( arm x86 amd64 ppc mips )"
 DEPEND="${RDEPEND}"
 
-DOCS=( "${S}"/README.md )
+DOCS=( README.md doc/)
+EXAMPLES=( examples/* )
 
-src_install() {
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD luajit)"
-       doins -r syscall syscall.lua
-       default
+each_lua_install() {
+       dolua syscall syscall.lua
 }

diff --git a/dev-lua/lpc/lpc-9999.ebuild b/dev-lua/lpc/lpc-9999.ebuild
index a878974..a572f23 100644
--- a/dev-lua/lpc/lpc-9999.ebuild
+++ b/dev-lua/lpc/lpc-9999.ebuild
@@ -4,7 +4,9 @@
 
 EAPI="5"
 
-inherit base multilib toolchain-funcs git-r3
+IS_MULTILIB=true
+VCS="git-r3"
+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";
@@ -13,19 +15,13 @@ EGIT_REPO_URI="https://github.com/LuaDist/lpc";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="${RDEPEND}"
-
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake CFLAGS="-I$($(tc-getPKG_CONFIG) --variable includedir ${lua}) 
-fPIC" CC="$(tc-getCC)"
+each_lua_compile() {
+       _lua_setCFLAGS
+       emake CC="${CC}" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"
 }
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       emake INSTALL_PREFIX="${D}$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" install
+each_lua_install() {
+       dolua ${PN}.so
 }

diff --git a/dev-lua/lpeg/lpeg-0.12.ebuild b/dev-lua/lpeg/lpeg-0.12.ebuild
index e0141e9..7d3d240 100644
--- a/dev-lua/lpeg/lpeg-0.12.ebuild
+++ b/dev-lua/lpeg/lpeg-0.12.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit flag-o-matic toolchain-funcs eutils multilib
+IS_MULTILIB=true
+inherit lua
 
 DESCRIPTION="Parsing Expression Grammars for Lua"
 HOMEPAGE="http://www.inf.puc-rio.br/~roberto/lpeg/";
@@ -13,44 +14,25 @@ 
SRC_URI="http://www.inf.puc-rio.br/~roberto/${PN}/${P}.tar.gz";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS="amd64 ~arm ~hppa ~mips x86"
-IUSE="debug doc luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}
-       virtual/pkgconfig"
-
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       epatch "${FILESDIR}"/${P}-makefile.patch
-       sed -r \
-               -e "2s#^(LUADIR).*#\1 = $($(tc-getPKG_CONFIG) --variable 
includedir ${lua})#" \
-               -i makefile
+IUSE="debug doc"
+
+PATCHES=( "${FILESDIR}"/${P}-makefile.patch )
+DOCS=( HISTORY )
+HTML_DOCS=( {lpeg,re}.html )
+
+all_lua_prepare() {
        use debug && append-cflags -DLPEG_DEBUG
 }
 
-src_compile() {
-       emake CC="$(tc-getCC)"
+each_lua_compile() {
+       _lua_setCFLAGS
+       emake CC="$(tc-getCC)" DLLFLAGS="${CFLAGS} ${LDFLAGS}" lpeg.so
 }
 
-src_test() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       ${lua} test.lua || die
+each_lua_test() {
+       ${LUA} test.lua
 }
 
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       exeinto "$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${lua})"
-       doexe lpeg.so
-
-       dodoc HISTORY
-
-       use doc && dohtml *.html
+each_lua_install() {
+       dolua lpeg.so
 }

diff --git a/dev-lua/lsysstats/lsysstats-9999.ebuild 
b/dev-lua/lsysstats/lsysstats-9999.ebuild
index f8d0006..3450870 100644
--- a/dev-lua/lsysstats/lsysstats-9999.ebuild
+++ b/dev-lua/lsysstats/lsysstats-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs flag-o-matic mercurial eutils
+VCS="mercurial"
+inherit lua
 
 DESCRIPTION="System statistics library for Lua"
 HOMEPAGE="http://code.matthewwild.co.uk/";
@@ -13,18 +14,19 @@ EHG_REPO_URI="http://code.matthewwild.co.uk/${PN}/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
-
-RDEPEND="
-       virtual/lua[luajit=]
-       dev-lua/squish
-       dev-lua/luasocket
-"
-DEPEND="${RDEPEND}"
-
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       insinto $($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})/${PN}/;
-       doins *.lua || die
+IUSE="+examples"
+
+EXAMPLES=( demo.lua )
+
+all_lua_prepare() {
+       sed -r \
+               -e "s#(require.*)(proc.*)#\1${PN}.\2#" \
+               -i init.lua
+
+       mkdir -p ${PN}
+       mv {init,proc}.lua ${PN}
+}
+
+each_lua_install() {
+       dolua ${PN}
 }

diff --git a/dev-lua/lua-cjson/lua-cjson-9999.ebuild 
b/dev-lua/lua-cjson/lua-cjson-9999.ebuild
index a9b599a..0c0d662 100644
--- a/dev-lua/lua-cjson/lua-cjson-9999.ebuild
+++ b/dev-lua/lua-cjson/lua-cjson-9999.ebuild
@@ -4,35 +4,36 @@
 
 EAPI="5"
 
-inherit cmake-utils git-r3
+VCS="git-r3"
+IS_MULTILIB=true
+LUA_COMPAT="lua51 luajit2"
+inherit cmake-utils lua
 
 DESCRIPTION="Lua JSON Library, written in C"
 HOMEPAGE="http://www.kyne.com.au/~mark/software/lua-cjson.php";
 SRC_URI=""
 
-EGIT_REPO_URI="https://github.com/msva/lua-cjson";
+EGIT_REPO_URI="https://github.com/openresty/lua-cjson";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="examples luajit"
+IUSE="+examples"
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}"
+EXAMPLES=( tests/* lua/{json2lua,lua2json}.lua )
 
-src_configure() {
+each_lua_configure() {
        mycmakeargs=(
-               $(cmake-utils_use_use luajit)
+               -DUSE_INTERNAL_FPCONV=ON
        )
        cmake-utils_src_configure
 }
 
-src_install() {
-       if use examples; then
-               insinto /usr/share/doc/"${P}"
-               doins -r tests
-       fi
-       cmake-utils_src_install
+each_lua_compile() {
+       emake
+}
+
+each_lua_install() {
+       dolua lua/cjson cjson.so
+#      cmake-utils_src_install
 }

diff --git a/dev-lua/lua-csv/lua-csv-9999.ebuild 
b/dev-lua/lua-csv/lua-csv-9999.ebuild
index 8141bf2..771a569 100644
--- a/dev-lua/lua-csv/lua-csv-9999.ebuild
+++ b/dev-lua/lua-csv/lua-csv-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="a Lua module for reading delimited text files"
 HOMEPAGE="https://github.com/geoffleyland/lua-csv";
@@ -15,23 +16,10 @@ EGIT_REPO_URI="https://github.com/geoffleyland/lua-csv";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit +lpeg_replace"
+IUSE=""
 
-RDEPEND="
-       virtual/lua[luajit=]
-"
-DEPEND="${RDEPEND}"
+READMES=( README.md )
 
-src_prepare() {
-       epatch_user
-}
-
-src_install() {
-       local lua=lua
-       use luajit && lua=luajit
-
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r lua/csv.lua
-
-       dodoc README.md || die "dodoc failed"
+each_lua_install() {
+       dolua lua/csv.lua
 }

diff --git a/dev-lua/lua-curl/lua-curl-9999.ebuild 
b/dev-lua/lua-curl/lua-curl-9999.ebuild
index 8a8702e..28c65b5 100644
--- a/dev-lua/lua-curl/lua-curl-9999.ebuild
+++ b/dev-lua/lua-curl/lua-curl-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="Lua cURL Library"
 HOMEPAGE="https://github.com/Lua-cURL/Lua-cURLv3";
@@ -15,37 +16,32 @@ EGIT_REPO_URI="https://github.com/Lua-cURL/Lua-cURLv3";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc examples luajit"
+IUSE="doc +examples"
 
 RDEPEND="
-       virtual/lua[luajit=]
        net-misc/curl
 "
-DEPEND="${RDEPEND}
-       virtual/pkgconfig
+DEPEND="
+       doc? ( dev-lua/luadoc )
+       ${RDEPEND}
 "
 
-src_prepare() {
-       epatch_user
-}
+EXAMPLES=( examples/* )
+HTML_DOCS=( html/ )
+READMES=( README.md )
 
-src_configure() {
-       local lua="lua";
-       use luajit && lua="luajit";
-       echo "LUA_IMPL=${lua}" > ${S}/.config;
+each_lua_compile() {
+       _lua_setCFLAGS
+       emake LUA_IMPL="${lua_impl}"
 }
-
-
-src_install() {
-       use examples && {
-               docompress -x /usr/share/doc/${PF}/examples
-               dodoc -r examples
-       }
+all_lua_compile() {
        use doc && (
-               docompress -x /usr/share/doc/${PF}/html
                cd doc
-               ldoc .
-               dohtml -r html
+               ldoc . -d ../html
        )
-       default
+}
+
+
+each_lua_install() {
+       emake LUA_IMPL="${lua_impl}" DESTDIR="${D}" install
 }

diff --git a/dev-lua/lua2html/lua2html-9999.ebuild 
b/dev-lua/lua2html/lua2html-9999.ebuild
index bbc9aa9..e04e0c0 100644
--- a/dev-lua/lua2html/lua2html-9999.ebuild
+++ b/dev-lua/lua2html/lua2html-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs flag-o-matic mercurial eutils
+VCS="mercurial"
+inherit lua
 
 DESCRIPTION="Lua to HTML code converter written in Lua."
 HOMEPAGE="http://code.matthewwild.co.uk/";
@@ -13,27 +14,19 @@ EHG_REPO_URI="http://code.matthewwild.co.uk/${PN}/";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit"
+IUSE=""
 
 RDEPEND="
-       virtual/lua[luajit=]
        dev-lua/squish
 "
 DEPEND="${RDEPEND}"
 
-src_prepare() {
-       local lua=lua
-       use luajit && lua=luajit;
-       sed -r \
-               -e "1s|^(!#.*) lua|\1 ${lua}|" \
-               -i lua2html.lua
-}
+DOCS=( README )
 
-src_compile() {
+all_lua_compile() {
        squish
 }
 
-src_install() {
+all_lua_install() {
        dobin lua2html
-       dodoc README
 }

diff --git a/dev-lua/luacrypto/luacrypto-9999.ebuild 
b/dev-lua/luacrypto/luacrypto-9999.ebuild
index 47581b2..345d841 100644
--- a/dev-lua/luacrypto/luacrypto-9999.ebuild
+++ b/dev-lua/luacrypto/luacrypto-9999.ebuild
@@ -6,45 +6,54 @@ EAPI="5"
 
 LANGS=" en ru"
 
-inherit eutils git-r3
+VCS=git-r3
+IS_MULTILIB=true
+LUA_COMPAT="lua51 luajit2"
+
+inherit lua
 
 DESCRIPTION="Lua Crypto Library"
 HOMEPAGE="https://github.com/msva/lua-crypto";
 SRC_URI=""
 
-EGIT_REPO_URI="git://github.com/msva/lua-crypto.git"
+EGIT_REPO_URI="https://github.com/msva/lua-crypto.git";
 
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="doc luajit"
+IUSE="doc +openssl gcrypt"
 IUSE+="${LANGS// / linguas_}"
 
 RDEPEND="
-       virtual/lua[luajit=]
-       >=dev-libs/openssl-0.9.7
-"
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
+       openssl? ( >=dev-libs/openssl-0.9.7 )
+       gcrypt? ( dev-libs/libgcrypt )
 "
 
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
-       sed \
-               -e 's|LUA_IMPL := "lua"|LUA_IMPL := "'${lua}'"|' \
-               -i Makefile
-}
+REQUIRED_USE="^^ ( openssl gcrypt )"
 
-src_install() {
-       if use doc; then
-               dodoc README || die "dodoc (REAMDE) failed"
+READMES=( README )
+HTML_DOCS=()
+
+all_lua_prepare() {
                for x in ${LANGS}; do
                        if use linguas_${x}; then
-                               dohtml -r doc/${x} || die "dohtml failed"
+                               HTML_DOCS+=( doc/${x} )
                        fi
                done
+}
+
+each_lua_compile() {
+       _lua_setCFLAGS
+
+       local engine="openssl";
+       if use gcrypt; then
+               engine="gcrypt"
+               tc-getPROG GCRYPT_CONFIG libgcrypt-config
        fi
-       default
+
+       emake LUA_IMPL="${lua_impl}" CC="${CC}" CRYPTO_ENGINE="${engine}" 
CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" PKG_CONFIG="${PKG_CONFIG}" 
GCRYPT_CONFIG="${GCRYPT_CONFIG}"
+}
+
+each_lua_install() {
+       dolua src/crypto.so
 }

diff --git a/dev-lua/luadbi/luadbi-9999.ebuild 
b/dev-lua/luadbi/luadbi-9999.ebuild
index ec987bb..8f3f922 100644
--- a/dev-lua/luadbi/luadbi-9999.ebuild
+++ b/dev-lua/luadbi/luadbi-9999.ebuild
@@ -4,7 +4,10 @@
 
 EAPI="5"
 
-inherit multilib toolchain-funcs flag-o-matic eutils mercurial
+LUA_COMPAT="lua51 lua52 luajit2"
+IS_MULTILIB=true
+VCS="mercurial"
+inherit lua
 
 DESCRIPTION="DBI module for Lua"
 HOMEPAGE="https://code.google.com/p/luadbi";
@@ -14,29 +17,28 @@ EHG_REPO_URI="https://bitbucket.org/mva/luadbi-temp";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="mysql postgres sqlite luajit"
+IUSE="mysql postgres sqlite oracle"
 
 RDEPEND="
-       virtual/lua[luajit=]
        mysql? ( || ( dev-db/mysql dev-db/mariadb ) )
        postgres? ( dev-db/postgresql )
        sqlite? ( >=dev-db/sqlite-3 )
+       oracle? ( dev-db/oracle-instantclient-basic )
 "
-DEPEND="${RDEPEND}
-       virtual/pkgconfig"
+DEPEND="${RDEPEND}"
 
-S="${WORKDIR}"
+#S="${WORKDIR}"
 
-src_compile() {
-       local lua=lua;
-       use luajit && lua=luajit;
+each_lua_compile() {
+       _lua_setCFLAGS
 
-       local drivers=""
-       use mysql && drivers="${drivers} mysql"
-       use postgres && drivers="${drivers} psql"
-       use sqlite && drivers="${drivers} sqlite3"
+       local drivers=()
+       use mysql && drivers+=( "mysql" )
+       use postgres && drivers+=( "psql" )
+       use sqlite && drivers+=( "sqlite3" )
+       use oracle && drivers+=( "oracle" )
 
-       if [ -z "${drivers// /}" ] ; then
+       if [[ -z "${drivers[@]}" ]] ; then
                eerror
                eerror "No driver was selected, cannot build."
                eerror "Please set USE flags to build any driver."
@@ -45,38 +47,27 @@ src_compile() {
                die "No driver selected"
        fi
 
-       for driver in "${drivers}" ; do
-               emake \
-                       CC="$(tc-getCC) -fPIC -DPIC" \
-                       LDFLAGS="${LDFLAGS}" \
-                       CFLAGS="${CFLAGS}"  \
-                       LUA_LMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})" \
-                       LUA_CMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" \
-                       LUA_INC="-I$($(tc-getPKG_CONFIG) --variable includedir 
${lua})" \
-                       PSQL_INC="-I/usr/include/postgresql/server" \
-                       MYSQL_INC="-I/usr/include/mysql 
-L/usr/$(get_libdir)/mysql" \
-                       ${driver} \
-                       || die "Compiling driver '${drivers// /}' failed"
-       done
-}
+       for driver in "${drivers[@]}"; do
+               local buildme;
+               if [[ ${driver} = "psql" && ${ABI} = "x86" ]]; then
+                       # FIXME: when postgres and perl (as postgres dep) will 
have multilib support
+                       buildme=no
+               fi
 
-src_install() {
-       local drivers=""
-       use mysql && drivers="${drivers} mysql"
-       use postgres && drivers="${drivers} psql"
-       use sqlite && drivers="${drivers} sqlite3"
+#                      LUA_INC="$($(tc-getPKG_CONFIG) --cflags ${lua_impl})" \
 
-       for driver in ${drivers} ; do
-               emake \
-                       CC="$(tc-getCC) -fPIC -DPIC" \
+               [[ ${buildme} = "no" ]] || emake \
+                       CC="${CC}" \
                        LDFLAGS="${LDFLAGS}" \
                        CFLAGS="${CFLAGS}"  \
-                       LUA_LMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua})" \
-                       LUA_CMOD="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua})" \
-                       LUA_INC="-I$($(tc-getPKG_CONFIG) --variable includedir 
${lua})" \
                        PSQL_INC="-I/usr/include/postgresql/server" \
                        MYSQL_INC="-I/usr/include/mysql 
-L/usr/$(get_libdir)/mysql" \
-                       DESTDIR="${D}" "install_${driver// /}" \
-                       || die "Install of driver '${drivers// /}' failed"
+                       ${driver}
+
+               unset buildme
        done
 }
+
+each_lua_install() {
+       dolua *.so DBI.lua
+}

diff --git a/dev-lua/lunit/lunit-9999.ebuild b/dev-lua/lunit/lunit-9999.ebuild
index 9a7f2fe..31d755f 100644
--- a/dev-lua/lunit/lunit-9999.ebuild
+++ b/dev-lua/lunit/lunit-9999.ebuild
@@ -15,7 +15,7 @@ EGIT_REPO_URI="https://github.com/dcurrie/${PN}";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit +samples"
+IUSE="luajit +examples"
 
 RDEPEND="
        virtual/lua[luajit=]

diff --git a/dev-lua/moonscript/moonscript-9999.ebuild 
b/dev-lua/moonscript/moonscript-9999.ebuild
index 6989367..baca13f 100644
--- a/dev-lua/moonscript/moonscript-9999.ebuild
+++ b/dev-lua/moonscript/moonscript-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit base toolchain-funcs git-r3
+VCS="git-r3"
+inherit lua
 
 DESCRIPTION="A programmer friendly language that compiles into Lua."
 HOMEPAGE="https://github.com/leafo/moonscript";
@@ -15,48 +16,40 @@ EGIT_REPO_URI="https://github.com/leafo/moonscript";
 LICENSE="MIT"
 SLOT="0"
 KEYWORDS=""
-IUSE="luajit +inotify"
+IUSE="+doc +inotify"
 
 RDEPEND="
-       virtual/lua[luajit=]
-       dev-lua/lpeg
+       || (
+               dev-lua/lpeg
+               dev-lua/lulpeg[lpeg-compat]
+       )
        dev-lua/luafilesystem
        dev-lua/alt-getopt
        inotify? ( dev-lua/linotify )
 "
-DEPEND="
-       ${RDEPEND}
-       virtual/pkgconfig
-"
-
-HTML_DOCS=( "docs/" "README.md" )
-
-src_prepare() {
-       local lua=lua;
-       use luajit && lua=luajit;
+DEPEND="${RDEPEND}"
 
-       sed -r \
-                       -e "s/lua5.1/${lua}/" \
-                       -i Makefile
+DOCS=( docs/ README.md )
 
-       sed -r \
-                       -e "1s#(/usr/bin/env) lua#\1 ${lua}#" \
-                       -i bin/moon bin/moonc
+each_lua_compile() {
+       local lua="$(lua_get_implementation)"
+       ${lua} bin/moonc moon/ moonscript/
 }
 
-src_compile() {
-       emake compile
-}
+all_lua_compile() {
+       local lua="$(lua_get_implementation)"
 
-src_install() {
-       local lua=lua;
-       use luajit && lua=luajit;
+       echo "#!/usr/bin/env lua" > bin/moon
+       ${lua} bin/moonc -p bin/moon.moon >> bin/moon
+       echo "-- vim: set filetype=lua:" >> bin/moon
 
-       insinto "$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${lua})"
-       doins -r moon.lua moonscript.lua moon moonscript
+       ${lua} bin/moonc -p bin/splat.moon >> bin/splat
+}
 
-       dobin bin/moon bin/moonc
-       newbin bin/splat.moon splat
+each_lua_install() {
+       dolua moon{,script}{,.lua}
+}
 
-       base_src_install_docs
+all_lua_install() {
+       dobin bin/{moon,moonc,splat}
 }

diff --git a/dev-lua/squish/squish-9999.ebuild 
b/dev-lua/squish/squish-9999.ebuild
index c31313e..a806b34 100644
--- a/dev-lua/squish/squish-9999.ebuild
+++ b/dev-lua/squish/squish-9999.ebuild
@@ -4,7 +4,8 @@
 
 EAPI="5"
 
-inherit mercurial eutils
+VCS="mercurial"
+inherit eutils lua
 
 DESCRIPTION="XMPP client library written in Lua."
 HOMEPAGE="http://code.matthewwild.co.uk/";
@@ -15,17 +16,19 @@ SLOT="0"
 KEYWORDS=""
 IUSE="luajit"
 
-RDEPEND="virtual/lua[luajit=]"
-DEPEND="${RDEPEND}"
+READMES=( README )
 
-src_prepare() {
+all_lua_prepare() {
        use luajit && sed -r \
                -e '1s:(env lua):\1jit:' \
                -i squish.lua make_squishy
 }
 
-src_install() {
-       dobin squish || die;
-       dobin make_squishy || die;
-       dodoc README CHANGES || die
+all_lua_compile() {
+       emake
+}
+
+all_lua_install() {
+       dobin squish
+       dobin make_squishy
 }

diff --git a/eclass/lua.eclass b/eclass/lua.eclass
new file mode 100644
index 0000000..cf5651f
--- /dev/null
+++ b/eclass/lua.eclass
@@ -0,0 +1,749 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+# @ECLASS: lua.eclass
+# @MAINTAINER:
+# mva <[email protected]>
+# @AUTHOR:
+# Author: Vadim A. Misbakh-Soloviov <[email protected]>
+# @BLURB: An eclass for installing Lua packages with proper support for 
multiple Lua slots.
+# @DESCRIPTION:
+# The Lua eclass is designed to allow an easier installation of Lua packages
+# and their incorporation into the Gentoo Linux system.
+#
+# Currently available targets are:
+#  * lua51 - Lua (PUC-Rio) 5.1
+#  * lua52 - Lua (PUC-Rio) 5.2
+#  * lua53 - Lua (PUC-Rio) 5.3
+#  * luajit2 - LuaJIT 2.x
+#
+# This eclass does not define the implementation of the configure,
+# compile, test, or install phases. Instead, the default phases are
+# used.  Specific implementations of these phases can be provided in
+# the ebuild either to be run for each Lua implementation, or for all
+# Lua implementations, as follows:
+#
+#  * each_lua_configure
+#  * all_lua_configure
+
+# @ECLASS-VARIABLE: LUA_COMPAT
+# @REQUIRED
+# @DESCRIPTION:
+# This variable contains a space separated list of targets (see above) a 
package
+# is compatible to. It must be set before the `inherit' call.
+: ${LUA_COMPAT:=lua51 lua52 lua53 luajit2}
+
+# @ECLASS-VARIABLE: LUA_PATCHES
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# A String or Array of filenames of patches to apply to all implementations.
+
+# @ECLASS-VARIABLE: LUA_OPTIONAL
+# @DESCRIPTION:
+# Set the value to "yes" to make the dependency on a Lua interpreter
+# optional and then lua_implementations_depend() to help populate
+# DEPEND and RDEPEND.
+
+# @ECLASS-VARIABLE: LUA_S
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If defined this variable determines the source directory name after
+# unpacking. This defaults to the name of the package. Note that this
+# variable supports a wildcard mechanism to help with github tarballs
+# that contain the commit hash as part of the directory name.
+
+# @ECLASS-VARIABLE: LUA_QA_ALLOWED_LIBS
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If defined this variable contains a whitelist of shared objects that
+# are allowed to exist even if they don't link to liblua. This avoids
+# the QA check that makes this mandatory. This is most likely not what
+# you are looking for if you get the related "Missing links" QA warning,
+# since the proper fix is almost always to make sure the shared object
+# is linked against liblua. There are cases were this is not the case
+# and the shared object is generic code to be used in some other way
+# (e.g. selenium's firefox driver extension). When set this argument is
+# passed to "grep -E" to remove reporting of these shared objects.
+
+[[ -n "${IS_MULTILIB}" ]] && multilib="multilib-minimal"
+
+inherit base eutils ${multilib} toolchain-funcs ${VCS}
+
+EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install 
pkg_setup
+
+case ${EAPI} in
+       0|1)
+               die "Unsupported EAPI=${EAPI} (too old) for lua.eclass" ;;
+       2|3) ;;
+       4|5)
+               # S is no longer automatically assigned when it doesn't exist.
+               S="${WORKDIR}"
+               ;;
+       *)
+               die "Unknown EAPI=${EAPI} for lua.eclass"
+esac
+
+lua_implementation_depend() {
+       local lua_pn=
+       local lua_slot=
+
+       case $1 in
+               lua51)
+                       lua_pn="dev-lang/lua"
+                       lua_slot=":5.1"
+                       ;;
+               lua52)
+                       lua_pn="dev-lang/lua"
+                       lua_slot=":5.2"
+                       ;;
+               lua53)
+                       lua_pn="dev-lang/lua"
+                       lua_slot=":5.3"
+                       ;;
+               luajit2)
+                       lua_pn="dev-lang/luajit"
+                       lua_slot=":2"
+                       ;;
+               *) die "$1: unknown Lua implementation"
+       esac
+
+       echo "$2${lua_pn}$3${lua_slot}"
+}
+
+# @FUNCTION: lua_implementation_command
+# @RETURN: the path to the given lua implementation
+# @DESCRIPTION:
+lua_implementation_command() {
+       local _lua_name=
+       local _lua_slotted=$(lua_implementation_depend $1)
+       _lua_name=${_lua_slotted//:}
+
+       case $1 in
+               luajit*)
+                       _lua_name=${_lua_slotted/:/-}
+                       ;;
+       esac
+
+       local lua=$(readlink -fs $(type -p $(basename ${_lua_name} 
2>/dev/null)) 2>/dev/null)
+       [[ -x ${lua} ]] || die "Unable to locate executable Lua interpreter"
+       echo "${lua}"
+}
+
+# @FUNCTION: lua_samelib
+# @RETURN: use flag string with current lua implementations
+# @DESCRIPTION:
+# Convenience function to output the use dependency part of a
+# dependency. Used as a building block for lua_add_rdepend() and
+# lua_add_bdepend(), but may also be useful in an ebuild to specify
+# more complex dependencies.
+lua_samelib() {
+       local res=
+       for _lua_implementation in $LUA_COMPAT; do
+               has -${_lua_implementation} $@ || \
+                       res="${res}lua_targets_${_lua_implementation}?,"
+       done
+
+       echo "[${res%,}]"
+}
+
+_lua_atoms_samelib_generic() {
+       eshopts_push -o noglob
+       echo "LUATARGET? ("
+       for token in $*; do
+               case "$token" in
+                       "||" | "(" | ")" | *"?")
+                               echo "${token}"
+                               ;;
+                       *])
+                               echo "${token%[*}[LUATARGET,${token/*[}"
+                               #" <= kludge for vim's syntax highlighting 
engine to don't mess up all
+                               ;;
+                       *)
+                               echo "${token}[LUATARGET]"
+                               ;;
+               esac
+       done
+       echo ")"
+       eshopts_pop
+}
+
+_lua_atoms_samelib() {
+       local atoms=$(_lua_atoms_samelib_generic "$*")
+
+       for _lua_implementation in $LUA_COMPAT; do
+               echo "${atoms//LUATARGET/lua_targets_${_lua_implementation}}"
+       done
+}
+
+_lua_wrap_conditions() {
+       local conditions="$1"
+       local atoms="$2"
+
+       for condition in $conditions; do
+               atoms="${condition}? ( ${atoms} )"
+       done
+
+       echo "$atoms"
+}
+
+# @FUNCTION: lua_add_rdepend
+# @USAGE: dependencies
+# @DESCRIPTION:
+# Adds the specified dependencies, with use condition(s) to RDEPEND,
+# taking the current set of lua targets into account. This makes sure
+# that all lua dependencies of the package are installed for the same
+# lua targets. Use this function for all lua dependencies instead of
+# setting RDEPEND yourself. The list of atoms uses the same syntax as
+# normal dependencies.
+#
+# Note: runtime dependencies are also added as build-time test
+# dependencies.
+lua_add_rdepend() {
+       case $# in
+               1) ;;
+               2)
+                       [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now 
use the usual syntax in lua_add_rdepend for $CATEGORY/$PF"
+                       lua_add_rdepend "$(_lua_wrap_conditions "$1" "$2")"
+                       return
+                       ;;
+               *)
+                       die "bad number of arguments to $0"
+                       ;;
+       esac
+
+       local dependency=$(_lua_atoms_samelib "$1")
+
+       RDEPEND="${RDEPEND} $dependency"
+
+       # Add the dependency as a test-dependency since we're going to
+       # execute the code during test phase.
+       DEPEND="${DEPEND} test? ( ${dependency} )"
+       has test "$IUSE" || IUSE="${IUSE} test"
+}
+
+# @FUNCTION: lua_add_bdepend
+# @USAGE: dependencies
+# @DESCRIPTION:
+# Adds the specified dependencies, with use condition(s) to DEPEND,
+# taking the current set of lua targets into account. This makes sure
+# that all lua dependencies of the package are installed for the same
+# lua targets. Use this function for all lua dependencies instead of
+# setting DEPEND yourself. The list of atoms uses the same syntax as
+# normal dependencies.
+lua_add_bdepend() {
+       case $# in
+               1) ;;
+               2)
+                       [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now 
use the usual syntax in lua_add_bdepend for $CATEGORY/$PF"
+                       lua_add_bdepend "$(_lua_wrap_conditions "$1" "$2")"
+                       return
+                       ;;
+               *)
+                       die "bad number of arguments to $0"
+                       ;;
+       esac
+
+       local dependency=$(_lua_atoms_samelib "$1")
+
+       DEPEND="${DEPEND} $dependency"
+       RDEPEND="${RDEPEND}"
+}
+
+# @FUNCTION: lua_get_use_implementations
+# @DESCRIPTION:
+# Gets an array of lua use targets enabled by the user
+lua_get_use_implementations() {
+       local i implementation
+       for implementation in ${LUA_COMPAT}; do
+               use lua_targets_${implementation} && i+=" ${implementation}"
+       done
+       echo $i
+}
+
+# @FUNCTION: lua_get_use_targets
+# @DESCRIPTION:
+# Gets an array of lua use targets that the ebuild sets
+lua_get_use_targets() {
+       local t implementation
+       for implementation in ${LUA_COMPAT}; do
+               t+=" lua_targets_${implementation}"
+       done
+       echo $t
+}
+
+# @FUNCTION: lua_implementations_depend
+# @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND.
+# @DESCRIPTION:
+# Produces the dependency string for the various implementations of lua
+# which the package is being built against. This should not be used when
+# LUA_OPTIONAL is unset but must be used if LUA_OPTIONAL=yes. Do not
+# confuse this function with lua_implementation_depend().
+#
+# @EXAMPLE:
+# EAPI=5
+# LUA_OPTIONAL=yes
+#
+# inherit lua
+# ...
+# DEPEND="lua? ( $(lua_implementations_depend) )"
+# RDEPEND="${DEPEND}"
+lua_implementations_depend() {
+       local depend
+       for _lua_implementation in ${LUA_COMPAT}; do
+               depend="${depend}${depend+ }lua_targets_${_lua_implementation}? 
( $(lua_implementation_depend $_lua_implementation) )"
+       done
+       echo "${depend}"
+}
+
+IUSE+="$(lua_get_use_targets)"
+# If you specify LUA_OPTIONAL you also need to take care of
+# lua useflag and dependency.
+if [[ ${LUA_OPTIONAL} != yes ]]; then
+       DEPEND="${DEPEND} $(lua_implementations_depend)"
+       RDEPEND="${RDEPEND} $(lua_implementations_depend)"
+
+       case ${EAPI:-0} in
+               4|5)
+                       REQUIRED_USE+=" || ( $(lua_get_use_targets) )"
+                       ;;
+       esac
+fi
+
+_lua_invoke_environment() {
+       old_S=${S}
+       case ${EAPI} in
+               4|5)
+                       if [ -z "${LUA_S}" ]; then
+                               sub_S=${P}
+                       else
+                               sub_S=${LUA_S}
+                       fi
+                       ;;
+               *)
+                       sub_S=${S#${WORKDIR}/}
+                       ;;
+       esac
+
+       # Special case, for the always-lovely GitHub fetches. With this,
+       # we allow the star glob to just expand to whatever directory it's
+       # called.
+       if [[ "${sub_S}" = *"*"* ]]; then
+               case ${EAPI} in
+                       2|3)
+                               #The old method of setting S depends on 
undefined package
+                               # manager behaviour, so encourage upgrading to 
EAPI=4.
+                               eqawarn "Using * expansion of S is deprecated. 
Use EAPI and LUA_S instead."
+                               ;;
+               esac
+               pushd "${WORKDIR}"/all &>/dev/null
+               sub_S=$(eval ls -d "${sub_S}" 2>/dev/null)
+               popd &>/dev/null
+       fi
+
+       environment=$1; shift
+
+       my_WORKDIR="${WORKDIR}"/${environment}
+       S="${my_WORKDIR}"/"${sub_S}"
+
+       if [[ -d "${S}" ]]; then
+               pushd "$S" &>/dev/null
+       elif [[ -d "${my_WORKDIR}" ]]; then
+               pushd "${my_WORKDIR}" &>/dev/null
+       else
+               pushd "${WORKDIR}" &>/dev/null
+       fi
+
+       ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
+       "$@"
+       popd &>/dev/null
+
+       S=${old_S}
+}
+
+_lua_each_implementation() {
+       local invoked=no
+       for _lua_implementation in ${LUA_COMPAT}; do
+               # only proceed if it's requested
+               use lua_targets_${_lua_implementation} || continue
+
+               LUA=$(lua_implementation_command ${_lua_implementation})
+               lua_impl=$(basename ${LUA})
+               invoked=yes
+
+               if [[ -n "$1" ]]; then
+                       _lua_invoke_environment ${_lua_implementation} "$@"
+               fi
+
+               unset LUA lua_impl
+       done
+
+       if [[ ${invoked} == "no" ]]; then
+               eerror "You need to select at least one compatible Lua 
installation target via LUA_TARGETS in make.conf."
+               eerror "Compatible targets for this package are: ${LUA_COMPAT}"
+               eerror
+               die "No compatible Lua target selected."
+       fi
+}
+
+# @FUNCTION: lua_pkg_setup
+# @DESCRIPTION:
+# Check whether at least one lua target implementation is present.
+lua_pkg_setup() {
+       # This only checks that at least one implementation is present
+       # before doing anything; by leaving the parameters empty we know
+       # it's a special case.
+       _lua_each_implementation
+}
+
+# @FUNCTION: lua_src_unpack
+# @DESCRIPTION:
+# Unpack the source archive.
+lua_src_unpack() {
+       mkdir "${WORKDIR}"/all
+       pushd "${WORKDIR}"/all &>/dev/null
+
+       # We don't support an each-unpack, it's either all or nothing!
+       if type all_lua_unpack &>/dev/null; then
+               _lua_invoke_environment all all_lua_unpack
+       elif [[ -n ${A} ]]; then
+               unpack ${A}
+       elif [[ -n ${VCS} ]] && declare -f ${VCS}_src_unpack >/dev/null; then
+                       _lua_invoke_environment all ${VCS}_src_unpack
+       fi
+
+       # hack for VCS-eclasses (git-r3 and darcs, for now) which defaults 
unpack dir to WD/P instead of S
+       if [[ '*9999*' =~ ${PV} ]] && [[ -d ${WORKDIR}/${P} ]] && [[ ! -d 
${WORKDIR}/all/${P} ]] ; then
+               mv ${WORKDIR}/${P} ${WORKDIR}/all/${P}
+       fi
+
+       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.
+       cp -prlP all ${_lua_implementation} \
+               || die "Unable to copy ${_lua_implementation} environment"
+}
+
+_lua_setCFLAGS() {
+       local lua=$(readlink -fs $(type -p $(basename ${LUA:-lua} 2>/dev/null)) 
2>/dev/null)
+       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
+}
+
+# @FUNCTION: lua_src_prepare
+# @DESCRIPTION:
+# Apply patches and prepare versions for each lua target
+# 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
+       fi
+       _lua_invoke_environment all epatch_user
+       _lua_invoke_environment all _lua_apply_patches
+
+       if [[ -n ${IS_MULTILIB} ]]; then
+               _lua_invoke_environment all multilib_copy_sources
+       fi
+
+       _PHASE="source copy" \
+               _lua_each_implementation _lua_source_copy
+
+       if type each_lua_prepare &>/dev/null; then
+               _lua_each_implementation each_lua_prepare
+       fi
+}
+
+# @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
+       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
+       fi
+}
+
+# @FUNCTION: lua_src_compile
+# @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
+       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
+       fi
+}
+
+# @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
+       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
+       fi
+}
+
+# @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
+       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
+       fi
+
+#### TODO: move this things to more general eclass, like docs or so ####
+       local README_DOCS OTHER_DOCS MY_S;
+
+       README_DOCS=(${DOCS[@]});
+       OTHER_DOCS=(${DOCS[@]//README*});
+       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
+       done;
+
+       README_DOCS+=(${READMES[@]})
+
+       if [[ -n "${README_DOCS}" ]]; then
+               export DOCS=(${README_DOCS[@]});
+               _PHASE="install readmes" _lua_invoke_environment all 
base_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
+               unset DOCS
+       fi
+
+       if [[ -n "${EXAMPLES[@]}" ]] && use examples; then
+               _PHASE="install samples" _lua_invoke_environment all 
_lua_src_install_examples
+       fi
+#### END  ####
+}
+
+#### TODO: move this things to more general eclass, like docs or so ####
+_lua_src_install_examples() {
+       debug-print-function $FUNCNAME "$@"
+
+       local x
+
+       pushd "${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"
+               done
+       fi
+
+       popd >/dev/null
+}
+#### END ####
+
+# @FUNCTION: dolua
+# @USAGE: file [file...]
+# @DESCRIPTION:
+# Installs the specified file(s) into the proper INSTALL_?MOD location of the 
Lua interpreter in ${LUA}.
+dolua() {
+       local lmod=()
+       local cmod=()
+       for f in "$@"; do
+               base_f="$(basename ${f})"
+               case ${base_f} in
+                       *.lua|*.moon)
+                               lmod+=(${f})
+                               ;;
+                       *.so)
+                               cmod+=(${f})
+                               ;;
+                       *)
+                               if [[ -d ${f} ]]; then
+                                       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"
+                               fi
+                               ;;
+               esac
+       done
+       test -n "${lmod}" && _dolua_insdir="${_dolua_insdir}" dolua_lmod 
${lmod[@]}
+       test -n "${cmod}" && _dolua_insdir="${_dolua_insdir}" dolua_cmod 
${cmod[@]}
+}
+
+dolua_lmod() {
+       [[ -z ${LUA} ]] && die "\$LUA is not set"
+       has "${EAPI}" 2 && ! use prefix && EPREFIX=
+       local insdir="$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD 
${lua_impl})"
+       [[ -n "${_dolua_insdir}" ]] && insdir="${insdir}/${_dolua_insdir}"
+       (
+               insinto ${insdir#${EPREFIX}}
+               insopts -m 0644
+               doins -r "$@"
+       ) || die "failed to install $@"
+}
+
+dolua_cmod() {
+       [[ -z ${LUA} ]] && die "\$LUA is not set"
+       has "${EAPI}" 2 && ! use prefix && EPREFIX=
+       local insdir="$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD 
${lua_impl})"
+       [[ -n "${_dolua_insdir}" ]] && insdir="${insdir}/${_dolua_insdir}"
+       (
+               insinto ${insdir#${EPREFIX}}
+               insopts -m 0644
+               doins -r "$@"
+       ) || die "failed to install $@"
+}
+
+# @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})"
+       libname="${libname:-lua$(lua_get_abi)}"
+       echo "${libdir}/lib${libname}.so"
+}
+
+# @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})
+       echo "${incdir}"
+}
+
+# @FUNCTION: lua_get_abi
+# @RETURN: The version of the Lua interpreter ABI in ${LUA}, or what 'lua' 
points to.
+lua_get_abi() {
+       local lua=${LUA:-$(type -p lua 2>/dev/null)}
+       [[ -x ${lua} ]] || die "Unable to locate executable Lua interpreter"
+       echo $(${lua} -e 'print(_VERSION:match("[%d.]+"))')
+}
+
+# @FUNCTION: lua_get_implementation
+# @RETURN: The implementation of the Lua interpreter in ${LUA}, or what 'lua' 
points to.
+lua_get_implementation() {
+       local lua=${LUA:-$(type -p lua 2>/dev/null)}
+       [[ -x ${lua} ]] || die "Unable to locate executable Lua interpreter"
+
+       case $(${lua} -v) in
+               LuaJIT*)
+                       echo "luajit"
+                       ;;
+               *)
+                       echo "lua"
+                       ;;
+       esac
+}
+

diff --git a/profiles/make.defaults b/profiles/make.defaults
index d186cb6..a280c3d 100644
--- a/profiles/make.defaults
+++ b/profiles/make.defaults
@@ -1 +1 @@
-USE_EXPAND="PROSODY_MODULES"
+USE_EXPAND="${USE_EXPAND} PROSODY_MODULES LUA_TARGETS"

diff --git a/profiles/updates/2Q-2015 b/profiles/updates/2Q-2015
index 0b5ea7a..3f57e65 100644
--- a/profiles/updates/2Q-2015
+++ b/profiles/updates/2Q-2015
@@ -1,5 +1,3 @@
-slotmove =dev-lang/luajit-2.0.9999 2 2.0
-slotmove =dev-lang/luajit-2.1.9999 2 2.1
 slotmove =dev-lang/lua-5.1* 0 5.1
 slotmove =dev-lang/lua-5.2* 0 5.2
 slotmove =dev-lang/lua-5.3* 0 5.3

diff --git a/profiles/updates/3Q-2015 b/profiles/updates/3Q-2015
new file mode 100644
index 0000000..84799e5
--- /dev/null
+++ b/profiles/updates/3Q-2015
@@ -0,0 +1,3 @@
+slotmove =dev-lang/luajit-2.0.9999 2.0 2
+slotmove =dev-lang/luajit-2.1.9999 2.1 2
+

diff --git a/virtual/lua/lua-5.ebuild b/virtual/lua/lua-5.ebuild
index cecd8b1..a1db06a 100644
--- a/virtual/lua/lua-5.ebuild
+++ b/virtual/lua/lua-5.ebuild
@@ -27,21 +27,16 @@ RDEPEND="
                || (
                        dev-lang/lua:5.2[deprecated,${MULTILIB_USEDEP}]
                        dev-lang/lua:5.3[deprecated,${MULTILIB_USEDEP}]
-                       dev-lang/luajit:2.0[${MULTILIB_USEDEP}]
-                       dev-lang/luajit:2.1[${MULTILIB_USEDEP}]
+                       dev-lang/luajit:2[${MULTILIB_USEDEP}]
                        dev-lua/LuaBitOp[${MULTILIB_USEDEP}]
                )
        )
        luajit? (
-               || (
-                       dev-lang/luajit:2.0[${MULTILIB_USEDEP}]
-                       dev-lang/luajit:2.1[${MULTILIB_USEDEP}]
-               )
+               dev-lang/luajit:2[${MULTILIB_USEDEP}]
                app-eselect/eselect-luajit
        )
        app-eselect/eselect-lua
        !!dev-lang/lua:0
-       !!dev-lang/luajit:2
 "
 DEPEND="${RDEPEND}"
 S="${WORKDIR}"

Reply via email to