diff --git a/lang/luaexpat/Makefile b/lang/luaexpat/Makefile new file mode 100644 index 0000000000..e59731e2ec --- /dev/null +++ b/lang/luaexpat/Makefile @@ -0,0 +1,56 @@ +# +# Copyright (C) 2009 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luaexpat +PKG_VERSION:=1.1 +PKG_RELEASE:=2 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=http://luaforge.net/frs/download.php/2469 +PKG_MD5SUM:=6ecb895ccf5cff1e7f2facd438b1f8d0 + +include $(INCLUDE_DIR)/package.mk + +define Package/luaexpat + SUBMENU:=Lua + SECTION:=lang + CATEGORY:=Languages + TITLE:=LuaExpat + URL:=http://www.keplerproject.org/luaexpat/ + MAINTAINER:=W. Michael Petullo + DEPENDS:=+lua +libexpat +endef + +define Package/luaexpat/description + LuaExpat is a SAX XML parser based on the Expat library. +endef + +define Build/Configure +endef + +define Build/Compile + $(CP) files/compat-5.1r5 $(PKG_BUILD_DIR)/compat-5.1r5 + $(MAKE) -C $(PKG_BUILD_DIR) \ + EXPAT_INC="$(STAGING_DIR)/usr/include/" \ + LUA_INC="$(STAGING_DIR)/usr/include/" \ + LUA_LIBDIR="$(STAGING_DIR)/usr/lib/" \ + COMPAT_DIR="$(PKG_BUILD_DIR)/compat-5.1r5" \ + LIB_OPTION="-shared $(TARGET_LDFLAGS)" \ + CC="$(TARGET_CC) $(TARGET_CFLAGS) $(FPIC) -std=c99" \ + LD="$(TARGET_CROSS)ld -shared" +endef + +define Package/luaexpat/install + $(INSTALL_DIR) $(1)/usr/lib/lua + $(INSTALL_DATA) $(PKG_BUILD_DIR)/src/lxp.so.1.1.0 $(1)/usr/lib/lua/lxp.so + $(INSTALL_DIR) $(1)/usr/lib/lua/lxp + $(INSTALL_DATA) $(PKG_BUILD_DIR)/src/lxp/lom.lua $(1)/usr/lib/lua/lxp +endef + +$(eval $(call BuildPackage,luaexpat)) diff --git a/lang/luaexpat/files/compat-5.1r5/compat-5.1.c b/lang/luaexpat/files/compat-5.1r5/compat-5.1.c new file mode 100644 index 0000000000..6fdb8b7bd6 --- /dev/null +++ b/lang/luaexpat/files/compat-5.1r5/compat-5.1.c @@ -0,0 +1,97 @@ +/* +** Compat-5.1 +** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat) +** $Id: compat-5.1.c,v 1.13 2006/02/20 21:12:47 carregal Exp $ +*/ + +#include +#include +#include "lua.h" +#include "lauxlib.h" +#include "compat-5.1.h" + +static void getfield(lua_State *L, int idx, const char *name) { + const char *end = strchr(name, '.'); + lua_pushvalue(L, idx); + while (end) { + lua_pushlstring(L, name, end - name); + lua_gettable(L, -2); + lua_remove(L, -2); + if (lua_isnil(L, -1)) return; + name = end+1; + end = strchr(name, '.'); + } + lua_pushstring(L, name); + lua_gettable(L, -2); + lua_remove(L, -2); +} + +static void setfield(lua_State *L, int idx, const char *name) { + const char *end = strchr(name, '.'); + lua_pushvalue(L, idx); + while (end) { + lua_pushlstring(L, name, end - name); + lua_gettable(L, -2); + /* create table if not found */ + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_newtable(L); + lua_pushlstring(L, name, end - name); + lua_pushvalue(L, -2); + lua_settable(L, -4); + } + lua_remove(L, -2); + name = end+1; + end = strchr(name, '.'); + } + lua_pushstring(L, name); + lua_pushvalue(L, -3); + lua_settable(L, -3); + lua_pop(L, 2); +} + +LUALIB_API void luaL_module(lua_State *L, const char *libname, + const luaL_reg *l, int nup) { + if (libname) { + getfield(L, LUA_GLOBALSINDEX, libname); /* check whether lib already exists */ + if (lua_isnil(L, -1)) { + int env, ns; + lua_pop(L, 1); /* get rid of nil */ + lua_pushliteral(L, "require"); + lua_gettable(L, LUA_GLOBALSINDEX); /* look for require */ + lua_getfenv(L, -1); /* getfenv(require) */ + lua_remove(L, -2); /* remove function require */ + env = lua_gettop(L); + + lua_newtable(L); /* create namespace for lib */ + ns = lua_gettop(L); + getfield(L, env, "package.loaded"); /* get package.loaded table */ + if (lua_isnil(L, -1)) { /* create package.loaded table */ + lua_pop(L, 1); /* remove previous result */ + lua_newtable(L); + lua_pushvalue(L, -1); + setfield(L, env, "package.loaded"); + } + else if (!lua_istable(L, -1)) + luaL_error(L, "name conflict for library `%s'", libname); + lua_pushstring(L, libname); + lua_pushvalue(L, ns); + lua_settable(L, -3); /* package.loaded[libname] = ns */ + lua_pop(L, 1); /* get rid of package.loaded table */ + lua_pushvalue(L, ns); /* copy namespace */ + setfield(L, LUA_GLOBALSINDEX, libname); + lua_remove (L, env); /* remove env */ + } + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + lua_pushstring(L, l->name); + for (i=0; ifunc, nup); + lua_settable(L, -(nup+3)); + } + lua_pop(L, nup); /* remove upvalues */ +} + diff --git a/lang/luaexpat/files/compat-5.1r5/compat-5.1.h b/lang/luaexpat/files/compat-5.1r5/compat-5.1.h new file mode 100644 index 0000000000..97570d9c8f --- /dev/null +++ b/lang/luaexpat/files/compat-5.1r5/compat-5.1.h @@ -0,0 +1,13 @@ +/* +** Compat-5.1 +** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat/) +** $Id: compat-5.1.h,v 1.8 2006/02/20 21:12:47 carregal Exp $ +*/ + +#ifndef COMPAT_H + +LUALIB_API void luaL_module(lua_State *L, const char *libname, + const luaL_reg *l, int nup); +#define luaL_openlib luaL_module + +#endif diff --git a/lang/luaexpat/files/compat-5.1r5/compat-5.1.lua b/lang/luaexpat/files/compat-5.1r5/compat-5.1.lua new file mode 100644 index 0000000000..0938d56a77 --- /dev/null +++ b/lang/luaexpat/files/compat-5.1r5/compat-5.1.lua @@ -0,0 +1,267 @@ +-- +-- Compat-5.1 +-- Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat) +-- According to Lua 5.1 +-- $Id: compat-5.1.lua,v 1.22 2006/02/20 21:12:47 carregal Exp $ +-- + +_COMPAT51 = "Compat-5.1 R5" + +local LUA_DIRSEP = '/' +local LUA_OFSEP = '_' +local OLD_LUA_OFSEP = '' +local POF = 'luaopen_' +local LUA_PATH_MARK = '?' +local LUA_IGMARK = ':' + +local assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type = assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type +local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub + +-- +-- avoid overwriting the package table if it's already there +-- +package = package or {} +local _PACKAGE = package + +package.path = LUA_PATH or os.getenv("LUA_PATH") or + ("./?.lua;" .. + "/usr/local/share/lua/5.0/?.lua;" .. + "/usr/local/share/lua/5.0/?/?.lua;" .. + "/usr/local/share/lua/5.0/?/init.lua" ) + +package.cpath = LUA_CPATH or os.getenv("LUA_CPATH") or + "./?.so;" .. + "./l?.so;" .. + "/usr/local/lib/lua/5.0/?.so;" .. + "/usr/local/lib/lua/5.0/l?.so" + +-- +-- make sure require works with standard libraries +-- +package.loaded = package.loaded or {} +package.loaded.debug = debug +package.loaded.string = string +package.loaded.math = math +package.loaded.io = io +package.loaded.os = os +package.loaded.table = table +package.loaded.base = _G +package.loaded.coroutine = coroutine +local _LOADED = package.loaded + +-- +-- avoid overwriting the package.preload table if it's already there +-- +package.preload = package.preload or {} +local _PRELOAD = package.preload + + +-- +-- looks for a file `name' in given path +-- +local function findfile (name, pname) + name = gsub (name, "%.", LUA_DIRSEP) + local path = _PACKAGE[pname] + assert (type(path) == "string", format ("package.%s must be a string", pname)) + for c in gfind (path, "[^;]+") do + c = gsub (c, "%"..LUA_PATH_MARK, name) + local f = io.open (c) + if f then + f:close () + return c + end + end + return nil -- not found +end + + +-- +-- check whether library is already loaded +-- +local function loader_preload (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + assert (type(_PRELOAD) == "table", "`package.preload' must be a table") + return _PRELOAD[name] +end + + +-- +-- Lua library loader +-- +local function loader_Lua (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local filename = findfile (name, "path") + if not filename then + return false + end + local f, err = loadfile (filename) + if not f then + error (format ("error loading module `%s' (%s)", name, err)) + end + return f +end + + +local function mkfuncname (name) + name = gsub (name, "^.*%"..LUA_IGMARK, "") + name = gsub (name, "%.", LUA_OFSEP) + return POF..name +end + +local function old_mkfuncname (name) + --name = gsub (name, "^.*%"..LUA_IGMARK, "") + name = gsub (name, "%.", OLD_LUA_OFSEP) + return POF..name +end + +-- +-- C library loader +-- +local function loader_C (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local filename = findfile (name, "cpath") + if not filename then + return false + end + local funcname = mkfuncname (name) + local f, err = loadlib (filename, funcname) + if not f then + funcname = old_mkfuncname (name) + f, err = loadlib (filename, funcname) + if not f then + error (format ("error loading module `%s' (%s)", name, err)) + end + end + return f +end + + +local function loader_Croot (name) + local p = gsub (name, "^([^.]*).-$", "%1") + if p == "" then + return + end + local filename = findfile (p, "cpath") + if not filename then + return + end + local funcname = mkfuncname (name) + local f, err, where = loadlib (filename, funcname) + if f then + return f + elseif where ~= "init" then + error (format ("error loading module `%s' (%s)", name, err)) + end +end + +-- create `loaders' table +package.loaders = package.loaders or { loader_preload, loader_Lua, loader_C, loader_Croot, } +local _LOADERS = package.loaders + + +-- +-- iterate over available loaders +-- +local function load (name, loaders) + -- iterate over available loaders + assert (type (loaders) == "table", "`package.loaders' must be a table") + for i, loader in ipairs (loaders) do + local f = loader (name) + if f then + return f + end + end + error (format ("module `%s' not found", name)) +end + +-- sentinel +local sentinel = function () end + +-- +-- new require +-- +function _G.require (modname) + assert (type(modname) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local p = _LOADED[modname] + if p then -- is it there? + if p == sentinel then + error (format ("loop or previous error loading module '%s'", modname)) + end + return p -- package is already loaded + end + local init = load (modname, _LOADERS) + _LOADED[modname] = sentinel + local actual_arg = _G.arg + _G.arg = { modname } + local res = init (modname) + if res then + _LOADED[modname] = res + end + _G.arg = actual_arg + if _LOADED[modname] == sentinel then + _LOADED[modname] = true + end + return _LOADED[modname] +end + + +-- findtable +local function findtable (t, f) + assert (type(f)=="string", "not a valid field name ("..tostring(f)..")") + local ff = f.."." + local ok, e, w = find (ff, '(.-)%.', 1) + while ok do + local nt = rawget (t, w) + if not nt then + nt = {} + t[w] = nt + elseif type(t) ~= "table" then + return sub (f, e+1) + end + t = nt + ok, e, w = find (ff, '(.-)%.', e+1) + end + return t +end + +-- +-- new package.seeall function +-- +function _PACKAGE.seeall (module) + local t = type(module) + assert (t == "table", "bad argument #1 to package.seeall (table expected, got "..t..")") + local meta = getmetatable (module) + if not meta then + meta = {} + setmetatable (module, meta) + end + meta.__index = _G +end + + +-- +-- new module function +-- +function _G.module (modname, ...) + local ns = _LOADED[modname] + if type(ns) ~= "table" then + ns = findtable (_G, modname) + if not ns then + error (string.format ("name conflict for module '%s'", modname)) + end + _LOADED[modname] = ns + end + if not ns._NAME then + ns._NAME = modname + ns._M = ns + ns._PACKAGE = gsub (modname, "[^.]*$", "") + end + setfenv (2, ns) + for i, f in ipairs (arg) do + f (ns) + end +end diff --git a/lang/luaexpat/patches/001-compile-fix.patch b/lang/luaexpat/patches/001-compile-fix.patch new file mode 100644 index 0000000000..c2e863a7e8 --- /dev/null +++ b/lang/luaexpat/patches/001-compile-fix.patch @@ -0,0 +1,10 @@ +--- a/config ++++ b/config +@@ -31,6 +31,6 @@ + -Wshadow \ + -Wwrite-strings + +-CFLAGS = $(CWARNS) -ansi -O2 -I$(LUA_INC) \ ++CFLAGS = $(CWARNS) -O2 -I$(LUA_INC) \ + -I$(COMPAT_DIR) -I$(EXPAT_INC) + CC = gcc