1 /*****************************************************************************
2 * vlc.h: VLC specific lua library functions.
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
8 * Pierre d'Herbemont <pdherbemont # videolan.org>
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.
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.
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 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33 #include <vlc_playlist.h>
35 #include <vlc_meta_fetcher.h>
37 #include <vlc_strings.h>
38 #include <vlc_stream.h>
39 #include <vlc_demux.h>
41 #define LUA_COMPAT_MODULE
42 #include <lua.h> /* Low level lua C API */
43 #include <lauxlib.h> /* Higher level C API */
44 #include <lualib.h> /* Lua libs */
46 #if LUA_VERSION_NUM >= 502
47 # define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
48 # define lua_objlen(L,idx) lua_rawlen(L,idx)
49 # define lua_strlen(L,idx) lua_rawlen(L,idx)
52 #if LUA_VERSION_NUM >= 503
54 # define luaL_register(L, n, l) luaL_setfuncs(L, (l), 0)
55 # define luaL_register_namespace(L, n, l) \
56 lua_getglobal( L, n ); \
57 if( lua_isnil( L, -1 ) ) \
62 luaL_setfuncs( L, (l), 0 ); \
63 lua_pushvalue( L, -1 ); \
64 lua_setglobal( L, n );
66 # define luaL_register_namespace(L, n, l) luaL_register( L, n, (l) );
70 /*****************************************************************************
72 *****************************************************************************/
73 int ReadMeta( demux_meta_t
* );
74 int FetchMeta( meta_fetcher_t
* );
75 int FindArt( meta_fetcher_t
* );
77 int Import_LuaPlaylist( vlc_object_t
* );
78 void Close_LuaPlaylist( vlc_object_t
* );
80 #define TELNETPORT_DEFAULT 4212
81 int Open_LuaIntf( vlc_object_t
* );
82 void Close_LuaIntf( vlc_object_t
* );
83 int Open_LuaHTTP( vlc_object_t
* );
84 int Open_LuaCLI( vlc_object_t
* );
85 int Open_LuaTelnet( vlc_object_t
* );
88 int Open_Extension( vlc_object_t
* );
89 void Close_Extension( vlc_object_t
* );
91 int Open_LuaSD( vlc_object_t
* );
92 void Close_LuaSD( vlc_object_t
* );
95 int vlclua_probe_sd( vlc_object_t
*, const char *name
);
97 /*****************************************************************************
99 *****************************************************************************/
100 static inline void lua_Dbg( vlc_object_t
* p_this
, const char * ppz_fmt
, ... )
103 va_start( ap
, ppz_fmt
);
104 msg_GenericVa( p_this
, VLC_MSG_DBG
, ppz_fmt
, ap
);
108 static inline bool lua_Disabled( vlc_object_t
*p_this
)
110 return !var_InheritBool( p_this
, "lua" );
112 #define lua_Disabled( x ) lua_Disabled( VLC_OBJECT( x ) )
114 /*****************************************************************************
115 * Functions that should be in lua ... but aren't for some obscure reason
116 *****************************************************************************/
117 static inline bool luaL_checkboolean( lua_State
*L
, int narg
)
119 luaL_checktype( L
, narg
, LUA_TBOOLEAN
); /* can raise an error */
120 return lua_toboolean( L
, narg
);
123 static inline int luaL_optboolean( lua_State
*L
, int narg
, int def
)
125 return luaL_opt( L
, luaL_checkboolean
, narg
, def
);
128 static inline const char *luaL_nilorcheckstring( lua_State
*L
, int narg
)
130 if( lua_isnil( L
, narg
) )
132 return luaL_checkstring( L
, narg
);
135 static inline char *luaL_strdupornull( lua_State
*L
, int narg
)
137 if( lua_isstring( L
, narg
) )
138 return strdup( luaL_checkstring( L
, narg
) );
142 void vlclua_set_this( lua_State
*, vlc_object_t
* );
143 #define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
144 vlc_object_t
* vlclua_get_this( lua_State
* );
146 void vlclua_set_playlist_internal( lua_State
*, playlist_t
* );
147 playlist_t
* vlclua_get_playlist_internal( lua_State
* );
149 /*****************************************************************************
150 * Lua function bridge
151 *****************************************************************************/
152 #define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
153 int vlclua_push_ret( lua_State
*, int i_error
);
155 /*****************************************************************************
156 * Will execute func on all scripts in luadirname, and stop if func returns
158 *****************************************************************************/
159 typedef struct luabatch_context_t luabatch_context_t
;
160 struct luabatch_context_t
162 input_item_t
*p_item
;
163 meta_fetcher_scope_t e_scope
;
164 bool (*pf_validator
)( const luabatch_context_t
*, meta_fetcher_scope_t
);
167 int vlclua_scripts_batch_execute( vlc_object_t
*p_this
, const char * luadirname
,
168 int (*func
)(vlc_object_t
*, const char *, const luabatch_context_t
*),
170 int vlclua_dir_list( const char *luadirname
, char ***pppsz_dir_list
);
171 void vlclua_dir_list_free( char **ppsz_dir_list
);
172 char *vlclua_find_file( const char *psz_luadirname
, const char *psz_name
);
174 /*****************************************************************************
175 * Replace Lua file reader by VLC input. Allows loadings scripts in Zip pkg.
176 *****************************************************************************/
177 int vlclua_dofile( vlc_object_t
*p_this
, lua_State
*L
, const char *url
);
179 /*****************************************************************************
180 * Playlist and meta data internal utilities.
181 *****************************************************************************/
182 void vlclua_read_options( vlc_object_t
*, lua_State
*, int *, char *** );
183 #define vlclua_read_options( a, b, c, d ) vlclua_read_options( VLC_OBJECT( a ), b, c, d )
184 void vlclua_read_meta_data( vlc_object_t
*, lua_State
*, input_item_t
* );
185 #define vlclua_read_meta_data( a, b, c ) vlclua_read_meta_data( VLC_OBJECT( a ), b, c )
186 void vlclua_read_custom_meta_data( vlc_object_t
*, lua_State
*,
188 #define vlclua_read_custom_meta_data( a, b, c ) vlclua_read_custom_meta_data( VLC_OBJECT( a ), b, c )
190 input_item_t
*vlclua_read_input_item(vlc_object_t
*, lua_State
*);
192 int vlclua_add_modules_path( lua_State
*, const char *psz_filename
);
194 struct vlc_interrupt
;
197 * File descriptors table
201 struct vlc_interrupt
*interrupt
;
206 int vlclua_fd_init( lua_State
*, vlclua_dtable_t
* );
207 void vlclua_fd_interrupt( vlclua_dtable_t
* );
208 void vlclua_fd_cleanup( vlclua_dtable_t
* );
209 struct vlc_interrupt
*vlclua_set_interrupt( lua_State
*L
);
211 #endif /* VLC_LUA_H */