GObject Integration¶
The Lua engine that powers WirePlumber’s scripts provides direct integration with GObject. Most of the objects that you will deal with in the lua scripts are wrapping GObjects. In order to work with the scripts, you will first need to have a basic understanding of GObject’s basic concepts, such as signals and properties.
Properties¶
All GObjects have the ability to have properties. In C we normally use g_object_get to retrieve them and g_object_set to set them.
In WirePlumber’s lua engine, these properties are exposed as object members of the Lua object.
For example:
-- read the "bound-id" GObject property from the proxy
local proxy = function_that_returns_a_wp_proxy()
local proxy_id = proxy["bound-id"]
print("Bound ID: " .. proxy_id)
Writable properties can also be set in a similar fashion:
-- set the "scale" GObject property to the enum value "cubic"
local mixer = ...
mixer["scale"] = "cubic"
Signals¶
GObjects also have a generic mechanism to deliver events to external callbacks. These events are called signals
All lua objects that wrap a GObject contain the following methods:
- connect(detailed_signal, callback)¶
Connects the signal to a callback. When the signal is emitted by the underlying object, the callback will be executed.
- Parameters
detailed_signal – the signal name to listen to (of the form “signal-name::detail”)
callback – a lua function that will be called when the signal is emitted
- call(action_signal, ...)¶
Calls an action signal on this object.
- Parameters
action_signal – the signal name to call
... – a list of arguments that will be passed to the signal