Lua API guide
Load opcua.api to create clients, servers, and models. Examples use
ua as the local name for the returned table. Start with the object that
owns the operation:
Object |
Entry point and reference |
|---|---|
Network client |
|
Local server |
|
Address space |
|
MQTT publisher or subscriber (full) |
|
Configuration and version
- ua.clientConfig(config)
- ua.serverConfig(config)
Validate a required Lua configuration table, fill its defaults in place and return the same table. Invalid settings raise a Lua error. Constructors call the matching function themselves. Call it directly to prepare a configuration for
ua.baseModel()orua.emptyModel(). See Client configuration table and Configuration table.
- ua.versionValid(version)
- ua.assertVersion(version)
Compare the required string with
ua.Version.Versionusing exact equality. The first returns a boolean. The second raises an error on a mismatch and returns no value on success.ua.Version.BuildNumberis a separate string. See Choose a build profile to identify the build settings for that release.
Identifiers, values and requests
NodeId covers
ua.NodeId.fromString,toStringandisValid.ua.NodeId.Nullis the string"i=0".ua.NodeId.isNull(id)returns a boolean and accepts nil, a string or a parsed NodeId table.ua.createGuid()returns a new GUID string.Use
ua.AttributeIdto select an attribute andua.VariantTypeto identify the type of a value. Data Types describes both the Lua value and its wire representation.ua.StatusCode.Goodis numeric zero.ua.newFolderParams(parentNodeId, name[, newNodeId])andua.newVariableParams(parentNodeId, name, value[, newNodeId])return one AddNodes item table. Supply a parent NodeId string, a name string or a table withBrowseName(QualifiedName) andDisplayName(LocalizedText), and, for a variable, a DataValue table. Omit the new NodeId string to let the server assign one. See Adding Nodes.ua.newEventFilter(selectFields[, whereClause])builds a filter for an event monitored item. See Data Change and Event Subscriptions for field selection and predicates. Events require the full profile.ua.parseUrl(url)accepts an endpoint URL string and returns a table with stringschemeandhost, numericportand stringpath. An omitted port or path is nil. An invalid URL returns nil and a numeric status code.
Identity token helpers
Most clients can use the forms of client:activateSession described in
Client Authentication. When building a request by hand, the following
functions return an ExtensionObject table with a TypeId string and a
Body table. Each takes the server-advertised policy ID string first.
Function |
Remaining arguments |
|---|---|
|
None. |
|
Username string, password bytes and optional encryption algorithm URI string. |
|
User certificate bytes. |
|
Issued token bytes and optional encryption algorithm URI string. |
These helpers wrap the supplied bytes. The higher-level session API handles token encryption and signatures according to the negotiated policy.
Diagnostics and constants
ua.printTable(name, value[, output]) prints a labeled Lua value for
inspection. Pass a string label and an optional function receiving one line
at a time. See Logging subsystem for runtime traces.
The API exports numeric constants for node classes, attribute IDs, variant
types, value ranks, browse masks and monitoring modes. It also exports
NodeId strings in ua.DataTypeId and ua.ReferenceType, security policy
URIs in ua.SecurityPolicy, and transport URIs in
ua.TranportProfileUri (the spelling in Lua). Secure Policy lists
the policies implemented by each crypto backend.
ua.crypto_engine names the backend initially chosen by the runtime
("sharkssl" in BAS, "openssl" in stock Lua).
ua.crypto holds its module table. ua.setCryptoEngine(name) accepts
one of those strings, loads the named module and updates these two API
fields, or raises an error. The channel policy implementation reads its
backend directly from opcua.crypto. Use the host’s selected backend when
configuring channels. Minimal builds omit the OpenSSL Lua module.
ua.debug() starts the Lua debugger connection and requires the optional
ldbgmon module. ua.ServerState contains numeric server states.
ua.ServerProfile contains OPC UA profile URI constants. The build-time
selectors for minimal and full are documented in Choose a build profile.