0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00
Commit Graph

16 Commits

Author SHA1 Message Date
Avi Halachmi (:avih)
5e0875c9e0 js: use osd-dimentions for mp.get_osd_{size,margins}
This matches lua's 11b9315b but with the lagacy field names which the
js code used previously.

Currently the property always returns an object (with dummy/last/null
field values if there are no dimensions), but the code is ready for
a future case where it might return null if there are no dimensions - at
which case it will forward the null, breaking backward compatibility for
a better API.
2020-01-08 11:49:49 +02:00
Avi Halachmi (:avih)
9f2fda7d85 js: support mp.create_osd_overlay (match 07287262)
The legacy mp.set_osd_ass(...) is still supported (but also still
undocumented) as a wrapper for the new mp.create_osd_overlay(...).
2019-12-23 17:52:34 +02:00
wm4
0728726251 client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.

The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".

There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.

Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.

The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 11:44:24 +01:00
Avi Halachmi (:avih)
eb033bc29f js: don't pre-filter log level argument in mp.enable_messages()
Match lua's 8e5642ff
2019-11-19 18:13:39 +02:00
Avi Halachmi (:avih)
44f8dccfb6 js: expose mpv_abort_async_command() (match dbe831bd)
With minor difference from lua, as documented.
2019-09-11 21:08:04 +03:00
Avi Halachmi (:avih)
ad0a525f20 js: reimplement subprocess_detached using the run command (match 7f91e268) 2019-09-11 21:08:04 +03:00
Avi Halachmi (:avih)
fea39b5a6b js: reimplement subprocess using the subprocess command (match 548ef078)
Semantics changes are the same as at 548ef078 .

Also, the previous C implementation returnd a string for the `stdout`
value, but stdout of the subprocess command is MPV_FORMAT_BYTE_ARRAY
which js previously didn't support, so support it too (at pushnode)
by returning it as a string - the same as the lua code does.
2019-09-11 21:08:04 +03:00
Avi Halachmi (:avih)
5b5f776900 js: expose async commands (match 159379980e) 2019-09-11 21:08:04 +03:00
Avi Halachmi (:avih)
fc56798aca js: correctness: use integer range checks
There were some cases where a js number (double) was blindly casted to
int or uint64, but that can be undefined behavior (out of range to int)
or wrong (negative to uint).

Now the code throws a js error if the value is out of range.

Additionally, commit ec625266 added these checks for the new hooks API,
but incorrectly tested int64 range rather than uint64. Fix this too.
2019-09-11 21:08:04 +03:00
Avi Halachmi (:avih)
ec625266c8
js: use new hooks API (match f60826c3) 2018-04-07 16:02:20 -07:00
sfan5
8f9785d128 lua+js: Implement utils.getpid()
Usable for uniquely identifying mpv instances from
subprocesses, controlling mpv with AppleScript, ...

Adds a new mp_getpid() wrapper for cross-platform reasons.
2018-02-13 20:16:01 -08:00
TSaaristo
522bfe5be1 lua+js: implement utils.file_info()
This commit introduces mp.utils.file_info() for querying information
on file paths, implemented for both Lua and Javascript.

The function takes a file path as an argument and returns a Lua table /
JS object upon success. The table/object will contain the values:
mode, size, atime, mtime, ctime and the convenience booleans is_file, is_dir.

On error, the Lua side will return `nil, error` and the Javascript side
will return `undefined` (and mark the last error).

This feature utilizes the already existing cross-platform `mp_stat()`
function.
2017-12-13 21:55:28 +02:00
Avi Halachmi (:avih)
2dd2acac89 js: fix broken mp.set_property_number, mp.set_property_native
Also implicitly fixes memory leak when mp.set_property_native was used,
because the cleanup did not expect more allocations from the accidental
use of mpv_get_property.
2017-09-23 14:41:17 +03:00
Avi Halachmi (:avih)
fa857ac7bc js: utils.getenv(): fix crash on undefined var 2017-07-06 18:11:24 +03:00
wm4
aa690e3997 javascript: replace custom MIN macro with MPMIN 2017-06-17 14:28:42 +02:00
Avi Halachmi (:avih)
d223a63bc5 js: add javascript scripting support using MuJS
Implements JS with almost identical API to the Lua support.

Key differences from Lua:
- The global mp, mp.msg and mp.utils are always available.
- Instead of returning x, error, return x and expose mp.last_error().
- Timers are JS standard set/clear Timeout/Interval.
- Supports CommonJS modules/require.
- Added at mp.utils: getenv, read_file, write_file and few more.
- Global print and dump (expand objects) functions.
- mp.options currently not supported.

See DOCS/man/javascript.rst for more details.
2017-06-14 12:29:32 +02:00