lua-users home
lua-l archive

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


On Tuesday 11 October 2005 23:04, David Burgess wrote:
> I agree that it is a bug. The same problem occurs with
>
> lua - -e print(arg)  -- "arg1" or
> lua - -e print(...)  -- "arg1"
>
> What is your suggested solution?

What I've done is to change the relevant chunk of code at the end of 
handle_argv() with this:

    if (argv[i] != NULL) {
      const char *filename = argv[i];
      getargs(argv, i);  /* collect arguments */
      lua_setglobal(L, "arg");
      if (strcmp(filename, "/dev/stdin") == 0)
        filename = NULL;
      return file_input(filename);  /* stop scanning arguments */
    }

This allows:

echo "print(arg)" | lua /dev/stdin arg1

This mirrors the behaviour of a bunch of other tools such as awk that allow 
stdin, stdout etc to be specified in this way; plus, on Linux and AFAIK some 
other Unices, there really *is* a device called /dev/stdin that maps to fd 0. 
(And /dev/fd/0, and /proc/self/fd/0...)

However, this doesn't really make sense on non-Unix platforms, and so may not 
be suitable as a generic solution.

I'm using Lua 5.0, BTW.

-- 
+- David Given --McQ-+ "I smell a rat; I see him forming in the air &
|  dg@cowlark.com    | darkening the sky; but I'll nip him in the bud."
| (dg@tao-group.com) | --- Sir Boyle Roche
+- www.cowlark.com --+ 

Attachment: pgp6qEanbnvRf.pgp
Description: PGP signature