Validation Utilities


These functions can be used to ensure the validity of data and datatypes, and ensure environments are set up correctly.

etc.check_depends

Usage: etc.check_depends(...)
 Takes a list of 'dependecies' in the format specified below, and checks if all are satisfied. If so, return true; else return false and the dependency (including the special character) that failed to resolve.

Dependency Format

 Each dependency is a string in the form of a name optionally preceded by a special control character that specifies the type of dependency to test for. The following formats are allowed:

etc.validate_table_struc

Usage: etc.validate_table_struc(table, template[, table_name])
 Takes a table and recursively tests if it matches the structure specified in a template. Returns a boolean indicating whether the match was successful, and if false, a 'key path' representing the part of the table that failed (formatted like table.<key>.<key>...). table_name is optional, and if set will change the name of the root table in the key path.
Note that keys not specified in the template are allowed to exist in the table; the table can contain arbitrary keys as long as they don't conflict with any defined key types.

Template Format

 The template is a table with the exact structure the tested table is expected to have, with its' bottom-level keys containing a string specifying the type they should have. If the string is prepended with a question mark (?) it is optional; however it is still required to match the type (so it can be of the correct type or nil).

This example template...

{
	foo = {
		bar = 'string',
		baz = '?number'
	},
	qux = 'table'
}
Will match any table with the following:

etc.is_*

Usage: etc.is_<type>(...)
 Returns true if all members of ... are of a specified type. See the table below for a list of options for type.