lua-users home
lua-l archive

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


I am trying to detect if Lua was launched in interactive mode.

The chunk is:

local interactive = true
if _G.arg then
  for _, v in pairs(_G.arg) do
    interactive = false
    if v == "-i" then
      interactive = true

But this does not work always. For example:

lua -e "require'somemodule'; do_something()"

thinks (with the code above) the mode is interactive, because arg
is nil (?) -- at least in two of the computers (with Linux Debian) I have access.

Is it possible to include in Lua 5.2 the assignation of _PROMPT
in interactive mode? (currently if the user does not assign _PROMPT it is nil,
and Lua uses ">").

With the modification I am proposing, then if the user assign _PROMPT
then is it not nil. If the user does not assign _PROMPT then the interpreter does
_PROMPT = ">". I think is a minimum change in the interpreter
that could help for some tasks.