[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Exposure of nil to end-users
- From: Ben Harper <rogojin@...>
- Date: Thu, 5 Feb 2009 13:31:45 +0200
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.
>