aboutsummaryrefslogtreecommitdiff
path: root/loslib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-03-03 13:34:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-03-03 13:34:46 -0300
commitd806710ab5622487159f2a8aecf72003d831542b (patch)
tree0a2c49e7ee732f17002ed086420f51ca7f42b221 /loslib.c
parente049abb69a45e06ca5769a3956a0ba36a959d29e (diff)
downloadlua-d806710ab5622487159f2a8aecf72003d831542b.tar.gz
lua-d806710ab5622487159f2a8aecf72003d831542b.tar.bz2
lua-d806710ab5622487159f2a8aecf72003d831542b.zip
returns for file-related functions and process-related functions
unified in 'auxlib'
Diffstat (limited to 'loslib.c')
-rw-r--r--loslib.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/loslib.c b/loslib.c
index d4ec884c..fc7f5459 100644
--- a/loslib.c
+++ b/loslib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loslib.c,v 1.32 2010/10/05 12:18:03 roberto Exp roberto $ 2** $Id: loslib.c,v 1.33 2011/01/26 16:30:02 roberto Exp roberto $
3** Standard Operating System library 3** Standard Operating System library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -59,37 +59,28 @@
59 59
60 60
61 61
62static int os_pushresult (lua_State *L, int i, const char *filename) { 62static int os_execute (lua_State *L) {
63 int en = errno; /* calls to Lua API may change this value */ 63 const char *cmd = luaL_optstring(L, 1, NULL);
64 if (i) { 64 int stat = system(cmd);
65 lua_pushboolean(L, 1); 65 if (cmd != NULL)
66 return 1; 66 return luaL_execresult(L, stat);
67 }
68 else { 67 else {
69 lua_pushnil(L); 68 lua_pushboolean(L, stat); /* true if there is a shell */
70 lua_pushfstring(L, "%s: %s", filename, strerror(en)); 69 return 1;
71 lua_pushinteger(L, en);
72 return 3;
73 } 70 }
74} 71}
75 72
76 73
77static int os_execute (lua_State *L) {
78 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
79 return 1;
80}
81
82
83static int os_remove (lua_State *L) { 74static int os_remove (lua_State *L) {
84 const char *filename = luaL_checkstring(L, 1); 75 const char *filename = luaL_checkstring(L, 1);
85 return os_pushresult(L, remove(filename) == 0, filename); 76 return luaL_fileresult(L, remove(filename) == 0, filename);
86} 77}
87 78
88 79
89static int os_rename (lua_State *L) { 80static int os_rename (lua_State *L) {
90 const char *fromname = luaL_checkstring(L, 1); 81 const char *fromname = luaL_checkstring(L, 1);
91 const char *toname = luaL_checkstring(L, 2); 82 const char *toname = luaL_checkstring(L, 2);
92 return os_pushresult(L, rename(fromname, toname) == 0, fromname); 83 return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);
93} 84}
94 85
95 86