[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Exposure of nil to end-users
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 5 Feb 2009 08:55:26 -0200
> 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.