lua-users home
lua-l archive

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


A long time ago I wrote a simple function to validate the contents of a lua table.

It took as input the table to validate and a table describing the table. The descriptor table had an entry for each possible entry in the data table.  For each possible entry it indicated a) whether the entry was required or optional, the valid type()s of the entry, and a bunch of stuff to validate the data (eg, mom and max numerical values).  If the entry  can itself be a table then the descriptor table has a reference to another descriptor table (etc)

The checking function also took a flag to indicate whether the table being validated could contain entries not in the descriptor table (or must only have entries in the descriptor table).

I don’t have access to it right this moment ... I can dig it out tonight and clean it up and post it tonight...


> On Aug 22, 2019, at 8:25 AM, Chris Smith <> wrote:
> I’m using Lua for configuration.  That means I need to validate entries for correctness, provide default values and warning messages where necessary, as well as ensuring my code doesn’t blow up when trying to access a non-existent structure.  I’m finding my code becoming bloated with largely boiler-plate safety code, particularly when accessing entries that are nested a few levels deep.
> Is there a nice, idiomatic way of handling this?
> Regards,
> Chris
> —
> Chris Smith <>