lua-users home
lua-l archive

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


> 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.