Module PropTab
Table-like class for parsing and storing concrete values of property sets.
Functions
MT:__access (fullname, val, convertStr, simulateWrite, errorlevel) |
Access (read or write) a field in the property table by its full property path. |
MT:__get (fullname, errorlevel) |
Read access to property by its full name |
MT:__propPairs () |
Generator which creates a sequence of pairs with the full property path as first element and the property value as second element, sorted alphabetically by the property path. |
MT:__serialize () |
Serialize the content of the table. |
MT:__set (fullname, val, convertStr, errorlevel) |
Write access to property by its full name |
MT:__toPlainTab () |
Convert property table to a plain Lua map with property names as keys and property values as values. |
MT:__try (fullname, val, convertStr) |
Check write access to property by its full name |
create (pdef) |
Create a property table. |
loadPropFile (file) |
Load a property file and return it as a Lua chunk |
parseProperties (pdef, props) |
Parse property values and create a property table from them. |
readPropFile (pdef, file) |
Read a property file and create a property table with the values in the file. |
readPropString (pdef, propstr) |
Read a string with property definitions and create a property table with the values specified in the string. |
Tables
MT |
Meta-table which is used for controlling the access to the property table. |
Functions
- MT:__access (fullname, val, convertStr, simulateWrite, errorlevel)
-
Access (read or write) a field in the property table by its full property path.
Parameters
-
fullname: full name of the property with elements of the property path separated by ".".
-
val: if not nil, the property specified by fullname will be set to the given value.
-
convertStr: boolean flag which indicates whether the given value 'val' is a string that needs to be converted to the Lua type which is used for representing the property
-
simulateWrite: boolean flag which indicates whether writing the value 'val' shall only be simulated by checking that it is a legal value for the given property.
-
errorlevel: level on the call stack on which the error shall be reported (see documentation of standard Lua function 'error').
Return value:
if simulateWrite is set, the method returns an error flag (which is true if an error occurred) and an optional error message; otherwise, nil is returned.
- MT:__get (fullname, errorlevel)
-
Read access to property by its full name
Parameters
-
fullname: property path
-
errorlevel: level on the call stack for which errors shall be reported
Return value:
the value of the property if the read access is successful (otherwise an exception is thrown)
- MT:__propPairs ()
-
Generator which creates a sequence of pairs with the full property path as first element and the property value as second element, sorted alphabetically by the property path.
- MT:__serialize ()
-
Serialize the content of the table. The table can then be reconstructed by parsing the output using the parse functions in the module.
Return value:
the serialized table as string.
- MT:__set (fullname, val, convertStr, errorlevel)
-
Write access to property by its full name
Parameters
-
fullname: property path
-
val: property value which shall be set
-
convertStr: flag whether string values shall be converted to the Lua representation of the property (optional, default: false)
-
errorlevel: level on the call stack on which errors shall be reported (optional)
- MT:__toPlainTab ()
-
Convert property table to a plain Lua map with property names as keys and property values as values. Nested property sets are represented as nested tables.
Return value:
a table containing the values of the properties.
- MT:__try (fullname, val, convertStr)
-
Check write access to property by its full name
Parameters
-
fullname: property path
-
val: property value which shall be set
-
convertStr: flag whether string values shall be converted to the Lua representation of the property (optional, default: false)
Return value:
error flag (true indicates error) and optional error message
- create (pdef)
-
Create a property table. Creates a table for holding property values with meta-table MT.
Parameters
-
pdef: reference to a PropDef object which defines the structure of the property table
- loadPropFile (file)
-
Load a property file and return it as a Lua chunk
Parameters
-
file: name or base file name (suffix .properties is assumed)
Return value:
Lua chunk with the parsed content of the given file
- parseProperties (pdef, props)
-
Parse property values and create a property table from them. The property values are given as executable chunk which is executed in the context of a property table that is based on a given property definition.
Parameters
-
pdef: reference to a PropDef object which defines the structure of the property table.
-
props: a chunk which contains code that sets property values in the table.
Return value:
a PropTab object with the corresponding property values.
- readPropFile (pdef, file)
-
Read a property file and create a property table with the values in the file.
Parameters
-
pdef: reference to a PropDef object which defines the structure of the property table.
-
file: name of the file which shall be read.
Return value:
a PropTab object with the corresponding property values.
- readPropString (pdef, propstr)
-
Read a string with property definitions and create a property table with the values specified in the string.
Parameters
-
pdef: reference to a PropDef object which defines the structure of the property table.
-
propstr: string which shall be read.
Return value:
a PropTab object with the corresponding property values.
Tables
- MT
- Meta-table which is used for controlling the access to the property table. The property values are stored in a private table and access to them takes place through methods or through __index and __newindex and is checked for correctness of the used property values and types. The meta-table contains references to the following Lua standard modules: string, math, os and table. This is necessary for easy access to these modules within the context of the meta-table. Other methods (used for accessing the property values) are prefixed by '__' in order to avoid name clashes with properties.
Fields
-
__plain: reference to a table which stores the property values.
-
__propdef: reference to the PropDef object which specifies the structure of the property table.