]> git.sesse.net Git - vlc/blob - modules/misc/lua/vlc.h
e6e13d2ca82be2aabf313413ec67084cb49c2f69
[vlc] / modules / misc / lua / vlc.h
1 /*****************************************************************************
2  * vlc.h: VLC specific lua library functions.
3  *****************************************************************************
4  * Copyright (C) 2007-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *          Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VLC_LUA_H
26 #define VLC_LUA_H
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33 #include <vlc_playlist.h>
34 #include <vlc_meta.h>
35 #include <vlc_url.h>
36 #include <vlc_strings.h>
37 #include <vlc_stream.h>
38
39 #include <lua.h>        /* Low level lua C API */
40 #include <lauxlib.h>    /* Higher level C API */
41 #include <lualib.h>     /* Lua libs */
42
43 /*****************************************************************************
44  * Module entry points
45  *****************************************************************************/
46 int ReadMeta( vlc_object_t * );
47 int FetchMeta( vlc_object_t * );
48 int FindArt( vlc_object_t * );
49
50 int Import_LuaPlaylist( vlc_object_t * );
51 void Close_LuaPlaylist( vlc_object_t * );
52
53 int Open_LuaIntf( vlc_object_t * );
54 void Close_LuaIntf( vlc_object_t * );
55
56 int Open_Extension( vlc_object_t * );
57 void Close_Extension( vlc_object_t * );
58
59 int Open_LuaSD( vlc_object_t * );
60 void Close_LuaSD( vlc_object_t * );
61
62 /*****************************************************************************
63  * Lua debug
64  *****************************************************************************/
65 static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
66 {
67     va_list ap;
68     va_start( ap, ppz_fmt );
69     msg_GenericVa( p_this, VLC_MSG_DBG, MODULE_STRING, ppz_fmt, ap );
70     va_end( ap );
71 }
72
73 /*****************************************************************************
74  * Functions that should be in lua ... but aren't for some obscure reason
75  *****************************************************************************/
76 static inline int luaL_checkboolean( lua_State *L, int narg )
77 {
78     luaL_checktype( L, narg, LUA_TBOOLEAN ); /* can raise an error */
79     return lua_toboolean( L, narg );
80 }
81
82 static inline int luaL_optboolean( lua_State *L, int narg, int def )
83 {
84     return luaL_opt( L, luaL_checkboolean, narg, def );
85 }
86
87 static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
88 {
89     if( lua_isnil( L, narg ) )
90         return NULL;
91     return luaL_checkstring( L, narg );
92 }
93
94 vlc_object_t * vlclua_get_this( lua_State * );
95
96 /*****************************************************************************
97  * Lua function bridge
98  *****************************************************************************/
99 #define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
100 int vlclua_push_ret( lua_State *, int i_error );
101
102 /*****************************************************************************
103  * Will execute func on all scripts in luadirname, and stop if func returns
104  * success.
105  *****************************************************************************/
106 int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
107         int (*func)(vlc_object_t *, const char *, void *),
108         void * user_data );
109 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char ***pppsz_dir_list );
110 void vlclua_dir_list_free( char **ppsz_dir_list );
111 char *vlclua_find_file( vlc_object_t *p_this, const char *psz_luadirname, const char *psz_name );
112
113 /*****************************************************************************
114  * Playlist and meta data internal utilities.
115  *****************************************************************************/
116 void __vlclua_read_options( vlc_object_t *, lua_State *, int *, char *** );
117 #define vlclua_read_options(a,b,c,d) __vlclua_read_options(VLC_OBJECT(a),b,c,d)
118 void __vlclua_read_meta_data( vlc_object_t *, lua_State *, input_item_t * );
119 #define vlclua_read_meta_data(a,b,c) __vlclua_read_meta_data(VLC_OBJECT(a),b,c)
120 void __vlclua_read_custom_meta_data( vlc_object_t *, lua_State *,
121                                      input_item_t *);
122 #define vlclua_read_custom_meta_data(a,b,c) __vlclua_read_custom_meta_data(VLC_OBJECT(a),b,c)
123 int __vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
124                                     input_item_t *, bool );
125 #define vlclua_playlist_add_internal(a,b,c,d,e) __vlclua_playlist_add_internal(VLC_OBJECT(a),b,c,d,e)
126
127 int __vlclua_add_modules_path( vlc_object_t *, lua_State *, const char *psz_filename );
128 #define vlclua_add_modules_path( a, b, c ) __vlclua_add_modules_path(VLC_OBJECT(a), b, c)
129
130 /**
131  * Per-interface private state
132  */
133 struct intf_sys_t
134 {
135     char *psz_filename;
136     lua_State *L;
137
138     vlc_thread_t thread;
139     vlc_mutex_t lock;
140     vlc_cond_t wait;
141     bool exiting;
142 };
143
144 #endif /* VLC_LUA_H */
145