lua-users home
lua-l archive

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


That's awesome!

On Thu, Feb 5, 2009 at 12:55 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> In this example, value = nil
>> User Types:      value .. "abc"
>> User Expects:   'abc'
>> User Gets:        Error: attempt to concatenate a nil value
>
> Try this:
>
>    debug.setmetatable(nil,{
>            __concat = function (x,y) return (x or "") .. (y or "") end,
>            __tostring = function (x) return "NIL" end,
>    })
>    print(value .. "abc")
>    print("XYZ" .. anothervalue)
>    print(hello)
>
> You can avoid using debug.setmetatable by coding this in C.
>