summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-07-17 01:36:33 +0200
committerwm4 <wm4@nowhere>2020-07-20 21:02:17 +0200
commit0e7f53a5bc76cc3f042791b5f8923563842224a3 (patch)
tree45f9991c00a80151ea881b01434e04f21d4ae0c1 /player
parent0279a44d93a378fbdff393d6568a691817f83518 (diff)
downloadmpv-0e7f53a5bc76cc3f042791b5f8923563842224a3.tar.bz2
mpv-0e7f53a5bc76cc3f042791b5f8923563842224a3.tar.xz
lua: add mp.get_env_list() function
Because Lua is too stupid to provide this directly, and I sort of need it.
Diffstat (limited to 'player')
-rw-r--r--player/lua.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c
index b37a6cd84f..668552741c 100644
--- a/player/lua.c
+++ b/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}
};