Commit Graph

123 Commits

Author SHA1 Message Date
George Kiagiadakis
81af8c2069 lua: sandbox: remove all traces of the minimal_std flag, as it's no longer used 2022-04-23 20:14:59 +03:00
George Kiagiadakis
ecb6100b77 m-lua-scripting: wrap every script in a WpPlugin and expose async activation api
This allows scripts to declare when they have finished their loading,
so we can now also know when wireplumber is done loading and ready to
handle clients

Related to !313
2022-04-23 20:14:59 +03:00
George Kiagiadakis
031bc65c20 lua: sandbox: relax the sandbox to allow more functionality in scripts
This enables the debug and coroutine libraries and some more functions
that are not really so risky to have around

Related to #121
2022-04-23 20:14:59 +03:00
George Kiagiadakis
9387ce0d95 wplua: implement reference counting of the lua_State 2022-04-23 20:14:59 +03:00
George Kiagiadakis
9c22f6076a wplua: enable the use of require() to load lua libraries from scripts/lib 2022-04-23 20:14:59 +03:00
George Kiagiadakis
e1d0240bc9 wplua: split the functionality of the load functions into smaller functions
The load functions used to do 3 things:
- push the sandbox function on the stack
- load the file and push it as a function on the stack
- call the sandbox (or the file)

Now there are separate functions to do these 3:
- wplua_push_sandbox
- wplua_load_*
- wplua_pcall
2022-04-23 20:14:59 +03:00
Pauli Virtanen
bbe9ac00f3 modules: add m-i18n
Add simple gettext i18n module.

Add Lua script API functions I18n.gettext, I18n.ngettext.
2022-04-11 19:20:43 +03:00
George Kiagiadakis
17a257ddbe wplua: move under modules/module-lua-scripting
It's unlikely that wplua will ever be useful outside the context
of module-lua-scripting, so let's move it to keep all the code in one place
2022-03-24 09:47:59 +02:00
George Kiagiadakis
ca906362cd lua-scripting: expose WpImplMetadata on the API 2022-02-03 13:04:55 +02:00
Julian Bouzas
b0ddd6f890 m-lua-scripting: add Json.Raw constructor 2022-01-26 09:53:24 -05:00
Julian Bouzas
46ab414a04 spa-json: fix coverity scan issues 2022-01-25 21:18:16 -05:00
Julian Bouzas
20187e07b5 m-lua-scripting: add WpSpaJson API 2022-01-25 07:20:35 -05:00
Ashok Sidipotu
784c405c31 wp: support loading optional modules
-some modules will not be available during runtime, due to
  external dependencies.
 -these modules can now be marked optional.
 -loading of these optional modules will be attempted and if
  they are not available, wp will recover and will not be
  terminated.
2021-10-14 06:27:53 +00:00
Nicolai Syvertsen
27a6970de5 lua/api: fix impl_module_new arg parse 2021-10-13 17:25:51 +00:00
George Kiagiadakis
30407f9930 lua/api: add bindings for client:send_error() 2021-10-13 11:18:51 +03:00
George Kiagiadakis
5ce2dd3e66 lua/pod: add bindings for fixate() and filter() 2021-10-13 11:18:14 +03:00
Julian Bouzas
711d1ee686 spa-pod: add support for custom Id properties
Allows creating and parsing Pod Objects with custom properties.
2021-09-21 12:29:54 -04:00
George Kiagiadakis
2a5f9c51f2 lua/api: fix object constructors to fail gracefully 2021-09-15 12:51:47 +03:00
George Kiagiadakis
27ed36c2da wp: make the config file lookup methods more generic
* Make the flags public and give them nicer names
* Pass down the flags from the caller, so the caller can now explicitly
  ask for looking into specific directories
* Rename the methods
* Remove and inline the wp_get_xdg_config_dir() method, since it's only
  used internally
* Refactor the lookup dirs ordering to get both WIREPLUMBER_*_DIR env
  variables to replace all the other directories. Previously, we were looking
  for scripts in WIREPLUMBER_DATA_DIR, but we were also looking in /etc at
  the same time (with precedence, even), which could result in unexpected
  behaviour. Now, if a WIREPLUMBER environment variable is specified,
  we only look in there.
2021-08-19 10:06:37 +03:00
Arun Raghavan
129b44bb0c doc: Add WpImplModule docs for the C and Lua API 2021-08-18 16:04:39 +00:00
Arun Raghavan
ef29018c55 m-lua-scripting: Add WpImplModule bindings 2021-08-18 16:04:39 +00:00
Julian Bouzas
9b8a876662 m-lua-scripting: add GLib access Lua API 2021-08-10 11:50:51 +03:00
jakobrs
92d99f4a75 dump_table: Sort keys before printing 2021-08-10 07:50:01 +00:00
jakobrs
86bfdbea13 Fix not-equals verb having the wrong number of arguments in Lua API 2021-08-08 20:45:56 +02:00
George Kiagiadakis
9ebea2976d wp: refactor and rename wp_iter_conf_files() to use WpIterator
This also corrects the logic of loading config files in m-lua-scripting.
Previously, if an error occured within the iteration function,
the error was not properly propagated to the caller because -EINVAL
was being added to nfiles instead of checked.
2021-07-20 14:42:42 +03:00
Peter Hutterer
d38c3fb4cc lib: add functions to search in configuration/data directories
The previous approach to loading config files was to ask WP for the
directory and then search those for the config files. This patch changes the
approach - a caller now asks WP to search for a specific config file or
iterate over a config file directory.

