lua-users home
lua-l archive

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


Hi,

What I'm trying to achieve is an interactive Lua command line in my
program, which executes the given Lua commands, then display their
results. (Or, let's say, display the result of the first or last
command, if there are more than one.)

According to the lua_pcall() docs, there should be values on the stack
after execution. I noticed that if I specify a "return" statement
explicitly at the end, the values are passed through the stack, but
otherwise not.

What I'd really like is to get results on the stack without giving an
explicit "return" statement. I need it because this will be an
interactive Lua 'console', where users can type quick commands that
get evaluated, and the idea is that the user should type only like
this:

math.sin(1)

instead of typing

print(math.sin(1)) or
return math.sin(1)

Any ideas on how to achieve this? (An alternative: if I somehow could
detect whether the to-be-executed block contains a single command, and
insert a 'return' statement before it somehow.) I'm open to any idea
:)


imre


--
[ Imre Tuske | http://... | mailto:imre.tuske@gmail.com ]