lua-users home
lua-l archive

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


on 5/10/07 5:20 AM, David Haley at dchaley@gmail.com wrote:

> For instance, this entire statement should just disappear:
> 
> assert(self.assignment[var] == nil, "var '" .. var .. "' already had
> value '" .. (self.assignment[var] or "nil") .. "'")

That's also a prime example of why one would want to drop out such
assertions. In a debug build, you might not care that it always builds the
error string, but in production code it could be a real annoyance.

The efficient way to write this if you don't want the extra overhead is:

    if self.assignment[var] ~= nil then
        local errorMessage = "var '" .. tostring(var) ..
            "' already had value '" .. tostring(self.assignment[var]) ..
            "'"
        error(errorMessage)
    end

That's a lot more typing, however, and hence people will tend to just use
assert.

Now, if assert were a macro...

Mark