# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: package/.../lua-posix/t2-ext-glob.patch
# Copyright (C) 2004 - 2006 The T2 SDE Project
# 
# More information can be found in the files COPYING and README.
# 
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- T2-COPYRIGHT-NOTE-END ---
--- posix/lposix.c	2005-09-08 21:50:42.445019600 +0200
+++ posix-t2/lposix.c	2005-09-08 21:49:14.994723494 +0200
@@ -22,6 +22,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <utime.h>
+#include <glob.h>
 
 #define MYNAME		"posix"
 #define MYVERSION	MYNAME " library for " LUA_VERSION " / Nov 2003"
@@ -177,6 +178,25 @@
 }
 
 
+static int Pglob(lua_State *L)			/** glob(pattern) */
+{
+	const char *pattern = luaL_optstring(L, 1, ".");
+	glob_t globres;
+
+	if (glob(pattern, GLOB_MARK, NULL, &globres))
+		return pusherror(L, pattern);
+	else
+	{
+		int i;
+		lua_newtable(L);
+		for (i=1; i<=globres.gl_pathc; i++)
+			storeindex(L, i, globres.gl_pathv[i-1]);
+		globfree(&globres);
+		return 1;
+	}
+}
+
+
 static int aux_files(lua_State *L)
 {
 	DIR *d = lua_touserdata(L, lua_upvalueindex(1));
@@ -773,6 +793,7 @@
 	{"getlogin",		Pgetlogin},
 	{"getpasswd",		Pgetpasswd},
 	{"getprocessid",	Pgetprocessid},
+	{"glob",                Pglob},
 	{"kill",		Pkill},
 	{"link",		Plink},
 	{"mkdir",		Pmkdir},