This allows us to implement a directory lookup order, i.e.
"wireplumber.conf" may be in XDG_CONFIG_DIR, /etc/,
/usr/share and the first one found is used.

For configuration directories, the new method iterates over all matching
entries (files + directories) and invokes a callback for each entry.

This enables distributions to ship default files in /usr/share/wireplumber
but have admins and users override them on a local basis. For lua scripts in
particular, overriding a distribution-provided file with an empty file
effectively disables it, adding a file adds it in the right sort order.
2021-07-15 15:17:01 +00:00
Peter Hutterer
1132b37f0b modules: fix g_file_test for regular files
From the g_file_test documentation:
"For example, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) will return TRUE if
the file exists; the check whether it's a directory doesn't matter since the
existence test is TRUE. With the current set of available tests, there's no
point passing in more than one test at a time."
2021-07-15 15:17:01 +00:00
George Kiagiadakis
ec397aaaca lua: add not-equals to the possible constraint verbs 2021-07-02 20:24:25 +03:00
Julian Bouzas
dc6fa6cbfe m-lua-scripting: unref value pod after adding it to control 2021-06-30 14:06:48 -04:00
George Kiagiadakis
888d6e5033 lua: add Port.get_direction() + documentation for it 2021-06-30 19:51:21 +03:00
George Kiagiadakis
18fe17fa01 lua: fail if an optional Interest is not none, nil, Interest or table 2021-06-30 19:51:21 +03:00
George Kiagiadakis
795a37d029 lua: complete the WpNode bindings 2021-06-30 19:51:21 +03:00
Julian Bouzas
f0830e5a7d m-lua-scripting: check return values of lua_getstack and lua_getinfo 2021-06-25 08:50:08 -04:00
Julian Bouzas
412fae485a m-lua-scripting: make sure pod is successfully parsed
Otherwise show a warning
2021-06-25 08:50:08 -04:00
Julian Bouzas
671b8110d9 m-lua-scripting: make sure lua type is valid 2021-06-25 08:50:08 -04:00
Julian Bouzas
c423012238 m-lua-scripting: fix conversion from SPA_TYPE_Bytes to LUA_TNUMBER 2021-06-25 08:50:08 -04:00
George Kiagiadakis
2668900e18 lua: improve the object:activate() callback to report errors
There is now a second param to the callback that is an error string,
if any error happened
2021-06-10 14:53:08 +03:00
George Kiagiadakis
892129bd08 lua: implement metadata:set() 2021-06-08 13:40:13 +03:00
George Kiagiadakis
77454243bc lua: fix refcounting of metadata iterator
wplua_push* takes a full ref
2021-06-08 13:40:13 +03:00
George Kiagiadakis
80fad18e3d lua: remove hack around WpObjectInterest since we can _ref() it now 2021-06-07 18:01:49 +03:00
George Kiagiadakis
38f7483793 state: remove support for groups and propagate save errors
There is no real use for groups in our API. Just use the name of
the file as the default group and be done with it...
Storing multiple groups with this API is problematic because it
forces flushing the file to disk multiple times, one for each group,
and it's just more performant if we use a prefix in the keys
to implement some form of logical separation.

This commit also makes the GKeyFile a temporary object. As we
always load the file from the file system in _load()
and we always replace its contents with a new dictionary in _save(),
there is no point in keeping the keyfile's internal data structures
stored in memory.

Save errors are now also propagated to adhere to the programming
practices of GObject
2021-06-04 18:36:19 +03:00
Julian Bouzas
3fbcf05c9b pipewire-object: take ownership of param argument
The wp_pipewire_object_set_param API must take ownership of the param argument
as described by the documentation.
2021-06-03 14:53:00 -04:00
George Kiagiadakis
a604ac4c0c lua: don't crash if an iterator is NULL
simply behave as if the iterator is valid and has no items in it
2021-06-02 19:38:51 +03:00
George Kiagiadakis
9db0e741cd lua: allow the Log api to debug boxed objects (useful for pods) 2021-06-02 19:38:51 +03:00
George Kiagiadakis
132de309cb lua: fix PipewireObject api: s/set_params/set_param/ and cleanup 2021-06-02 19:38:51 +03:00
George Kiagiadakis
53fdc14d5d lua: add WpState bindings 2021-06-02 19:38:51 +03:00
George Kiagiadakis
e567637d37 docs: convert lua api docs to pure rst
Not all the docs are there yet, this is WIP
2021-05-25 14:19:53 +03:00
Raghavendra
80e7b20a73 docs: Add Lua API documentation 2021-05-25 14:19:53 +03:00
George Kiagiadakis
f0d33cb873 endpoint: remove wp_endpoint_create_link()
Not used and not useful with the current design.
May be reverted in the future, if necessary.
2021-05-21 19:57:31 +03:00
George Kiagiadakis
ac9e1e89c4 wp: remove WpSession and WpEndpointLink
We have ended up not using them, so let's not carry them
in the ABI of 0.4

We can always revert that, but let's first decide how
these objects should be used
2021-05-21 19:57:31 +03:00