monotone-devel
[Top][All Lists]
Advanced

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

Re: [Monotone-devel] [PATCH] New lua command execute_redirout which exec


From: Alex Queiroz
Subject: Re: [Monotone-devel] [PATCH] New lua command execute_redirout which executes an os command and captures standard output
Date: Mon, 14 Aug 2006 08:32:03 -0300

Hallo,

On 8/14/06, Daniel Dickinson <address@hidden> wrote:
============================================================
- --- luaext_platform.cc        d6b2a9e14b19d3fe6bc6105f3574048a333b118b
+++ luaext_platform.cc  186f18019b766de62254ea6e1a53dd82c08ac00b
@@ -1,7 +1,8 @@

 #include "lua.hh"

 #include <signal.h>
+#include <string>

 #include "platform.hh"

@@ -74,6 +75,28 @@ LUAEXT(spawn_redirected, )
   return 1;
 }

+LUAEXT(execute_redirout, )
+{
+  std::string out;
+  int n = -lua_gettop(L);
+  const char *path = luaL_checkstring(L, n);
+  n = -n;
+  char **argv = (char**)malloc((n+1)*sizeof(char*));
+  int i;
+  pid_t ret;
+  if (argv==NULL)
+    return 0;
+  argv[0] = (char*)path;
+  for (i=1; i<n; i++) argv[i] = (char*)luaL_checkstring(L, -(n - i));
+  argv[i] = NULL;
+
+  ret = process_execute_redirout(out, argv);
+  free(argv);
+  lua_pushnumber(L, ret);
+  lua_pushstring(L, out.c_str());
+  return 2;
+}
+
 LUAEXT(wait, )
 {
   pid_t pid = static_cast<pid_t>(luaL_checknumber(L, -1));
============================================================

    Don't do this because:

1) It's deprecated. In Lua 5.1, negative arguments to the
luaL_check*() functions cause an error.
2) It's not needed. The stack is adjusted upon entry of Lua
CFunctions. Your arguments are in the range [1..lua_gettop(L)].

--
-alex
http://www.ventonegro.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]