[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to create interactive mode for Java Swing application using Lua Java?
- From: Sam Roberts <sroberts@...>
- Date: Tue, 24 Oct 2006 16:03:51 -0700
On Tue, Oct 24, 2006 at 10:43:11PM +0100, Jonas Bengtsson wrote:
> I think it was mainly a misunderstanding from my side. I thought the
> interactive mode works like irb for Ruby or Python, like:
>
> > 1 + 4
> 5
> > foo()
> "hello world"
>
> But now I know it doesn't so I don't have to recreate it in my Swing
> shell. Too bad Lua doesn't have implicit returns :-)
It does have the "=" shortcut:
> = 1 + 4
5
> = (function() return"hello world" end)()
hello world
= is just replaced with "return "
Also, a trick I learned from somewhere in the source and use in my
interactive consoles - I prepend "return " to any code before loading
it. If it fails to compile because of a syntax error, I try again
without the return.
This means that anything typed at the prompt that is an expression, like
> foo()
will leave it's return values on the stack. Then after the pcall you can
walk the stack and print any values you find on it. This makes it a bit
more irb-like.