mirror of https://github.com/mpv-player/mpv
lua: add mp.get_env_list() function
Because Lua is too stupid to provide this directly, and I sort of need it.
This commit is contained in:
parent
0279a44d93
commit
0e7f53a5bc
|
@ -539,6 +539,9 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
|
|||
useless.) The format of the list is as in the ``execle()`` syscall. Each
|
||||
string item defines an environment variable as in ``NANME=VALUE``.
|
||||
|
||||
On Lua, you may use ``utils.get_env_list()`` to retrieve the current
|
||||
environment if you e.g. simply want to add a new variable.
|
||||
|
||||
The command returns the following result (as ``MPV_FORMAT_NODE_MAP``):
|
||||
|
||||
``status`` (``MPV_FORMAT_INT64``)
|
||||
|
|
|
@ -826,6 +826,10 @@ strictly part of the guaranteed API.
|
|||
Returns the process ID of the running mpv process. This can be used to identify
|
||||
the calling mpv when launching (detached) subprocesses.
|
||||
|
||||
``utils.get_env_list()``
|
||||
Returns the C environment as a list of strings. (Do not confuse this with
|
||||
the Lua "environment", which is an unrelated concept.)
|
||||
|
||||
``utils.parse_json(str [, trail])``
|
||||
Parses the given string argument as JSON, and returns it as a Lua table. On
|
||||
error, returns ``nil, error``. (Currently, ``error`` is just a string
|
||||
|
|
13
player/lua.c
13
player/lua.c
|
@ -53,6 +53,8 @@
|
|||
#include "client.h"
|
||||
#include "libmpv/client.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
// List of builtin modules and their contents as strings.
|
||||
// All these are generated from player/lua/*.lua
|
||||
static const char * const builtin_lua_scripts[][2] = {
|
||||
|
@ -1185,6 +1187,16 @@ static int script_format_json(lua_State *L, void *tmp)
|
|||
return 2;
|
||||
}
|
||||
|
||||
static int script_get_env_list(lua_State *L)
|
||||
{
|
||||
lua_newtable(L); // table
|
||||
for (int n = 0; environ && environ[n]; n++) {
|
||||
lua_pushstring(L, environ[n]); // table str
|
||||
lua_rawseti(L, -2, n + 1); // table
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define FN_ENTRY(name) {#name, script_ ## name, 0}
|
||||
#define AF_ENTRY(name) {#name, 0, script_ ## name}
|
||||
struct fn_entry {
|
||||
|
@ -1226,6 +1238,7 @@ static const struct fn_entry main_fns[] = {
|
|||
FN_ENTRY(get_wakeup_pipe),
|
||||
FN_ENTRY(raw_hook_add),
|
||||
FN_ENTRY(raw_hook_continue),
|
||||
FN_ENTRY(get_env_list),
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue