File lua/PropDef.lua

Classes for defining elementary properties and property sets. The classes in this module define the structure of a property set and the types of the elementary properties in a property set. A property set definition is represented by a tree of classes derived from the class PropBase. The inner nodes of the tree are represented by the class PropSet (which represents a set of properties) and the leafs have the type PropDef (which represents an elementary property).

Functions

PropBase:fullName () Return the full name of the property.
PropBase:isMain () Check whether the property definition refers to a main property set.
PropBase:isSet () Check whether the property definition refers to a set of properties.
PropDef:doValidation (val) Check whether a given value is valid for the property.
PropDef:getCppType () Return the C++ type that shall represent the property set.
PropDef:getInitializer () Return C++ code required for initializing the property as C++ object with its default value.
PropDef:getLuaType () Return the type identifier of the Lua type which may be used to initialized the property.
PropDef:new (base, pdef) Create an elementary property.
PropSet:contentPairs () Generator which returns pairs of local name and definition of the inner property definitions of the property set.
PropSet:getCppType (name) Return the C++ type that shall represent the property set.
PropSet:getId () Return the identifier of the property set (non-empty only if the set is a main set)
PropSet:getInitializer (name) Return C++ code required for initializing the property set as C++ object.
PropSet:isMain () Check whether the property definition refers to a main property set.
PropSet:isSet () Return true since definition refers to a set of properties.
PropSet:new (innerdefs) Create a property set definition.
PropSet:propDefPairs () Generator which returns pairs of full name and definition of the elementary properties in the set sorted alphabetically by their full name.
PropSet:setIsMain (file) Define the property set to be a 'main' set and store the name of its def-file.
createDefFromDSL (cfg) Create a property set definition from DSL-calls (given as executable chunk).
dsl.bool (initVal) DSL command 'bool' which creates a boolean property.
dsl.double (initVal) DSL command 'double' which creates a double property.
dsl.float (initVal) DSL command 'float' which creates a float property.
dsl.import (file) DSL command 'import' which reads a file that contains the self-contained definition of a property set and returns this property set definition.
dsl.include (file) DSL command 'include' which reads a given file and evaluates its content as if it were part of the DSL code where it is contained.
dsl.int (initVal) DSL command 'int' which creates an integer property.
dsl.long (initVal) DSL command 'long' which creates a long integer property.
dsl.set (inner) DSL command 'set' which creates a property set
dsl.string (initVal) DSL command 'string' which creates a string property.
getDsl () Accessor for the DSL environment (used for testing purposes)
loadDefFile (file) Load a property definition file and return it as a Lua chunk
parseDef (defstring) Read and parse a property set definition from DSL-commands in a string
parseDefFile (file) Read and parse a property set definition from DSL-commands in a file.

Tables

PropBase Base class for property definitions.
PropDef Class that represents the definition of an elementary property.
PropSet Class that represents a set of properties.
dsl Table which is used as environment for evaluating the property definition DSL.


Functions

