Browse Source

Copy luaexpat package from old repository

Signed-off-by: W. Michael Petullo <mike@flyn.org>
W. Michael Petullo 10 years ago
parent
commit
2576665677

+ 56
- 0
lang/luaexpat/Makefile View File

@@ -0,0 +1,56 @@
1
+# 
2
+# Copyright (C) 2009 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=luaexpat
11
+PKG_VERSION:=1.1
12
+PKG_RELEASE:=2
13
+
14
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15
+PKG_SOURCE_URL:=http://luaforge.net/frs/download.php/2469
16
+PKG_MD5SUM:=6ecb895ccf5cff1e7f2facd438b1f8d0
17
+
18
+include $(INCLUDE_DIR)/package.mk
19
+
20
+define Package/luaexpat
21
+  SUBMENU:=Lua
22
+  SECTION:=lang
23
+  CATEGORY:=Languages
24
+  TITLE:=LuaExpat 
25
+  URL:=http://www.keplerproject.org/luaexpat/
26
+  MAINTAINER:=W. Michael Petullo <mike@flyn.org>
27
+  DEPENDS:=+lua +libexpat
28
+endef
29
+
30
+define Package/luaexpat/description
31
+  LuaExpat is a SAX XML parser based on the Expat library.
32
+endef
33
+
34
+define Build/Configure
35
+endef
36
+
37
+define Build/Compile
38
+	$(CP) files/compat-5.1r5 $(PKG_BUILD_DIR)/compat-5.1r5
39
+	$(MAKE) -C $(PKG_BUILD_DIR) \
40
+	EXPAT_INC="$(STAGING_DIR)/usr/include/" \
41
+	LUA_INC="$(STAGING_DIR)/usr/include/" \
42
+	LUA_LIBDIR="$(STAGING_DIR)/usr/lib/" \
43
+	COMPAT_DIR="$(PKG_BUILD_DIR)/compat-5.1r5" \
44
+	LIB_OPTION="-shared $(TARGET_LDFLAGS)" \
45
+	CC="$(TARGET_CC) $(TARGET_CFLAGS) $(FPIC) -std=c99" \
46
+	LD="$(TARGET_CROSS)ld -shared" 
47
+endef
48
+
49
+define Package/luaexpat/install
50
+	$(INSTALL_DIR) $(1)/usr/lib/lua
51
+	$(INSTALL_DATA) $(PKG_BUILD_DIR)/src/lxp.so.1.1.0 $(1)/usr/lib/lua/lxp.so
52
+	$(INSTALL_DIR) $(1)/usr/lib/lua/lxp
53
+	$(INSTALL_DATA) $(PKG_BUILD_DIR)/src/lxp/lom.lua $(1)/usr/lib/lua/lxp
54
+endef
55
+
56
+$(eval $(call BuildPackage,luaexpat))

+ 97
- 0
lang/luaexpat/files/compat-5.1r5/compat-5.1.c View File

