summaryrefslogtreecommitdiffstats
path: root/player/lua.c
Commit message (Collapse)AuthorAgeFilesLines
* osd: delay libass initialization as far as possiblewm42015-09-071-0/+2
| | | | | | | | | | | | Until now, most OSD objects created the associated ASS_Renderer instance as soon as possible, even if nothing was going to be rendered. Maybe this was even intentional. Change this for the sake of lowering resource usage, and strictly initialize ASS_Renderer only when it's really needed. For the OSC, initialization has to be forced, because of the insane mechanism for translating mouse coordinates to OSD coordinates.
* lua: implement input_enable_section/input_disable_section via commandswm42015-08-061-34/+0
| | | | | | | | | | | | | | | Removes some more internal API calls from the Lua scripting backend. Which is good, because ideally the scripting backend would use libmpv functions only. One awkwardness is that mouse sections are still not supported by the public commands (and probably will never), so flags like allow-hide- cursor make no sense to an outside user. Also, the way flags are passed to the Lua function changes. But that's ok, because they're only undocumented internal functions, and not supposed to be used by script users. osc.lua only does due to historical reasons.
* lua: make mp.input_define_section use the define-section commandwm42015-08-061-21/+0
|
* subprocess, lua: export whether the process was killed by uswm42015-06-271-0/+2
| | | | | | | | We want to distinguish actual errors, and just aborting the program intentionally. Also be a bit more careful with handling the wait() exit status: do not called WEXITSTATUS() without checking WIFEXITED() first.
* lua: support MPV_END_FILE_REASON_REDIRECTwm42015-06-111-0/+1
| | | | And also add the missing "unknown" entry to the manpage.
* lua: export end-file event fieldswm42015-06-111-0/+20
|
* path: make mp_path_join accept normal C stringswm42015-05-091-2/+2
| | | | | Instead of bstr. Most callers of this function do not need bstr. The bstr version of this function is now mp_path_join_bstr().
* lua: remove deprecated "lua" sub directorieswm42015-05-091-10/+4
| | | | | The compatibility code and the deprecation warning were at least in releases 0.8 and 0.9 - time to get rid of them.
* lua: add utils.format_json() functionwm42015-04-221-0/+18
| | | | Requested. Why not.
* client API: add MPV_FORMAT_BYTE_ARRAY typewm42015-04-201-0/+3
| | | | | | | | | | | | This will be used in the following commit, which adds screenshot_raw. The reasoning is that this will be better for binding scripting languages. One could special-case the screenshot_raw commit and define fixed semantics for passing through a pointer using the current API, like formatting a pointer as string. But that would be ridiculous and unclean.
* lua: reject Lua 5.3wm42015-04-011-0/+5
| | | | | | | | | | | | | | It simply doesn't work, and is hard to make work. Lua 5.3 is a different language from 5.1 and 5.2, and is different enough to make adding support a major issue. Most importantly, 5.3 introduced integer types, which completely mess up any code which deals with numbers. I tried to make this a compile time check, but failed. Still at least try to avoid selecting the 5.3 pkg-config package when the generic "lua" name is used (why can't Lua upstream just provide an official .pc file...). Maybe this actually covers all cases. Fixes #1729 (kind of).
* build: make posix_spawn() mandatorywm42015-03-301-4/+0
| | | | | | | It was already accidentally used unconditionally by command.c. Apparently this worked well for us, so don't change anything about, but should it be unavailable, fail at configure time instead of compile time.
* lua: replace getcwd() implementationwm42015-03-241-14/+0
|
* Lua: add mp.get_screen_margins().torque2015-03-011-0/+12
| | | | | | When used with mp.get_screen_size(), mp.get_screen_margins() allows a Lua script to determine what portion of the mpv window actually has the video in it.
* client API: be more lenient about mpv_suspend/resume mismatcheswm42014-12-151-27/+6
| | | | | | | | | | | | Before this commit, this was defined to trigger undefined behavior. This was nice because it required less code; but on the other hand, Lua as well as IPC support had to check these things manually. Do it directly in the API to avoid code duplication, and to make the API more robust. (The total code size still grows, though...) Since all of the failure cases were originally meant to ruin things forever, there is no way to return error codes. So just print the errors.
* lua: cosmetics: fix some include directiveswm42014-12-151-3/+2
| | | | | | Apparently, the atomics were used by the win32 subprocess code. This code was moved to a separate file, but the atomics.h include was forgotten.
* options: deprecate 'lua' based options/dirs for 'script'Avi Halachmi (:avih)2014-12-151-4/+10
| | | | | | | | | | | | - --lua and --lua-opts change to --script and --script-opts - 'lua' default script dirs change to 'scripts' - DOCS updated - 'lua-settings' dir was _not_ modified The old lua-based names/dirs still work, but display a warning. Signed-off-by: wm4 <wm4@nowhere>
* lua: fix broken error messagewm42014-12-021-1/+1
| | | | | luaL_error() doesn't support %.*s, because it uses Lua's own format string mechanism that just looks like the C one. Just drop this part.
* lua, ipc: remove leftoverswm42014-11-241-9/+0
| | | | | | MPV_EVENT_SCRIPT_INPUT_DISPATCH is now unused/deprecated. Also remove a debug-print from defaults.lua.
* lua: subprocess: move to osdep/subprocess-{win,posix}.cJames Ross-Gowan2014-11-221-478/+3
| | | | | | The subprocess code was already split into fairly general functions, separate from the Lua code. It's getting pretty big though, especially the Windows-specific parts, so move it into its own files.
* lua: subprocess: use macros for SetHandleInformationJames Ross-Gowan2014-11-221-1/+2
| | | | | Apparently both parameters refer to the same set of flags (the first is a mask for which flags to set.)
* lua: subprocess: fix handle inheritance race conditionJames Ross-Gowan2014-11-221-11/+87
| | | | | | | | | | | | | | | Normally, when creating a process with inherited handles on Windows, the process inherits all inheritable handles from the parent, including ones that were created on other threads. This can cause a race condition, where unintended handles are copied into the new process, preventing them from being closed correctly while the process is running. The only way to prevent this on Windows XP was to serialise the creation of all inheritable handles, which is clearly unacceptable for libmpv. Windows Vista solves this problem by allowing programs to specify exactly which handles are inherited, so do that on Vista and up. See http://blogs.msdn.com/b/oldnewthing/archive/2011/12/16/10248328.aspx
* lua: subprocess: fix Ctrl+C handling on WindowsJames Ross-Gowan2014-11-221-3/+11
| | | | | | | | | | | | The CREATE_NO_WINDOW flag is used to prevent the subprocess from creating an empty console window when mpv is not running in a console. When mpv is running in a console, it causes the subprocess to detach itself, and prevents it from seeing Ctrl+C events, so it hangs around in the background after mpv is killed. Fix this by only specifying CREATE_NO_WINDOW when mpv is not attached to a console. When it is attached to a console, subprocesses will automatically inherit the console and correctly receive Ctrl+C events.
* lua: subprocess: cancel pending I/O before returnJames Ross-Gowan2014-11-221-2/+7
| | | | | | | I'm not sure if this is necessary, but it can't hurt, and it's what you're supposed to do before leaving the stack frame that contains the OVERLAPPED object and the buffer. If there is no pending I/O, CancelIo will do nothing and GetOverlappedResult will silently fail.
* player: integrate ytdl_hook.luawm42014-11-191-0/+3
|
* lua: subprocess: support cancellation on WindowsJames Ross-Gowan2014-11-181-1/+9
|
* lua: subprocess: use overlapped I/O on WindowsJames Ross-Gowan2014-11-181-56/+133
| | | | | | | Instead of threads, use overlapped (asynchronous) I/O to read from both stdout and stderr. Like in d0643fa, stdout and stderr could be closed at different times, so a sparse_wait function is added to wrap WaitForMultipleObjects and skip NULL handles.
* lua: subprocess: remove minor code duplicationwm42014-11-161-31/+22
| | | | | | | | Now that the code for stderr and stdout does exactly the same things, and the specialization is in the callbacks, this is blatantly duplicated. Also, define a typedef for those callbacks to reduce the verbosity.
* lua: subprocess: add Windows implementationJames Ross-Gowan2014-11-161-46/+257
| | | | Doesn't handle mp_cancel yet.
* lua: subprocess: fix dumbwm42014-10-261-1/+1
|
* lua: subprocess: tunnel stderr through mp_logwm42014-10-261-20/+63
| | | | | | | | | | | Pretty much a fringe-feature, but also it's awkward if something appears on the terminal with no indication for the source. This is made quite awkward by the fact that stderr and stdout could be closed at different times, and that poll() doesn't accept "holes" in its FD list. Invalid (.e.g negative) FDs just make it return immediately, as required by the standard. So sparse_poll() takes care of the messy details.
* lua: parse_json(): fix inverted condition for trail argumentwm42014-10-261-1/+1
| | | | It accidentally had the opposite meaning.
* lua: subprocess: don't distinguish pipe errors/EOFwm42014-10-261-7/+4
| | | | | | | What was the purpose of that? Probably none. Also simplify another thing: if we get the cancel signal through FD, there's no reason to check it separately.
* lua: fix some more lua_tostring() mistakeswm42014-10-251-1/+3
| | | | Why can't it just raise an error?
* lua: lua_tostring() on an error value can return NULLwm42014-10-241-2/+4
| | | | | Lua is so clever it allows values that can't be converted to strings, in which case lua_tostring() returns NULL. Trigger undefined behavior.
* lua: fix non-sensewm42014-10-231-1/+1
| | | | Let's actually test our code next time.
* lua: don't let temporary values take the place of argumentswm42014-10-221-1/+13
| | | | | | | Because Lua is so terrible, it's easy to confuse temporary values pushed to the Lua stack with arguments if the arguments are checked after that. Add a hack that should fix this.
* lua: don't use "output" as identifierwm42014-10-211-4/+4
| | | | | I suspect this clashes with libcs,w hich define "stdout" as macro. Hopefully fixes #1206.
* fix build on OS X and BSDStefano Pigozzi2014-10-191-0/+1
|
* lua: fix lua_objlen -> lua_rawlen for lua 5.2Kevin Mitchell2014-10-181-1/+3
|
* lua: strictly free memory on errorswm42014-10-191-29/+26
| | | | | | | Thanks to the recently introduced mp_lua_PITA(), this is "simple" now. It fixes leaks on Lua errors. The hack to avoid stack overflows manually isn't needed anymore, and the Lua error handler will take care of this.
* lua: expose JSON parserwm42014-10-191-0/+26
| | | | | | | The JSON parser was introduced for the IPC protocol, but I guess it's useful here too. The motivation for this commit is the same as with 8e4fa5fc (again).
* lua: add an utility function for starting processeswm42014-10-191-2/+146
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because 1) Lua is terrible, and 2) popen() is terrible. Unfortunately, since Unix is also terrible, this turned out more complicated than I hoped. As a consequence and to avoid that this code has to be maintained forever, add a disclaimer that any function in Lua's utils module can disappear any time. The complexity seems a bit ridiculous, especially for a feature so far removed from actual video playback, so if it turns out that we don't really need this function, it will be dropped again. The motivation for this commit is the same as with 8e4fa5fc. Note that there is an "#ifndef __GLIBC__". The GNU people are very special people and thought it'd be convenient to actually declare "environ", even though the POSIX people, which are also very special people, state that no header declares this and that the user has to declare this manually. Since the GNU people overtook the Unix world with their very clever "embrace, extend, extinguish" strategy, but not 100%, and trying to build without _GNU_SOURCE is hopeless; but since there might be Unix environments which support _GNU_SOURCE features partially, this means that in practice "environ" will be randomly declared or not declared by system headers. Also, gcc was written by very clever people too, and prints a warning if an external variable is declared twice (I didn't check, but I suppose redeclaring is legal C, and not even the gcc people are clever enough to only warn against a definitely not legal C construct, although sometimes they do this), ...and since we at mpv hate compiler warnings, we seek to silence them all. Adding a configure test just for a warning seems too radical, so we special-case this against __GLIBC__, which is hopefully not defined on other libcs, especially not libcs which don't implement all aspects of _GNU_SOURCE, and redefine "environ" on systems even if the headers define it already (because they support _GNU_SOURCE - as I mentioned before, the clever GNU people wrote software THAT portable that other libcs just gave up and implemented parts of _GNU_SOURCE, although probably not all), which means that compiling mpv will print a warning about "environ" being redefined, but at least this won't happen on my system, so all is fine. However, should someone complain about this warning, I will force whoever complained about this warning to read this ENTIRE commit message, and if possible, will also force them to eat a printed-out copy of the GNU Manifesto, and if that is not enough, maybe this person could even be forced to convince the very clever POSIX people of not doing crap like this: having the user to manually declare somewhat central symbols - but I doubt it's possible, because the POSIX people are too far gone and only care about maintaining compatibility with old versions of AIX and HP-UX. Oh, also, this code contains some subtle and obvious issues, but writing about this is not fun.
* lua: add a helper to auto-free temporary C memorywm42014-10-191-6/+32
| | | | | | | | | | | | | | | | | Using the Lua API is a big PITA because it uses longjmp() error handling. That is, a Lua API function could any time raise an error and longjmp() to a lower part of the stack. This kind of "exception handling" is completely foreign to C, and there are no proper ways to clean up the "skipped" stack frames. Other than avoiding such situations entirely, the only way to deal with this is using Lua "userdata", which is basically a malloc'ed data block managed by the Lua GC, and which can have a destructor function associated (__gc metamethod). This requires an awful lot of code (because the Lua API is just so terrible), so I avoided this utnil now. But it looks like this will make some of the following commits much easier, so here we go.
* win32: get rid of mp_stat in the normal source codewm42014-10-171-1/+1
| | | | | | | | | | | mp_stat() instead of stat() was used in the normal code (i.e. even on Unix), because MinGW-w64 has an unbelievable macro-mess in place, which prevents solving this elegantly. Add some dirty workarounds to hide mp_stat() from the normal code properly. This now requires replacing all functions that use the struct stat type. This includes fstat, lstat, fstatat, and possibly others. (mpv currently uses stat and fstat only.)
* lua: add command_native() functionwm42014-10-111-0/+23
| | | | This is the Lua equivalent of mpv_command_node().
* lua: add mpv/lua directories to the lua pathOtto Modinos2014-09-281-0/+25
| | | | Signed-off-by: wm4 <wm4@nowhere>
* sanitizer: avoid divide-by-zero instancesBen Boeckel2014-09-141-5/+5
| | | | | | | | Merges pull request #1094, with some minor changes. mpv expects IEEE, and IEEE allows divisions by 0 for floats, so these shouldn't actually be a problem, but do it anyway for the sake of clang. Signed-off-by: wm4 <wm4@nowhere>
* lua: expose mp_getcwd through mp.utilsOtto Modinos2014-08-311-0/+14
|
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-291-1/+1
| | | | | | | | | bstr.c doesn't really deserve its own directory, and compat had just a few files, most of which may as well be in osdep. There isn't really any justification for these extra directories, so get rid of them. The compat/libav.h was empty - just delete it. We changed our approach to API compatibility, and will likely not need it anymore.
* lua: wake up the core when setting OSDwm42014-08-151-0/+1
| | | | | | | | | | The OSD is marked as changed, but the core isn't notified and this doesn't immediately wakeup. (Possibly the OSD code should wakeup the core instead, but maybe that woudl be overkill.) Observed when using "mp.use_suspend = false" in the OSC, and pausing, and moving the mouse pointer out of the window. The last part of the fade remained visible for longer than intended.
* command: add a property that returns a list of all propertieswm42014-08-021-13/+0
| | | | Also remove the undocumented Lua mp.property_list() function.
* build: include <strings.h> for strcasecmp()wm42014-07-101-0/+1
| | | | | | | It happens to work without strings.h on glibc or with _GNU_SOURCE, but the POSIX standard requires including <strings.h>. Hopefully fixes OSX build.
* lua: redo error handling, print backtraceswm42014-07-071-82/+90
| | | | | | | | | | | | | | | | | | | | The original goal was just adding backtraces, however making the code safe (especially wrt. to out of memory Lua errors) was hard. So this commit also restructures error handling to make it conceptually simpler. Now all Lua code is run inside a Lua error handling, except the calls for creating and destroying the Lua context, and calling the wrapper C function in a safe way. The new error handling is actually conceptually simpler and more correct, because you can just call any Lua function at initialization, without having to worry whwther it throws errors or not. Unfortunately, Lua 5.2 removes lua_cpcall(), so we have to emulate it. There isn't any way to emulate it in a way that works the same on 5.1 and 5.2 with the same semantics in error cases, so ifdeffery is needed. The debug.traceback() function also behaves weirdly differently between the Lua versions, so its output is not as nice as it could be (empty extra line).
* Basic xdg directory implementationKenneth Zhou2014-06-261-1/+1
| | | | | | | | | | Search $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS for config files. This also negates the need to have separate user and global variants of mp_find_config_file() Closes #864, #109. Signed-off-by: wm4 <wm4@nowhere>
* command: redo the property typewm42014-06-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Instead of absuing m_option to store the property list, introduce a separate type for properties. m_option is still used to handle data types. The property declaration itself now never contains the option type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This was already done with some properties, now all properties use it.) This also fixes that the function signatures did not match the function type with which these functions were called. They were called as: int (*)(const m_option_t*, int, void*, void*) but the actual function signatures were: int (*)(m_option_t*, int, void*, MPContext *) Two arguments were mismatched. This adds one line per property implementation. With additional the reordering of the parameters, this makes most of the changes in this commit.
* Add more constwm42014-06-111-2/+2
| | | | | | | While I'm not very fond of "const", it's important for declarations (it decides whether a symbol is emitted in a read-only or read/write section). Fix all these cases, so we have writeable global data only when we really need.
* lua: slightly nicer diagnostics outputwm42014-05-271-1/+3
| | | | | | | | | | | | | When Lua itself prints errors such as: Error: [string "mp.defaults"]:387: syntax error near 'function' It's unclear why the location is prefixed with "string ". And for some reason, it disappears if you prefix the name with '@'. I suppose this is done for the sake of luaL_loadstring. With the '@' prefix added, the output is now: Error: mp.defaults:387: syntax error near 'function'
* lua: add missing include fileswm42014-05-261-0/+2
| | | | | | These are actually already included in osdep/io.h, but I think it's cleaner to repeat them in the file where they are actually needed. (osdep/io.h needs to have them for other reasons.)
* lua: fix compilation with lua 5.2wm42014-05-261-8/+42
| | | | | | | | | | | Commit e2e450f9 started making use of luaL_register(), but OF COURSE this function disappeared in Lua 5.2, and was replaced with a 5.2-only alternative, slightly different mechanism. So just NIH our