aboutsummaryrefslogtreecommitdiffhomepage
path: root/player/lua.c
Commit message (Collapse)AuthorAge
...
* lua: subprocess: fix dumbGravatar wm42014-10-26
|
* lua: subprocess: tunnel stderr through mp_logGravatar wm42014-10-26
| | | | | | | | | | | 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 argumentGravatar wm42014-10-26
| | | | It accidentally had the opposite meaning.
* lua: subprocess: don't distinguish pipe errors/EOFGravatar wm42014-10-26
| | | | | | | 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() mistakesGravatar wm42014-10-25
| | | | Why can't it just raise an error?
* lua: lua_tostring() on an error value can return NULLGravatar wm42014-10-24
| | | | | 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-senseGravatar wm42014-10-23
| | | | Let's actually test our code next time.
* lua: don't let temporary values take the place of argumentsGravatar wm42014-10-22
| | | | | | | 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 identifierGravatar wm42014-10-21
| | | | | I suspect this clashes with libcs,w hich define "stdout" as macro. Hopefully fixes #1206.
* fix build on OS X and BSDGravatar Stefano Pigozzi2014-10-19
|
* lua: fix lua_objlen -> lua_rawlen for lua 5.2Gravatar Kevin Mitchell2014-10-18
|
* lua: strictly free memory on errorsGravatar wm42014-10-19
| | | | | | | 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 parserGravatar wm42014-10-19
| | | | | | | 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 processesGravatar wm42014-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 memoryGravatar wm42014-10-19
| | | | | | | | | | | | | | | | | 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 codeGravatar wm42014-10-17
| | | | | | | | | | | 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() functionGravatar wm42014-10-11
| | | | This is the Lua equivalent of mpv_command_node().
* lua: add mpv/lua directories to the lua pathGravatar Otto Modinos2014-09-28
| | | | Signed-off-by: wm4 <wm4@nowhere>
* sanitizer: avoid divide-by-zero instancesGravatar Ben Boeckel2014-09-14
| | | | | | | | 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.utilsGravatar Otto Modinos2014-08-31
|
* Move compat/ and bstr/ directory contents somewhere elseGravatar wm42014-08-29
| | | | | | | | | 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 OSDGravatar wm42014-08-15
| | | | | | | | | | 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 propertiesGravatar wm42014-08-02
| | | | Also remove the undocumented Lua mp.property_list() function.
* build: include <strings.h> for strcasecmp()Gravatar wm42014-07-10
| | | | | | | 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 backtracesGravatar wm42014-07-07
| | | | | | | | | | | | | | | | | | | | 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 implementationGravatar Kenneth Zhou2014-06-26
| | | | | | | | | | 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 typeGravatar wm42014-06-13
| | | | | | | | | | | | | | | | | | | | | | | 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 constGravatar wm42014-06-11
| | | | | | | 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 outputGravatar wm42014-05-27
| | | | | | | | | | | | | 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 filesGravatar wm42014-05-26
| | | | | | 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.2Gravatar wm42014-05-26
| | | | | | | | | | | 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 own function. This is actually slightly more correct, since it forces the user to call "require" to actually make the module visible for builtin C-only modules other than "mp". Fix autoload.lua accordingly.
* lua: add some filesystem utility functionsGravatar wm42014-05-25
| | | | | | | | | | | We need this only because Lua's stdlib is so scarce. Lua doesn't intend to include a complete stdlib - they confine themselves to standard C, both for portability reasons and to keep the code minimal. But standard C does not provide much either. It would be possible to use Lua POSIX wrapper libraries, but that would be a messy (and unobvious) dependency. It's better to implement the missing functions ourselves, as long as they're small in number.
* lua/osc: forgot some changed files in previous commitGravatar ChrisK22014-05-23
|
* player: reorganize how lua scripts are loadedGravatar wm42014-05-13
| | | | | | Make loading of scripts independent of Lua. Move some of the loading code from lua.c to scripting.c, and make it easier to add new scripting backends.
* lua: remove "lua/" prefix from script namesGravatar wm42014-05-02
| | | | | | | | | This affects the return value of mp.script_name, the "client name" (what's returned by mpv_client_name()) and all associated features, as well as the mpv terminal output module prefix when scripts print something. As discussed in #748.
* lua: fix stack going out of syncGravatar wm42014-04-24
| | | | This broke with recursive tables.
* client API: remove mpv_event_pause_reasonGravatar wm42014-04-14
| | | | | | | | | And slightly adjust the semantics of MPV_EVENT_PAUSE/MPV_EVENT_UNPAUSE. The real pause state can now be queried with the "core-idle" property, the user pause state with the "pause" property, whether the player is paused due to cache with "paused-for-cache", and the keep open event can be guessed with the "eof-reached" property.
* lua: wrap mpv_get_wakeup_pipe()Gravatar wm42014-04-12
| | | | Pretty much experimental for issue #661.
* lua: add API for observing property changesGravatar wm42014-04-08
| | | | | A low level API was added already earlier, but that was merely a binding for the raw C API. Add a "proper" one, and document it.
* lua: add basic mpv_observe_property supportGravatar wm42014-04-06
| | | | Undocumented and only the most basic functionality for now.
* lua: add license headerGravatar wm42014-03-07
| | | | Oops.
* lua: set a proper chunk name for builtin modulesGravatar wm42014-03-01
| | | | | | | | luaL_loadstring(), which was used until now, uses the start of the Lua code itself as chunk name. Since the chunk name shows up even with runtime errors triggered by e.g. Lua code loaded from user scripts, this looks a but ugly. Switch to luaL_loadbuffer(), which is almost the same as luaL_loadstring(), but allows setting a chunk name.
* lua: fix format string in luaL_error()Gravatar wm42014-03-01
|
* lua: add option to disable auto-loading of lua scriptsGravatar wm42014-02-28
|
* lua: add set_property_native functionGravatar wm42014-02-26
| | | | | | Probably completely useless, at least for now. Also not very well tested, but initial test seems successful.
* lua: mark table values returned by get_property_native with their typeGravatar wm42014-02-26
| | | | | | | Lua doesn't distinguish between arrays and maps on the language level; there are just tables. Use metatables to mark these tables with their actual types. In particular, it allows distinguishing empty arrays from empty tables.
* lua: implement mp.get_opt() in LuaGravatar wm42014-02-26
| | | | | | Will be more expensive if used very often, but it's probably ok. Reduce the dependency of lua.c on MPContext a bit further.
* osd: override user bindings for OSC inputGravatar wm42014-02-26
| | | | | | | | | E.g. binding MOUSE_BTN0 always used the user defined binding. While it is ok that the user can override mouse_move and mouse_leave (for whatever reasons), we want to strictly override the bindings when input is sent to the OSC itself. Regression since 03624a1.
* client API: report pause/unpause reasonGravatar wm42014-02-24
| | | | | | | | | Not sure about this... might redo. At least this provides a case of a broadcasted event, which requires per-event data allocation. See github issue #576.
* client API: expose the internal clockGravatar wm42014-02-24
| | | | | | | | | May or may not be useful in some ways. We require a context parameter for this just to be sure, even if the internal implementation currently doesn't. That's one less mpv internal function for the Lua wrapper.