wireplumber/src/scripts/node/create-virtual-item.lua
George Kiagiadakis 43aa2d4952 scripts: don't use 'local' for file-wide scoped variables
Since all scripts run in a sandbox with their own global environment,
it means that they don't interfere with each other's global variables.
Therefore, all file-wide variables can be declared global without
any change in behavior. In my understanding, it is better to do so
because this means that any code accessing those variables is going
to access them directly from the global environment table with a simple
lookup rather than having each variable referenced in the local closure
of each function separately.
2023-09-29 23:13:28 +03:00

46 lines
1.2 KiB
Lua

-- WirePlumber
--
-- Copyright © 2021 Collabora Ltd.
-- @author Julian Bouzas <julian.bouzas@collabora.com>
--
-- SPDX-License-Identifier: MIT
-- Receive script arguments from config.lua
-- creates the virtual items defined in the JSON(virtual.conf)
log = Log.open_topic ("s-node")
defaults = {}
defaults.virtual_items = Json.Object {}
config = {}
config.virtual_items = Conf.get_section (
"virtual-items", defaults.virtual_items):parse ()
function createVirtualItem (factory_name, properties)
-- create virtual item
local si_v = SessionItem ( factory_name )
if not si_v then
log:warning (si_v, "could not create virtual item of type " .. factory_name)
return
end
-- configure virtual item
if not si_v:configure(properties) then
log:warning(si_v, "failed to configure virtual item " .. properties.name)
return
end
-- activate and register virtual item
si_v:activate (Features.ALL, function (item)
item:register ()
log:info(item, "registered virtual item " .. properties.name)
end)
end
for name, properties in pairs(config.virtual_items) do
properties["name"] = name
createVirtualItem ("si-audio-virtual", properties)
end