@@ -0,0 +1,97 @@
1
+/*
2
+** Compat-5.1
3
+** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat)
4
+** $Id: compat-5.1.c,v 1.13 2006/02/20 21:12:47 carregal Exp $
5
+*/
6
+
7
+#include <stdio.h>
8
+#include <string.h>
9
+#include "lua.h"
10
+#include "lauxlib.h"
11
+#include "compat-5.1.h"
12
+
13
+static void getfield(lua_State *L, int idx, const char *name) {
14
+    const char *end = strchr(name, '.');
15
+    lua_pushvalue(L, idx);
16
+    while (end) {
17
+        lua_pushlstring(L, name, end - name);
18
+        lua_gettable(L, -2);
19
+        lua_remove(L, -2);
20
+        if (lua_isnil(L, -1)) return;
21
+        name = end+1;
22
+        end = strchr(name, '.');
23
+    }
24
+    lua_pushstring(L, name);
25
+    lua_gettable(L, -2);
26
+    lua_remove(L, -2);
27
+}
28
+
29
+static void setfield(lua_State *L, int idx, const char *name) {
30
+    const char *end = strchr(name, '.');
31
+    lua_pushvalue(L, idx);
32
+    while (end) {
33
+        lua_pushlstring(L, name, end - name);
34
+        lua_gettable(L, -2);
35
+        /* create table if not found */
36
+        if (lua_isnil(L, -1)) {
37
+            lua_pop(L, 1);
38
+            lua_newtable(L);
39
+            lua_pushlstring(L, name, end - name);
40
+            lua_pushvalue(L, -2);
41
+            lua_settable(L, -4);
42
+        }
43
+        lua_remove(L, -2);
44
+        name = end+1;
45
+        end = strchr(name, '.');
46
+    }
47
+    lua_pushstring(L, name);
48
+    lua_pushvalue(L, -3);
49
+    lua_settable(L, -3);
50
+    lua_pop(L, 2);
51
+}
52
+
53
+LUALIB_API void luaL_module(lua_State *L, const char *libname,
54
+                              const luaL_reg *l, int nup) {
55
+  if (libname) {
56
+    getfield(L, LUA_GLOBALSINDEX, libname);  /* check whether lib already exists */
57
+    if (lua_isnil(L, -1)) { 
58
+      int env, ns;
59
+      lua_pop(L, 1); /* get rid of nil */
60
+      lua_pushliteral(L, "require");
61
+      lua_gettable(L, LUA_GLOBALSINDEX); /* look for require */
62
+      lua_getfenv(L, -1); /* getfenv(require) */
63
+      lua_remove(L, -2); /* remove function require */
64
+      env = lua_gettop(L);
65
+
66
+      lua_newtable(L); /* create namespace for lib */
67
+      ns = lua_gettop(L);
68
+      getfield(L, env, "package.loaded"); /* get package.loaded table */
69
+      if (lua_isnil(L, -1)) { /* create package.loaded table */
70
+          lua_pop(L, 1); /* remove previous result */
71
+          lua_newtable(L);
72
+          lua_pushvalue(L, -1);
73
+          setfield(L, env, "package.loaded");
74
+      }
75
+      else if (!lua_istable(L, -1))
76
+        luaL_error(L, "name conflict for library `%s'", libname);
77
+      lua_pushstring(L, libname);
78
+      lua_pushvalue(L, ns); 
79
+      lua_settable(L, -3); /* package.loaded[libname] = ns */
80
+      lua_pop(L, 1); /* get rid of package.loaded table */
81
+      lua_pushvalue(L, ns); /* copy namespace */
82
+      setfield(L, LUA_GLOBALSINDEX, libname);
83
+      lua_remove (L, env); /* remove env */
84
+    }
85
+    lua_insert(L, -(nup+1));  /* move library table to below upvalues */
86
+  }
87
+  for (; l->name; l++) {
88
+    int i;
89
+    lua_pushstring(L, l->name);
90
+    for (i=0; i<nup; i++)  /* copy upvalues to the top */
91
+      lua_pushvalue(L, -(nup+1));
92
+    lua_pushcclosure(L, l->func, nup);
93
+    lua_settable(L, -(nup+3));
94
+  }
95
+  lua_pop(L, nup);  /* remove upvalues */
96
+}
97
+

+ 13
- 0
lang/luaexpat/files/compat-5.1r5/compat-5.1.h View File

@@ -0,0 +1,13 @@
1
+/*
2
+** Compat-5.1
3
+** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat/)
4
+** $Id: compat-5.1.h,v 1.8 2006/02/20 21:12:47 carregal Exp $
5
+*/
6
+
7
+#ifndef COMPAT_H
8
+
9
+LUALIB_API void luaL_module(lua_State *L, const char *libname,
10
+                                       const luaL_reg *l, int nup);
11
+#define luaL_openlib luaL_module
12
+
13
+#endif

+ 267
- 0
lang/luaexpat/files/compat-5.1r5/compat-5.1.lua View File

