lua-users home
lua-l archive

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


On Thu, May 20, 2010 at 3:45 PM, Romulo <romuloab@gmail.com> wrote:
> In some recents projects I have implemented an interpolated version of
> assert, in which it justs comstructs the error message if the
> expression evaluates to false.

That is cute.  The basic problem is how to 'quote' an operation so
that it can be executed later.

At the risk of stirring things up, this is where the short-lambda form
can be useful:

assertc (mob:isalive(), || "the mob "..mob.name.." must be alive")

function assertc(condn,fun)
    if not condn then assert(false,fn()) end
end

The cost? Lots of little closures.

Increasingly thinking that this is one of the few places where those
unfashionable things, macros, are actually useful.

steve d.