lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hallo,

    Attached to this email is a diff against the code found in the
wiki of a proposed extension library for Lua. It solves some stack
handling problems, missing external declarations and the absence of
the size field in the entry table for POSIX systems.

--
-alex
http://www.ventonegro.org/
# 
# old_revision [6fee76f318b488f976953b2d61bec8bcb6189a9e]
# 
# add_file "ChangeLog"
#  content [2c6dd8bfce95565afd221d8b0d25e8c21a5f6bbe]
# 
# add_file "posix/Makefile"
#  content [1c9c0250c9b12051d85735193dffeb153152553e]
# 
# add_file "w32api/Makefile"
#  content [36da8da25c89ba8bea0503aa9a4583c436366199]
# 
# patch "posix/ex.c"
#  from [0b966053dd5b8f862e12016350be9e1ec4e99770]
#    to [5f3f8edffc8854d768eecafdc44d8b4c0606f836]
# 
# patch "posix/spawn.c"
#  from [7b236dd3c4c59c0c3d519ad09cf579fa1487bd83]
#    to [31fd22d08a3b8660ebffe06065c5656178c83778]
# 
# patch "w32api/ex.c"
#  from [31feb6ea487c58ce2fd0b9a871fb642471a3b747]
#    to [e966301a50a7a8b75b1ec3e5877949342a4a268b]
# 
# patch "w32api/spawn.c"
#  from [9389c070dd06762f55cb5d897442b34a25e0c2a3]
#    to [7afcf1e16346fa1c004a724727239bea09418b29]
# 
============================================================
--- ChangeLog	2c6dd8bfce95565afd221d8b0d25e8c21a5f6bbe
+++ ChangeLog	2c6dd8bfce95565afd221d8b0d25e8c21a5f6bbe
@@ -0,0 +1,10 @@
+2006-05-13 Alex Queiroz <ventonegro@ventonegro.org>
+
+	* posix/Makefile: file added.
+	* posix/ex.c, posix/spawn.c: Added external declaration of environ.
+
+2006-05-13 Alex Queiroz <ventonegro@ventonegro.org>
+
+	* w32api/Makefile: file added.
+	* w32api/ex.c, w32api/spawn.c: Proper stack handling.
+
============================================================
--- posix/Makefile	1c9c0250c9b12051d85735193dffeb153152553e
+++ posix/Makefile	1c9c0250c9b12051d85735193dffeb153152553e
@@ -0,0 +1,30 @@
+
+# Tools
+CC = gcc
+CFLAGS = -g -O2 -Wall
+LD = gcc -O -shared
+RM = rm -f
+
+# Module
+EX_MOD = ex.so
+
+# Objects
+EX_OBJS = \
+	ex.o \
+	spawn.o
+
+# Target
+all: $(EX_MOD)
+
+$(EX_MOD): $(EX_OBJS)
+	$(LD) -o $(EX_MOD) $(EX_OBJS)
+
+.PHONY: clean
+
+clean:
+	$(RM) $(EX_MOD) $(EX_OBJS)
+
+# Automatic rules
+%.o: %.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
============================================================
--- w32api/Makefile	36da8da25c89ba8bea0503aa9a4583c436366199
+++ w32api/Makefile	36da8da25c89ba8bea0503aa9a4583c436366199
@@ -0,0 +1,32 @@
+
+# Using MinGW
+
+# Tools
+CC = gcc
+CFLAGS = -g -O2 -Wall
+LD = gcc -O -shared
+RM = del /q
+
+# Module
+EX_MOD = ex.dll
+
+# Objects
+EX_OBJS = \
+	ex.o \
+	spawn.o
+
+# Target
+all: $(EX_MOD)
+
+$(EX_MOD): $(EX_OBJS)
+	$(LD) -o $(EX_MOD) $(EX_OBJS) -Lc:\mingw\bin -llua51
+
+.PHONY: clean
+
+clean:
+	$(RM) $(EX_MOD) $(EX_OBJS)
+
+# Automatic rules
+%.o: %.c
+	$(CC) $(CFLAGS) -c $< -o $@
+
============================================================
--- posix/ex.c	0b966053dd5b8f862e12016350be9e1ec4e99770
+++ posix/ex.c	5f3f8edffc8854d768eecafdc44d8b4c0606f836
@@ -18,6 +18,8 @@
 
 #define absindex(L,i) ((i)>0?(i):lua_gettop(L)+(i)+1)
 
+extern char **environ;
+
 /* -- nil error */
 extern int push_error(lua_State *L)
 {
@@ -152,6 +154,7 @@
 		} break;
 	}
 	isdir = S_ISDIR(st.st_mode);
+	size = st.st_size;
 	if (lua_type(L, 2) != LUA_TTABLE) {
 		lua_newtable(L);
 		lua_replace(L, 2);
============================================================
--- posix/spawn.c	7b236dd3c4c59c0c3d519ad09cf579fa1487bd83
+++ posix/spawn.c	31fd22d08a3b8660ebffe06065c5656178c83778
@@ -11,6 +11,8 @@
 
 #include "spawn.h"
 
+extern char **environ;
+
 struct spawn_params {
 	lua_State *L;
 	const char *command, **argv, **envp;
============================================================
--- w32api/ex.c	31feb6ea487c58ce2fd0b9a871fb642471a3b747
+++ w32api/ex.c	e966301a50a7a8b75b1ec3e5877949342a4a268b
@@ -202,20 +202,16 @@
 		size = lsize;
 		} break;
 	}
-	if (lua_type(L, 2) != LUA_TTABLE) {
-		lua_newtable(L);
-		lua_replace(L, 2);
-	}
-	lua_pushliteral(L, "type");
+
+	lua_newtable(L);
 	if (isdir)
 		lua_pushliteral(L, "directory");
 	else
 		lua_pushliteral(L, "file");
-	lua_settable(L, 2);
-	lua_pushliteral(L, "size");
+	lua_setfield(L, -2, "type");
 	lua_pushnumber(L, size);
-	lua_settable(L, 2);
-	lua_settop(L, 2);
+	lua_setfield(L, -2, "size");
+
 	return 1;
 }
 
============================================================
--- w32api/spawn.c	9389c070dd06762f55cb5d897442b34a25e0c2a3
+++ w32api/spawn.c	7afcf1e16346fa1c004a724727239bea09418b29
@@ -50,22 +50,23 @@
 /* cmd opts ... argtab -- cmd opts ... cmdline */
 void spawn_param_args(struct spawn_params *p)
 {
+	int t;
 	lua_State *L = p->L;
 	debug("spawn_param_args:"); debug_stack(L);
 	luaL_Buffer args;
 	luaL_buffinit(L, &args);
 	size_t i, n = lua_objlen(L, -1);
 	/* concatenate the arg array to a string */
+	t = lua_gettop(L);
 	for (i = 1; i <= n; i++) {
 		int quote;
-		lua_rawgeti(L, -1, i);     /* ... argtab arg */
+		lua_rawgeti(L, t, i);     /* ... argtab arg */
 		/* XXX checkstring is confusing here */
 		quote = needs_quoting(luaL_checkstring(L, -1));
 		luaL_putchar(&args, ' ');
 		if (quote) luaL_putchar(&args, '"');
 		luaL_addvalue(&args);
 		if (quote) luaL_putchar(&args, '"');
-		lua_pop(L, 1);             /* ... argtab */
 	}
 	luaL_pushresult(&args);        /* ... argtab argstr */
 	lua_pushvalue(L, 1);           /* cmd opts ... argtab argstr cmd */