Commit 7aed4494 authored by Natanael Copa's avatar Natanael Copa

lua: initial lua module

parent 3ec82a5a
...@@ -13,8 +13,9 @@ LIBDIR := /lib ...@@ -13,8 +13,9 @@ LIBDIR := /lib
CONFDIR := /etc/apk CONFDIR := /etc/apk
MANDIR := /usr/share/man MANDIR := /usr/share/man
DOCDIR := /usr/share/doc/apk DOCDIR := /usr/share/doc/apk
LUA_LIBDIR := /usr/lib/lua/5.1
export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR LUA_LIBDIR
## ##
# Top-level rules and targets # Top-level rules and targets
......
...@@ -8,6 +8,11 @@ shlibs-y += libapk.so ...@@ -8,6 +8,11 @@ shlibs-y += libapk.so
libapk.so-objs := common.o state.o database.o package.o archive.o \ libapk.so-objs := common.o state.o database.o package.o archive.o \
version.o io.o url.o gunzip.o blob.o hash.o print.o version.o io.o url.o gunzip.o blob.o hash.o print.o
shlibs-y += apk.so
apk.so-objs := lua-apk.o
CFLAGS_lua-apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
LIBS_apk.so := -L$(obj) -llua -lapk
progs-y += apk progs-y += apk
apk-objs := apk.o add.o del.o fix.o update.o info.o \ apk-objs := apk.o add.o del.o fix.o update.o info.o \
search.o upgrade.o cache.o ver.o index.o fetch.o \ search.o upgrade.o cache.o ver.o index.o fetch.o \
...@@ -30,8 +35,11 @@ LIBS := -Wl,--as-needed \ ...@@ -30,8 +35,11 @@ LIBS := -Wl,--as-needed \
$(obj)/apk: $(obj)/libapk.so $(obj)/apk: $(obj)/libapk.so
install: $(obj)/apk $(obj)/libapk.so $(obj)/apk.so: $(obj)/libapk.so
$(INSTALLDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR)
install: $(obj)/apk $(obj)/libapk.so $(obj)/apk.so
$(INSTALLDIR) $(addprefix $(DESTDIR),$(SBINDIR) $(LIBDIR) $(LUA_LIBDIR))
$(INSTALL) $(obj)/apk $(DESTDIR)$(SBINDIR) $(INSTALL) $(obj)/apk $(DESTDIR)$(SBINDIR)
$(INSTALL) $(obj)/libapk.so $(DESTDIR)$(LIBDIR) $(INSTALL) $(obj)/libapk.so $(DESTDIR)$(LIBDIR)
$(INSTALL) $(obj)/apk.so $(DESTDIR)$(LUA_LIBDIR)
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "apk_defines.h"
#include "apk_version.h"
#include "apk_blob.h"
#define LIBNAME "apk"
int apk_verbosity;
unsigned int apk_flags;
/* version_validate(verstr) */
/* returns boolean */
static int Pversion_validate(lua_State *L)
{
apk_blob_t ver;
ver.ptr = (char *)luaL_checklstring(L, 1, &ver.len);
lua_pushboolean(L, apk_version_validate(ver));
return 1;
}
/* version_compare(verstr1, verstr2)
returns either '<', '=' or '>'
*/
static int Pversion_compare(lua_State *L)
{
apk_blob_t a, b;
a.ptr = (char *)luaL_checklstring(L, 1, &a.len);
b.ptr = (char *)luaL_checklstring(L, 2, &b.len);
lua_pushstring(L, apk_version_op_string(apk_version_compare_blob(a, b)));
return 1;
}
/* version_is_less(verstr1, verstr2)
returns either '<', '=' or '>'
*/
static int Pversion_is_less(lua_State *L)
{
apk_blob_t a, b;
a.ptr = (char *)luaL_checklstring(L, 1, &a.len);
b.ptr = (char *)luaL_checklstring(L, 2, &b.len);
lua_pushboolean(L, apk_version_compare_blob(a, b) == APK_VERSION_LESS);
return 1;
}
static const luaL_reg R[] = {
{"version_validate", Pversion_validate},
{"version_compare", Pversion_compare},
{"version_is_less", Pversion_is_less},
{NULL, NULL}
};
LUALIB_API int luaopen_apk(lua_State *L)
{
luaL_register(L, LIBNAME, R);
lua_pushliteral(L, "version");
lua_pushliteral(L, APK_VERSION);
lua_settable(L, -3);
return 1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment