Module l2dbus.validate

Validation Module.

This module contains several useful functions for validating arguments to ensure they're the correct types or formatted according to the D-Bus specification.

Functions

checkTypes (pattern, ...) Checks the argument types according to the specified pattern.
isValidUtf8 (str) A simple UTF-8 validator in Lua.
isValidBusName (name) Verifies the given name is a valid D-Bus bus name.
isValidObjectPath (name) Verifies the given name is a valid D-Bus object path.
isValidMember (name) Verifies the given name is a valid D-Bus member name.
isValidInterface (name) Verifies the given name is a valid D-Bus interface name.
isValidErrorName (name) Verifies the given name is a valid D-Bus error name.
verify (v, msg) Verifies v is true and if not throw a Lua error with msg as the string.
verifyTypes (pattern, ...) Verify the arguments match the acceptable pattern of types.
verifyTypesWithMsg (pattern, msg, ...) Check argument types and emit Lua error with message if invalid.

Fields

doValidation Set to true to enable validation, false to skip the calls to do validation or check argument types.


Functions

checkTypes (pattern, ...)
Checks the argument types according to the specified pattern. A pattern has the form of:

type1|type2|...

Where typeN is a Lua type or the '*' wildcard character which matches any type. The '|' character functions as a type name delimiter and separates alternate types that can match (e.g. like a logical OR).

Parameters:

  • pattern string The acceptable "types" pattern to match.
  • ... any The arguments to check against the pattern.

Returns:

  1. bool Returns true if the arguments match the pattern or false if there is no match (e.g. the argument is not one of the specified types).
  2. nil or number If all the arguments match the acceptable types then return nil otherwise return the argument index of the first argument that doesn't match the type pattern.
isValidUtf8 (str)
A simple UTF-8 validator in Lua. Tested only with texlua.
Manuel Pégourié-Gonnard, 2009, WTFPL v2.
See license for details on WTFPL v2.

Parameters:

  • str string The string to check to see if it's valid UTF-8 text.

Returns:

    bool Returns true if str is a valid utf-8 sequence according to RFC 3629.
isValidBusName (name)
Verifies the given name is a valid D-Bus bus name.

Checks to see whether the provided name meets the requirements for a valid D-Bus bus name.

Parameters:

  • name string D-Bus bus name to validate.

Returns:

    bool Returns true if bus name is valid, false otherwise.
isValidObjectPath (name)
Verifies the given name is a valid D-Bus object path.

Checks to see whether the provided path name meets the requirements for a valid D-Bus object path.

Parameters:

  • name string D-Bus object path to validate.

Returns:

    bool Returns true if object path is valid, false otherwise.
isValidMember (name)
Verifies the given name is a valid D-Bus member name.

Checks to see whether the provided name meets the requirements for a valid D-Bus member name. Member names are D-Bus member or signal names.

Parameters:

  • name string D-Bus member name to validate.

Returns:

    bool Returns true if the member name is valid, false otherwise.
isValidInterface (name)
Verifies the given name is a valid D-Bus interface name.

Checks to see whether the provided name meets the requirements for a valid D-Bus interface name.

Parameters:

  • name string D-Bus interface name to validate.

Returns:

    bool Returns true if the interface name is valid, false otherwise.
isValidErrorName (name)
Verifies the given name is a valid D-Bus error name. Checks to see whether the provided name meets the requirements for a valid D-Bus error name. This requirements are identical to the requirements for a D-Bus interface name.

Parameters:

  • name string D-Bus error name to validate.

Returns:

    bool Returns true if the error name is valid, false otherwise.

see also:

verify (v, msg)
Verifies v is true and if not throw a Lua error with msg as the string.

Parameters:

  • v bool Value to verify whether it evaluates to true or *false.
  • msg optional string The optional message to emit in the Lua error if v evaluates to false.

Returns:

    nil Returns nil if v evaluates to true, otherwise a Lua error is thrown with msg as the error text.
verifyTypes (pattern, ...)
Verify the arguments match the acceptable pattern of types.

Parameters:

  • pattern string

    Types pattern of the form:

        type1|type2|typeN|...
    
  • ... any Argument list to test against the pattern.

Returns:

    nil Returns nil if all the arguments match the types pattern. A Lua error is thrown if an unexpected type is found.
verifyTypesWithMsg (pattern, msg, ...)
Check argument types and emit Lua error with message if invalid.

Similar to verifyTypes except the Lua error that is emitted if the types aren't valid with include the specified message.

Parameters:

  • pattern string

    Types pattern of the form:

        type1|type2|typeN|...
    
  • msg string The message to include with any Lua error emitted.
  • ... any Argument list to test against the pattern.

Returns:

    nil Returns nil if all the arguments match the types pattern. A Lua error is thrown if an unexpected type is found.

Fields

doValidation
Set to true to enable validation, false to skip the calls to do validation or check argument types. This provides a convenient global property that can turn real validation on or off based on possible performance needs or debugging options. By default validation is enabled (true).
generated by LDoc 1.3