@@ -0,0 +1,267 @@
1
+--
2
+-- Compat-5.1
3
+-- Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat)
4
+-- According to Lua 5.1
5
+-- $Id: compat-5.1.lua,v 1.22 2006/02/20 21:12:47 carregal Exp $
6
+--
7
+
8
+_COMPAT51 = "Compat-5.1 R5"
9
+
10
+local LUA_DIRSEP = '/'
11
+local LUA_OFSEP = '_'
12
+local OLD_LUA_OFSEP = ''
13
+local POF = 'luaopen_'
14
+local LUA_PATH_MARK = '?'
15
+local LUA_IGMARK = ':'
16
+
17
+local assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type = assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type
18
+local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub
19
+
20
+--
21
+-- avoid overwriting the package table if it's already there
22
+--
23
+package = package or {}
24
+local _PACKAGE = package
25
+
26
+package.path = LUA_PATH or os.getenv("LUA_PATH") or
27
+             ("./?.lua;" ..
28
+              "/usr/local/share/lua/5.0/?.lua;" ..
29
+              "/usr/local/share/lua/5.0/?/?.lua;" ..
30
+              "/usr/local/share/lua/5.0/?/init.lua" )
31
+ 
32
+package.cpath = LUA_CPATH or os.getenv("LUA_CPATH") or
33
+             "./?.so;" ..
34
+             "./l?.so;" ..
35
+             "/usr/local/lib/lua/5.0/?.so;" ..
36
+             "/usr/local/lib/lua/5.0/l?.so"
37
+
38
+--
39
+-- make sure require works with standard libraries
40
+--
41
+package.loaded = package.loaded or {}
42
+package.loaded.debug = debug
43
+package.loaded.string = string
44
+package.loaded.math = math
45
+package.loaded.io = io
46
+package.loaded.os = os
47
+package.loaded.table = table 
48
+package.loaded.base = _G
49
+package.loaded.coroutine = coroutine
50
+local _LOADED = package.loaded
51
+
52
+--
53
+-- avoid overwriting the package.preload table if it's already there
54
+--
55
+package.preload = package.preload or {}
56
+local _PRELOAD = package.preload
57
+
58
+
59
+--
60
+-- looks for a file `name' in given path
61
+--
62
+local function findfile (name, pname)
63
+	name = gsub (name, "%.", LUA_DIRSEP)
64
+	local path = _PACKAGE[pname]
65
+	assert (type(path) == "string", format ("package.%s must be a string", pname))
66
+	for c in gfind (path, "[^;]+") do
67
+		c = gsub (c, "%"..LUA_PATH_MARK, name)
68
+		local f = io.open (c)
69
+		if f then
70
+			f:close ()
71
+			return c
72
+		end
73
+	end
74
+	return nil -- not found
75
+end
76
+
77
+
78
+--
79
+-- check whether library is already loaded
80
+--
81
+local function loader_preload (name)
82
+	assert (type(name) == "string", format (
83
+		"bad argument #1 to `require' (string expected, got %s)", type(name)))
84
+	assert (type(_PRELOAD) == "table", "`package.preload' must be a table")
85
+	return _PRELOAD[name]
86
+end
87
+
88
+
89
+--
90
+-- Lua library loader
91
+--
92
+local function loader_Lua (name)
93
+	assert (type(name) == "string", format (
94
+		"bad argument #1 to `require' (string expected, got %s)", type(name)))
95
+	local filename = findfile (name, "path")
96
+	if not filename then
97
+		return false
98
+	end
99
+	local f, err = loadfile (filename)
100
+	if not f then
101
+		error (format ("error loading module `%s' (%s)", name, err))
102
+	end
103
+	return f
104
+end
105
+
106
+
107
+local function mkfuncname (name)
108
+	name = gsub (name, "^.*%"..LUA_IGMARK, "")
109
+	name = gsub (name, "%.", LUA_OFSEP)
110
+	return POF..name
111
+end
112
+
113
+local function old_mkfuncname (name)
114
+	--name = gsub (name, "^.*%"..LUA_IGMARK, "")
115
+	name = gsub (name, "%.", OLD_LUA_OFSEP)
116
+	return POF..name
117
+end
118
+
119
+--
120
+-- C library loader
121
+--
122
+local function loader_C (name)
123
+	assert (type(name) == "string", format (
124
+		"bad argument #1 to `require' (string expected, got %s)", type(name)))
125
+	local filename = findfile (name, "cpath")
126
+	if not filename then
127
+		return false
128
+	end
129
+	local funcname = mkfuncname (name)
130
+	local f, err = loadlib (filename, funcname)
131
+	if not f then
132
+		funcname = old_mkfuncname (name)
133
+		f, err = loadlib (filename, funcname)
134
+		if not f then
135
+			error (format ("error loading module `%s' (%s)", name, err))
136
+		end
137
+	end
138
+	return f
139
+end
140
+
141
+
142
+local function loader_Croot (name)
143
+	local p = gsub (name, "^([^.]*).-$", "%1")
144
+	if p == "" then
145
+		return
146
+	end
147
+	local filename = findfile (p, "cpath")
148
+	if not filename then
149
+		return
150
+	end
151
+	local funcname = mkfuncname (name)
152
+	local f, err, where = loadlib (filename, funcname)
153
+	if f then
154
+		return f
155
+	elseif where ~= "init" then
156
+		error (format ("error loading module `%s' (%s)", name, err))
157
+	end
158
+end
159
+
160
+-- create `loaders' table
161
+package.loaders = package.loaders or { loader_preload, loader_Lua, loader_C, loader_Croot, }
162
+local _LOADERS = package.loaders
163
+
164
+
165
+--
166
+-- iterate over available loaders
167
+--
168
+local function load (name, loaders)
169
+	-- iterate over available loaders
170
+	assert (type (loaders) == "table", "`package.loaders' must be a table")
171
+	for i, loader in ipairs (loaders) do
172
+		local f = loader (name)
173
+		if f then
174
+			return f
175
+		end
176
+	end
177
+	error (format ("module `%s' not found", name))
178
+end
179
+
180
+-- sentinel
181
+local sentinel = function () end
182
+
183
+--
184
+-- new require
185
+--
186
+function _G.require (modname)
187
+	assert (type(modname) == "string", format (
188
+		"bad argument #1 to `require' (string expected, got %s)", type(name)))
189
+	local p = _LOADED[modname]
190
+	if p then -- is it there?
191
+		if p == sentinel then
192
+			error (format ("loop or previous error loading module '%s'", modname))
193
+		end
194
+		return p -- package is already loaded
195
+	end
196
+	local init = load (modname, _LOADERS)
197
+	_LOADED[modname] = sentinel
198
+	local actual_arg = _G.arg
199
+	_G.arg = { modname }
200
+	local res = init (modname)
201
+	if res then
202
+		_LOADED[modname] = res
203
+	end
204
+	_G.arg = actual_arg
205
+	if _LOADED[modname] == sentinel then
206
+		_LOADED[modname] = true
207
+	end
208
+	return _LOADED[modname]
209
+end
210
+
211
+
212
+-- findtable
213
+local function findtable (t, f)
214
+	assert (type(f)=="string", "not a valid field name ("..tostring(f)..")")
215
+	local ff = f.."."
216
+	local ok, e, w = find (ff, '(.-)%.', 1)
217
+	while ok do
218
+		local nt = rawget (t, w)
219
+		if not nt then
220
+			nt = {}
221
+			t[w] = nt
222
+		elseif type(t) ~= "table" then
223
+			return sub (f, e+1)
224
+		end
225
+		t = nt
226
+		ok, e, w = find (ff, '(.-)%.', e+1)
227
+	end
228
+	return t
229
+end
230
+
231
+--
232
+-- new package.seeall function
233
+--
234
+function _PACKAGE.seeall (module)
235
+	local t = type(module)
236
+	assert (t == "table", "bad argument #1 to package.seeall (table expected, got "..t..")")
237
+	local meta = getmetatable (module)
238
+	if not meta then
239
+		meta = {}
240
+		setmetatable (module, meta)
241
+	end
242
+	meta.__index = _G
243
+end
244
+
245
+
246
+--
247
+-- new module function
248
+--
249
+function _G.module (modname, ...)
250
+	local ns = _LOADED[modname]
251
+	if type(ns) ~= "table" then
252
+		ns = findtable (_G, modname)
253
+		if not ns then
254
+			error (string.format ("name conflict for module '%s'", modname))
255
+		end
256
+		_LOADED[modname] = ns
257
+	end
258
+	if not ns._NAME then
259
+		ns._NAME = modname
260
+		ns._M = ns
261
+		ns._PACKAGE = gsub (modname, "[^.]*$", "")
262
+	end
263
+	setfenv (2, ns)
264
+	for i, f in ipairs (arg) do
265
+		f (ns)
266
+	end
267
+end

+ 10
- 0
lang/luaexpat/patches/001-compile-fix.patch View File

@@ -0,0 +1,10 @@
1
+--- a/config
2
++++ b/config
3
+@@ -31,6 +31,6 @@
4
+         -Wshadow \
5
+         -Wwrite-strings
6
+ 
7
+-CFLAGS = $(CWARNS) -ansi -O2 -I$(LUA_INC) \
8
++CFLAGS = $(CWARNS) -O2 -I$(LUA_INC) \
9
+    -I$(COMPAT_DIR) -I$(EXPAT_INC)
10
+ CC = gcc