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 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_input.h>
32 #include <vlc_playlist.h>
34 #include <vlc_meta_fetcher.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)
51 #if LUA_VERSION_NUM >= 502
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 ) ) \
61 luaL_setfuncs( L, (l), 0 ); \
62 lua_pushvalue( L, -1 ); \
63 lua_setglobal( L, n );
65 # define luaL_register_namespace(L, n, l) luaL_register( L, n, (l) );
69 /*****************************************************************************
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
* );
94 int vlclua_probe_sd( vlc_object_t
*, const char *name
);
96 /*****************************************************************************
98 *****************************************************************************/
99 static inline void lua_Dbg( vlc_object_t
* p_this
, const char * ppz_fmt
, ... )
102 va_start( ap
, ppz_fmt
);
103 msg_GenericVa( p_this
, VLC_MSG_DBG
, ppz_fmt
, 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
) )
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
) );
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
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
*),
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
*,
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
200 struct vlc_interrupt
*interrupt
;
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 */