PropBase:fullName ()
Return the full name of the property. (i.e. the path to the property if the property is contained in a property set; elements in the path are separated by '.'.

Return value:

the full name of the property in the format x.y.z
PropBase:isMain ()
Check whether the property definition refers to a main property set.
PropBase:isSet ()
Check whether the property definition refers to a set of properties.
PropDef:doValidation (val)
Check whether a given value is valid for the property.

Parameters

  • val:

Return value:

flag whether the validation was successful and an error message as optional second return value if the validation was not successful
PropDef:getCppType ()
Return the C++ type that shall represent the property set.

Return value:

string containing the C++ type
PropDef:getInitializer ()
Return C++ code required for initializing the property as C++ object with its default value.

Return value:

string containing the C++ initialization code
PropDef:getLuaType ()
Return the type identifier of the Lua type which may be used to initialized the property.
PropDef:new (base, pdef)
Create an elementary property.

Parameters

  • base: a table with the default definitions for the property type which shall be created
  • pdef: a table which overrides the default settings given with parameter 'base'

Return value:

a newly created property definition
PropSet:contentPairs ()
Generator which returns pairs of local name and definition of the inner property definitions of the property set.
PropSet:getCppType (name)
Return the C++ type that shall represent the property set.

Parameters

  • name:

Return value:

string containing the C++ type
PropSet:getId ()
Return the identifier of the property set (non-empty only if the set is a main set)
PropSet:getInitializer (name)
Return C++ code required for initializing the property set as C++ object. Returns the empty string if the set is not a main set because non-main sets are initialized as part of the main set to which they belong.

Parameters

  • name: name of the set

Return value:

string containing the C++ initialization code
PropSet:isMain ()
Check whether the property definition refers to a main property set.
PropSet:isSet ()
Return true since definition refers to a set of properties. Overrides implementation in PropBase
PropSet:new (innerdefs)
Create a property set definition. The property set is initialized as a non-main property set.

Parameters

  • innerdefs: map of properties indexed by name which belong to the property set to be created

Return value:

a newly created property set
PropSet:propDefPairs ()
Generator which returns pairs of full name and definition of the elementary properties in the set sorted alphabetically by their full name.
PropSet:setIsMain (file)
Define the property set to be a 'main' set and store the name of its def-file.

Parameters

  • file: name of the def-file (must end with .propdef)
createDefFromDSL (cfg)
Create a property set definition from DSL-calls (given as executable chunk).

Parameters

  • cfg: the chunk which contains the property set definition

Return value:

a property set containing all properties defined in cfg.
dsl.bool (initVal)
DSL command 'bool' which creates a boolean property.

Parameters

  • initVal:
dsl.double (initVal)
DSL command 'double' which creates a double property.

Parameters

  • initVal:
dsl.float (initVal)
DSL command 'float' which creates a float property.

Parameters

  • initVal:
dsl.import (file)
DSL command 'import' which reads a file that contains the self-contained definition of a property set and returns this property set definition.

Parameters

  • file:
dsl.include (file)
DSL command 'include' which reads a given file and evaluates its content as if it were part of the DSL code where it is contained.

Parameters

  • file:
dsl.int (initVal)
DSL command 'int' which creates an integer property.

Parameters

  • initVal:
dsl.long (initVal)
DSL command 'long' which creates a long integer property.

Parameters

  • initVal:
dsl.set (inner)
DSL command 'set' which creates a property set

Parameters

  • inner: the definition of the content of the property set (given as map with names as keys and property definitions as values).
dsl.string (initVal)
DSL command 'string' which creates a string property.

Parameters

  • initVal:
getDsl ()
Accessor for the DSL environment (used for testing purposes)

Return value:

the DSL environment table
loadDefFile (file)
Load a property definition file and return it as a Lua chunk

Parameters

  • file: name or base file name (suffix .propdef is assumed)

Return value:

Lua chunk with the parsed content of the given file
parseDef (defstring)
Read and parse a property set definition from DSL-commands in a string

Parameters

  • defstring: a string containing a property set definition.

Return value:

a property set containing all properties defined in the given string.
parseDefFile (file)
Read and parse a property set definition from DSL-commands in a file.

Parameters

  • file: a file containing a property set definition.

Return value:

a property set containing all properties defined in the given file.

Tables

PropBase
Base class for property definitions. Fields
  • name: the local name of the property (may be undefined for unnamed properties)
  • parent: a reference to the property set to which the property belongs
  • type: identifier of the type of the property (see definitions of the derived classes for a list of supported types)
PropDef
Class that represents the definition of an elementary property. Fields
  • type: id of the property type (supported types: "string", "int", "bool", "float")
  • luatype: contains the type of the Lua representation of the property type
  • cpptype: contains the C++ type of the property type
  • default: default value of the property
  • typeValidate: reference to a validation function which shall be called when the property value is set (optional, may be nil).
  • validate: reference to a validation function which shall be called when the property value is set (optional, may be nil).
  • convert: reference to a conversion function which converts a Lua object to the internal representation of the property value (optional, may be nil).
PropSet
Class that represents a set of properties. Fields
  • type: contains always "set" in for this type
  • content: an array containing the definitions of the properties that belong to the property set
  • main: flag whether the property set is a 'main' set, i.e., it has a self-contained definition (usually in its own .def-file)
  • id: identifier of the property set (non-empty only for main sets)
  • file: the file which contains the definition of the property set (if the property set was loaded from a file)
dsl
Table which is used as environment for evaluating the property definition DSL.

Valid XHTML 1.0!