qml: Create MediaGroupDisplay
[vlc.git] / modules / lua / vlc.h
blobe6dea213d11cfcd5c9d8ad6a8f2cc91be903d5ef
1 /*****************************************************************************
2 * vlc.h: VLC specific lua library functions.
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
6 * Authors: Antoine Cellerier <dionoea at videolan tod org>
7 * Pierre d'Herbemont <pdherbemont # videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_LUA_H
25 #define VLC_LUA_H
26 /*****************************************************************************
27 * Preamble
28 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_input.h>
32 #include <vlc_playlist.h>
33 #include <vlc_meta.h>
34 #include <vlc_meta_fetcher.h>
35 #include <vlc_url.h>
36 #include <vlc_strings.h>
37 #include <vlc_stream.h>
38 #include <vlc_demux.h>
40 #define LUA_COMPAT_MODULE
41 #include <lua.h> /* Low level lua C API */
42 #include <lauxlib.h> /* Higher level C API */
43 #include <lualib.h> /* Lua libs */
45 #if LUA_VERSION_NUM >= 502
46 # define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
47 # define lua_objlen(L,idx) lua_rawlen(L,idx)
48 # define lua_strlen(L,idx) lua_rawlen(L,idx)
49 #endif
51 #if LUA_VERSION_NUM >= 502
52 # undef luaL_register
53 # define luaL_register(L, n, l) luaL_setfuncs(L, (l), 0)
54 # define luaL_register_namespace(L, n, l) \
55 lua_getglobal( L, n ); \
56 if( lua_isnil( L, -1 ) ) \
57 { \
58 lua_pop( L, 1 ); \
59 lua_newtable( L ); \
60 } \
61 luaL_setfuncs( L, (l), 0 ); \
62 lua_pushvalue( L, -1 ); \
63 lua_setglobal( L, n );
64 #else
65 # define luaL_register_namespace(L, n, l) luaL_register( L, n, (l) );
66 #endif
69 /*****************************************************************************
70 * Module entry points
71 *****************************************************************************/
72 int ReadMeta( demux_meta_t * );
73 int FetchMeta( meta_fetcher_t * );
74 int FindArt( meta_fetcher_t * );
76 int Import_LuaPlaylist( vlc_object_t * );
77 void Close_LuaPlaylist( vlc_object_t * );
79 #define TELNETPORT_DEFAULT 4212
80 int Open_LuaIntf( vlc_object_t * );
81 void Close_LuaIntf( vlc_object_t * );
82 int Open_LuaHTTP( vlc_object_t * );
83 int Open_LuaCLI( vlc_object_t * );
84 int Open_LuaTelnet( vlc_object_t * );
87 int Open_Extension( vlc_object_t * );
88 void Close_Extension( vlc_object_t * );
90 int Open_LuaSD( vlc_object_t * );
91 void Close_LuaSD( vlc_object_t * );
93 // Script probe
94 int vlclua_probe_sd( vlc_object_t *, const char *name );
96 /*****************************************************************************
97 * Lua debug
98 *****************************************************************************/
99 static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
101 va_list ap;
102 va_start( ap, ppz_fmt );
103 msg_GenericVa( p_this, VLC_MSG_DBG, ppz_fmt, ap );
104 va_end( ap );
107 static inline bool lua_Disabled( vlc_object_t *p_this )
109 return !var_InheritBool( p_this, "lua" );
111 #define lua_Disabled( x ) lua_Disabled( VLC_OBJECT( x ) )
113 /*****************************************************************************
114 * Functions that should be in lua ... but aren't for some obscure reason
115 *****************************************************************************/
116 static inline bool luaL_checkboolean( lua_State *L, int narg )
118 luaL_checktype( L, narg, LUA_TBOOLEAN ); /* can raise an error */
119 return lua_toboolean( L, narg );
122 static inline int luaL_optboolean( lua_State *L, int narg, int def )
124 return luaL_opt( L, luaL_checkboolean, narg, def );
127 static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
129 if( lua_isnil( L, narg ) )
130 return NULL;
131 return luaL_checkstring( L, narg );
134 static inline char *luaL_strdupornull( lua_State *L, int narg )
136 if( lua_isstring( L, narg ) )
137 return strdup( luaL_checkstring( L, narg ) );
138 return NULL;
141 void vlclua_set_this( lua_State *, vlc_object_t * );
142 #define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
143 vlc_object_t * vlclua_get_this( lua_State * );
145 void vlclua_set_playlist_internal( lua_State *, vlc_playlist_t * );
146 vlc_playlist_t * vlclua_get_playlist_internal( lua_State * );
148 /*****************************************************************************
149 * Lua function bridge
150 *****************************************************************************/
151 #define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
152 int vlclua_push_ret( lua_State *, int i_error );
154 /*****************************************************************************
155 * Will execute func on all scripts in luadirname, and stop if func returns
156 * success.
157 *****************************************************************************/
158 typedef struct luabatch_context_t luabatch_context_t;
159 struct luabatch_context_t
161 input_item_t *p_item;
162 meta_fetcher_scope_t e_scope;
163 bool (*pf_validator)( const luabatch_context_t *, meta_fetcher_scope_t );
166 int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
167 int (*func)(vlc_object_t *, const char *, const luabatch_context_t *),
168 void * user_data );
169 int vlclua_dir_list( const char *luadirname, char ***pppsz_dir_list );
170 void vlclua_dir_list_free( char **ppsz_dir_list );
171 char *vlclua_find_file( const char *psz_luadirname, const char *psz_name );
173 /*****************************************************************************
174 * Replace Lua file reader by VLC input. Allows loadings scripts in Zip pkg.
175 *****************************************************************************/
176 int vlclua_dofile( vlc_object_t *p_this, lua_State *L, const char *url );
178 /*****************************************************************************
179 * Playlist and meta data internal utilities.
180 *****************************************************************************/
181 void vlclua_read_options( vlc_object_t *, lua_State *, int *, char *** );
182 #define vlclua_read_options( a, b, c, d ) vlclua_read_options( VLC_OBJECT( a ), b, c, d )
183 void vlclua_read_meta_data( vlc_object_t *, lua_State *, input_item_t * );
184 #define vlclua_read_meta_data( a, b, c ) vlclua_read_meta_data( VLC_OBJECT( a ), b, c )
185 void vlclua_read_custom_meta_data( vlc_object_t *, lua_State *,
186 input_item_t *);
187 #define vlclua_read_custom_meta_data( a, b, c ) vlclua_read_custom_meta_data( VLC_OBJECT( a ), b, c )
189 input_item_t *vlclua_read_input_item(vlc_object_t *, lua_State *);
191 int vlclua_add_modules_path( lua_State *, const char *psz_filename );
193 struct vlc_interrupt;
196 * File descriptors table
198 typedef struct
200 struct vlc_interrupt *interrupt;
201 int *fdv;
202 unsigned fdc;
203 } vlclua_dtable_t;
205 int vlclua_fd_init( lua_State *, vlclua_dtable_t * );
206 void vlclua_fd_interrupt( vlclua_dtable_t * );
207 void vlclua_fd_cleanup( vlclua_dtable_t * );
208 struct vlc_interrupt *vlclua_set_interrupt( lua_State *L );
210 #endif /* VLC_LUA_H */