]> git.sesse.net Git - vlc/blob - modules/lua/vlc.h
mux: mp4: fix signedness
[vlc] / modules / 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_meta_fetcher.h>
36 #include <vlc_url.h>
37 #include <vlc_strings.h>
38 #include <vlc_stream.h>
39 #include <vlc_demux.h>
40
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 */
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
50
51 /*****************************************************************************
52  * Module entry points
53  *****************************************************************************/
54 int ReadMeta( demux_meta_t * );
55 int FetchMeta( meta_fetcher_t * );
56 int FindArt( meta_fetcher_t * );
57
58 int Import_LuaPlaylist( vlc_object_t * );
59 void Close_LuaPlaylist( vlc_object_t * );
60
61 #define TELNETPORT_DEFAULT 4212
62 int Open_LuaIntf( vlc_object_t * );
63 void Close_LuaIntf( vlc_object_t * );
64 int Open_LuaHTTP( vlc_object_t * );
65 int Open_LuaCLI( vlc_object_t * );
66 int Open_LuaTelnet( vlc_object_t * );
67
68
69 int Open_Extension( vlc_object_t * );
70 void Close_Extension( vlc_object_t * );
71
72 int Open_LuaSD( vlc_object_t * );
73 void Close_LuaSD( vlc_object_t * );
74
75 /*****************************************************************************
76  * Lua debug
77  *****************************************************************************/
78 static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
79 {
80     va_list ap;
81     va_start( ap, ppz_fmt );
82     msg_GenericVa( p_this, VLC_MSG_DBG, MODULE_STRING, ppz_fmt, ap );
83     va_end( ap );
84 }
85
86 /*****************************************************************************
87  * Functions that should be in lua ... but aren't for some obscure reason
88  *****************************************************************************/
89 static inline bool luaL_checkboolean( lua_State *L, int narg )
90 {
91     luaL_checktype( L, narg, LUA_TBOOLEAN ); /* can raise an error */
92     return lua_toboolean( L, narg );
93 }
94
95 static inline int luaL_optboolean( lua_State *L, int narg, int def )
96 {
97     return luaL_opt( L, luaL_checkboolean, narg, def );
98 }
99
100 static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
101 {
102     if( lua_isnil( L, narg ) )
103         return NULL;
104     return luaL_checkstring( L, narg );
105 }
106
107 static inline char *luaL_strdupornull( lua_State *L, int narg )
108 {
109     if( lua_isstring( L, narg ) )
110         return strdup( luaL_checkstring( L, narg ) );
111     return NULL;
112 }
113
114 void vlclua_set_this( lua_State *, vlc_object_t * );
115 #define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
116 vlc_object_t * vlclua_get_this( lua_State * );
117
118 void vlclua_set_playlist_internal( lua_State *, playlist_t * );
119 playlist_t * vlclua_get_playlist_internal( lua_State * );
120
121 /*****************************************************************************
122  * Lua function bridge
123  *****************************************************************************/
124 #define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
125 int vlclua_push_ret( lua_State *, int i_error );
126
127 /*****************************************************************************
128  * Will execute func on all scripts in luadirname, and stop if func returns
129  * success.
130  *****************************************************************************/
131 typedef struct luabatch_context_t luabatch_context_t;
132 struct luabatch_context_t
133 {
134     input_item_t *p_item;
135     meta_fetcher_scope_t e_scope;
136     bool (*pf_validator)( const luabatch_context_t *, meta_fetcher_scope_t );
137 };
138
139 int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
140         int (*func)(vlc_object_t *, const char *, const luabatch_context_t *),
141         void * user_data );
142 int vlclua_dir_list( const char *luadirname, char ***pppsz_dir_list );
143 void vlclua_dir_list_free( char **ppsz_dir_list );
144 char *vlclua_find_file( const char *psz_luadirname, const char *psz_name );
145
146 /*****************************************************************************
147  * Replace Lua file reader by VLC input. Allows loadings scripts in Zip pkg.
148  *****************************************************************************/
149 int vlclua_dofile( vlc_object_t *p_this, lua_State *L, const char *url );
150
151 /*****************************************************************************
152  * Playlist and meta data internal utilities.
153  *****************************************************************************/
154 void vlclua_read_options( vlc_object_t *, lua_State *, int *, char *** );
155 #define vlclua_read_options( a, b, c, d ) vlclua_read_options( VLC_OBJECT( a ), b, c, d )
156 void vlclua_read_meta_data( vlc_object_t *, lua_State *, input_item_t * );
157 #define vlclua_read_meta_data( a, b, c ) vlclua_read_meta_data( VLC_OBJECT( a ), b, c )
158 void vlclua_read_custom_meta_data( vlc_object_t *, lua_State *,
159                                    input_item_t *);
160 #define vlclua_read_custom_meta_data( a, b, c ) vlclua_read_custom_meta_data( VLC_OBJECT( a ), b, c )
161 int vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
162                                   input_item_t *, bool );
163 #define vlclua_playlist_add_internal( a, b, c, d, e ) vlclua_playlist_add_internal( VLC_OBJECT( a ), b, c, d, e )
164
165 int vlclua_add_modules_path( lua_State *, const char *psz_filename );
166
167 /**
168  * File descriptors table
169  */
170 typedef struct
171 {
172     int *fdv;
173     unsigned fdc;
174 #ifndef _WIN32
175     int fd[2];
176 #endif
177 } vlclua_dtable_t;
178
179 int vlclua_fd_init( lua_State *, vlclua_dtable_t * );
180 void vlclua_fd_interrupt( vlclua_dtable_t * );
181 void vlclua_fd_cleanup( vlclua_dtable_t * );
182
183 /**
184  * Per-interface private state
185  */
186 struct intf_sys_t
187 {
188     char *psz_filename;
189     lua_State *L;
190     vlc_thread_t thread;
191     vlclua_dtable_t dtable;
192 };
193
194 #endif /* VLC_LUA_H */
195