lua-users home
lua-l archive

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


steve donovan wrote: (first quote from Dirk Laurie)
> >   2. It's a pity there were not more posts along the lines of:
> >      - This is what we do in our organization.
> 
> 
> Well, I cannot speak for a 'community of best practice' but this is how
> I see the problem. Lua does not have null, as understood in other
> languages. The concept is embedded in many external data formats and is
> distinct from a false boolean value.  So a JSON module will define
> json.null and a DB module will define db.null.  If I wanted to dump out
> a database record to JSON then I must do something like this:
> 
> tsub(rec,db.null,json.null)   -- really easy and general function to write

With my JSON library it is possible to write

  getmetatable(db.null).__tojson = function () return "null" end

and db.null would work for the JSON encoder as well.  And in the other
direction you can just tell the decoder to use any arbitrary value for null.

I haven't even used that outside of a few tests so I don't think any
changes coming out of this discussion would have much impact for me --
except for a few special cases where I can define some unique handle
like json.null or db.null I am quite happy with nil as it is.  At least
until now -- maybe at some point there will be an application where I
would want an universal explicit null, but I don't see that yet.

Best regards,

David Kolf