lua-users home
lua-l archive

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


[vbezobiuk@vbezobiuk ~]$ lua5.1
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> setmetatable(_G,{__index=function(...)print(...)end})
table: 0x10476b0    _PROMPT

here it is. lua cli requests the global variable _PROMPT :) and os.getenv needs string as it's first argument
the prompt is not set by default (that's why __index got triggered)
probably you wanted something like:

[vbezobiuk@vbezobiuk ~]$ lua5.1
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> setmetatable(_G,{__index=function(...) return os.getenv(select(2,...)) end})
> =HOME
/home/vbezobiuk
>
didn't you? :)

Sincerely,
  Volodymyr


On Thu, Jan 31, 2013 at 3:19 PM, Rob Kendrick <rjek@rjek.com> wrote:
In the command-line REPL, execute the following:

        setmetatable(_G,{__index=os.getenv})

In my caffeine-deprived state, I am at a loss to explain what happens:

rjek@octopus:~$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> setmetatable(_G,{__index=os.getenv})
bad argument #1 to '?' (string expected, got table)
rjek@octopus:~$ echo $?
1
rjek@octopus:~$

B.