lua-users home
lua-l archive

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


the standard way to do this is:

> = 5-3
2
> function two() return 2 end
> =two()
2

Is that too "special" ?

probably can't automatically prepend an equal, as this breaks function definitions.

On 6/21/06, Sam Roberts <sroberts@bycast.com> wrote:

I have a console, and I want people to be able to enter lua expressions
in, and see the results without having to do anything "special".

Should I just take their input, and put a "return( " before it and a ")"
after it? This seems a little hackish... is it the best way? What I
really want is the _expression_ to not have its return stack discarded.

% lua -i
> function two() return 2 end
> two()
> return two()
2
> return( two() )
2
> return( two() + 4 )
6
> return( {"a", "b"} )
table: 0x8068b40
>

I'll have to implement __tostring for tables, I guess.

Sam