1 diff -ur lua-5.1.4.orig/src/Makefile lua-5.1.4/src/Makefile
2 --- lua-5.1.4.orig/src/Makefile 2009-04-04 23:06:04.000000000 +0200
3 +++ lua-5.1.4/src/Makefile 2009-04-04 23:06:15.000000000 +0200
9 +LIBS= -lm -lz $(MYLIBS)
13 diff -ur lua-5.1.4.orig/src/lauxlib.c lua-5.1.4/src/lauxlib.c
14 --- lua-5.1.4.orig/src/lauxlib.c 2009-04-04 23:06:04.000000000 +0200
15 +++ lua-5.1.4/src/lauxlib.c 2009-04-05 00:03:33.000000000 +0200
23 /* This file uses only the official API of Lua.
25 char buff[LUAL_BUFFERSIZE];
28 +typedef struct LoadGZ {
31 + char buffer[LUAL_GZLDBUFFER];
35 static const char *getF (lua_State *L, void *ud, size_t *size) {
36 LoadF *lf = (LoadF *)ud;
41 +static const char *getGZ (lua_State *L, void *ud, size_t *size) {
42 + LoadGZ *lf = (LoadGZ *)ud;
45 + if (gzeof(lf->f)) return NULL;
46 + *size = gzread(lf->f, lf->buffer, sizeof(lf->buffer));
48 + if (lf->first_chunk) {
49 + lf->first_chunk = 0;
50 + if (strstr(lf->buffer, "#!") && (sp=strstr(lf->buffer, "\n")) != NULL) {
51 + *size -= ((uint)sp - (uint)lf->buffer);
61 static int errfile (lua_State *L, const char *what, int fnameindex) {
62 const char *serr = strerror(errno);
63 const char *filename = lua_tostring(L, fnameindex) + 1;
67 LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
68 + if ((filename != NULL) && strstr(filename, ".lua.gz")) {
69 + return luaL_loadfile_gzip(L, filename);
72 + return luaL_loadfile_plain(L, filename);
77 +LUALIB_API int luaL_loadfile_gzip (lua_State *L, const char *filename) {
80 + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
81 + lua_pushfstring(L, "@%s", filename);
82 + gzf.f = gzopen(filename, "r");
83 + gzf.first_chunk = 1;
84 + if (gzf.f == Z_NULL) return errfile(L, "open", fnameindex);
85 + status = lua_load(L, getGZ, &gzf, lua_tostring(L, -1));
86 + (void)gzclose(gzf.f);
87 + lua_remove(L, fnameindex);
92 +LUALIB_API int luaL_loadfile_plain (lua_State *L, const char *filename) {
94 int status, readstatus;
96 diff -ur lua-5.1.4.orig/src/lauxlib.h lua-5.1.4/src/lauxlib.h
97 --- lua-5.1.4.orig/src/lauxlib.h 2009-04-04 23:06:04.000000000 +0200
98 +++ lua-5.1.4/src/lauxlib.h 2009-04-04 23:06:15.000000000 +0200
100 LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
102 LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
103 +LUALIB_API int (luaL_loadfile_gzip) (lua_State *L, const char *filename);
104 +LUALIB_API int (luaL_loadfile_plain) (lua_State *L, const char *filename);
105 LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
107 LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
108 diff -ur lua-5.1.4.orig/src/luaconf.h lua-5.1.4/src/luaconf.h
109 --- lua-5.1.4.orig/src/luaconf.h 2009-04-04 23:06:04.000000000 +0200
110 +++ lua-5.1.4/src/luaconf.h 2009-04-04 23:27:20.000000000 +0200
112 #define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
113 #define LUA_PATH_DEFAULT \
114 "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
115 - LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
116 + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
117 + "./?.lua.gz;" LUA_LDIR"?.lua.gz;" LUA_LDIR"?/init.lua.gz;" \
118 + LUA_CDIR"?.lua.gz;" LUA_CDIR"?/init.lua.gz"
119 #define LUA_CPATH_DEFAULT \
120 "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
124 #define LUAL_BUFFERSIZE BUFSIZ
128 +@@ LUAL_GZLDBUFFER is the buffer size used by the gzip source loader.
130 +#define LUAL_GZLDBUFFER 8192
132 /* }================================================================== */