Detecting interactive mode
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Detecting interactive mode
- From: JM Fernandez <elcubion@...>
- Date: 2010年2月23日 17:22:17 +0100
Hello.
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
break
end
end
end
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.
Manel