lua-users home
lua-l archive

Re: unexpected syntax error

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


On Wed, Nov 28, 2012 at 05:17:28PM +0100, Matthias Kluwe wrote:
> Hi!
> 
> I played around trying to create a small DSL and stumbled upon an
> unexpected behaviour. This is a small example:
> 
> local function f()
> return setmetatable( {}, {
> __div = function( t, arg )
> print( arg )
> end } )
> end
> 
> f{} / 'a'
That's because this is an expression, not a statement. It doesn't work
as f() / 42, either. You need to specify where to put the result, or
use it in a flow control structure.
> I get the error message "unexpected symbol near '/'".
> 
> Surprisingly, the following prints 'a':
> 
> (function() end)( f{} / 'a' )
Not to me: this is a statement that calls a function, passing in the
result of an expression.
B.

AltStyle によって変換されたページ (->オリジナル) /