mirror of https://github.com/mpv-player/mpv
js: utils.getenv(): fix crash on undefined var
This commit is contained in:
parent
0922678fc4
commit
fa857ac7bc
|
@ -196,7 +196,8 @@ Additional utilities
|
|||
Like ``print`` but also expands objects and arrays recursively.
|
||||
|
||||
``mp.utils.getenv(name)``
|
||||
Returns the value of the host environment variable ``name``, or empty str.
|
||||
Returns the value of the host environment variable ``name``, or
|
||||
``undefined`` if the variable is not defined.
|
||||
|
||||
``mp.utils.get_user_path(path)``
|
||||
Expands (mpv) meta paths like ``~/x``, ``~~/y``, ``~~desktop/z`` etc.
|
||||
|
|
|
@ -981,7 +981,12 @@ static void script_write_file(js_State *J, void *af)
|
|||
// args: env var name
|
||||
static void script_getenv(js_State *J)
|
||||
{
|
||||
js_pushstring(J, getenv(js_tostring(J, 1)));
|
||||
const char *v = getenv(js_tostring(J, 1));
|
||||
if (v) {
|
||||
js_pushstring(J, v);
|
||||
} else {
|
||||
js_pushundefined(J);
|
||||
}
|
||||
}
|
||||
|
||||
// args: as-filename, content-string, returns the compiled result as a function
|
||||
|
|
Loading…
Reference in New Issue