]> git.sesse.net Git - vlc/blob - modules/misc/lua/vlc.h
Add a new type of VLC Lua module: Interfaces.
[vlc] / modules / misc / lua / vlc.h
1 /*****************************************************************************
2  * luameta.c: Get meta/artwork using lua scripts
3  *****************************************************************************
4  * Copyright (C) 2007 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 VLCLUA_H
26 #define VLC_LUA_H
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #ifndef  _GNU_SOURCE
31 #   define  _GNU_SOURCE
32 #endif
33
34 #include <vlc/vlc.h>
35 #include <vlc_input.h>
36 #include <vlc_playlist.h>
37 #include <vlc_meta.h>
38 #include <vlc_url.h>
39 #include <vlc_strings.h>
40 #include <vlc_stream.h>
41 #include <vlc_charset.h>
42
43 #ifdef HAVE_SYS_STAT_H
44 #   include <sys/stat.h>
45 #endif
46
47 #include <lua.h>        /* Low level lua C API */
48 #include <lauxlib.h>    /* Higher level C API */
49 #include <lualib.h>     /* Lua libs */
50
51 /*****************************************************************************
52  * Module entry points
53  *****************************************************************************/
54 int E_(FindArt)( vlc_object_t * );
55 int E_(FindMeta)( vlc_object_t * );
56
57 int E_(Import_LuaPlaylist)( vlc_object_t * );
58 void E_(Close_LuaPlaylist)( vlc_object_t * );
59
60 int E_(Open_LuaIntf)( vlc_object_t * );
61 void E_(Close_LuaIntf)( vlc_object_t * );
62
63
64 /*****************************************************************************
65  * Lua debug
66  *****************************************************************************/
67 static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
68 {
69     if( p_this->p_libvlc->i_verbose < 3 )
70         return;
71
72     va_list ap;
73     va_start( ap, ppz_fmt );
74     __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL,
75                       VLC_MSG_DBG, MODULE_STRING,
76                       ppz_fmt, ap );
77     va_end( ap );
78 }
79
80 /*****************************************************************************
81  * Functions that should be in lua ... but aren't for some obscure reason
82  *****************************************************************************/
83 static inline int luaL_checkboolean( lua_State *L, int narg )
84 {
85     luaL_checktype( L, narg, LUA_TBOOLEAN ); /* can raise an error */
86     return lua_toboolean( L, narg );
87 }
88
89 static inline const void *luaL_checklightuserdata( lua_State *L, int narg )
90 {
91     luaL_checktype( L, narg, LUA_TLIGHTUSERDATA ); /* can raise an error */
92     return lua_topointer( L, narg );
93 }
94
95 static inline const void *luaL_checkuserdata( lua_State *L, int narg, size_t size )
96 {
97     luaL_checktype( L, narg, LUA_TUSERDATA ); /* can raise an error */
98     if( size && size != lua_objlen( L, narg ) ) /* this isn't worth much ... but it might still prevent a few errors */
99         luaL_error( L, "user data size doesn't match" );
100     return lua_topointer( L, narg );
101 }
102
103 /*****************************************************************************
104  * Lua vlc_object_t wrapper
105  *****************************************************************************/
106 int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
107                               lua_CFunction pf_gc );
108 #define vlclua_push_vlc_object( a, b, c ) \
109         __vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
110 vlc_object_t *vlclua_checkobject( lua_State *L, int narg, int i_type );
111 int vlclua_gc_release( lua_State *L );
112 int vlclua_object_find( lua_State *L );
113 int vlclua_object_find_name( lua_State *L );
114
115 int vlclua_add_callback( lua_State * );
116 int vlclua_del_callback( lua_State * );
117
118 int vlclua_url_parse( lua_State * );
119 int vlclua_net_listen_tcp( lua_State * );
120 int vlclua_net_listen_close( lua_State * );
121 int vlclua_net_accept( lua_State * );
122 int vlclua_net_close( lua_State * );
123 int vlclua_net_send( lua_State * );
124 int vlclua_net_recv( lua_State * );
125 int vlclua_net_select( lua_State * );
126
127 int vlclua_fd_set_new( lua_State * );
128 int vlclua_fd_clr( lua_State * );
129 int vlclua_fd_isset( lua_State * );
130 int vlclua_fd_set( lua_State * );
131 int vlclua_fd_zero( lua_State * );
132 int vlclua_fd_read( lua_State * );
133 int vlclua_fd_write( lua_State * );
134
135 int vlclua_vlm_new( lua_State * );
136 int vlclua_vlm_delete( lua_State * );
137 int vlclua_vlm_execute_command( lua_State * );
138
139 /*****************************************************************************
140  * Lua function bridge
141  *****************************************************************************/
142 vlc_object_t * vlclua_get_this( lua_State * );
143 #define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
144 int vlclua_push_ret( lua_State *, int i_error );
145
146 int vlclua_version( lua_State * );
147 int vlclua_quit( lua_State * );
148
149 int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
150 int vlclua_var_get( lua_State * );
151 int vlclua_var_get_list( lua_State * );
152 int vlclua_var_set( lua_State * );
153 int vlclua_module_command( lua_State * );
154 int vlclua_libvlc_command( lua_State * );
155
156 int vlclua_config_get( lua_State * );
157 int vlclua_config_set( lua_State * );
158
159 int vlclua_volume_set( lua_State * );
160 int vlclua_volume_get( lua_State * );
161 int vlclua_volume_up( lua_State * );
162 int vlclua_volume_down( lua_State * );
163
164 int vlclua_stream_new( lua_State * );
165 int vlclua_stream_read( lua_State * );
166 int vlclua_stream_readline( lua_State * );
167 int vlclua_stream_delete( lua_State * );
168
169 int vlclua_decode_uri( lua_State * );
170 int vlclua_resolve_xml_special_chars( lua_State * );
171
172 int vlclua_msg_dbg( lua_State * );
173 int vlclua_msg_warn( lua_State * );
174 int vlclua_msg_err( lua_State * );
175 int vlclua_msg_info( lua_State * );
176
177 /*****************************************************************************
178  * Will execute func on all scripts in luadirname, and stop if func returns
179  * success.
180  *****************************************************************************/
181 int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
182         int (*func)(vlc_object_t *, const char *, lua_State *, void *),
183         lua_State * L, void * user_data );
184 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list );
185
186 /*****************************************************************************
187  * Playlist and meta data internal utilities.
188  *****************************************************************************/
189 void __vlclua_read_options( vlc_object_t *, lua_State *, int *, char *** );
190 #define vlclua_read_options(a,b,c,d) __vlclua_read_options(VLC_OBJECT(a),b,c,d)
191 void __vlclua_read_meta_data( vlc_object_t *, lua_State *, input_item_t * );
192 #define vlclua_read_meta_data(a,b,c) __vlclua_read_meta_data(VLC_OBJECT(a),b,c)
193 void __vlclua_read_custom_meta_data( vlc_object_t *, lua_State *,
194                                      input_item_t *);
195 #define vlclua_read_custom_meta_data(a,b,c) __vlclua_read_custom_meta_data(VLC_OBJECT(a),b,c)
196 int __vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
197                                     input_item_t *, vlc_bool_t );
198 #define vlclua_playlist_add_internal(a,b,c,d,e) __vlclua_playlist_add_internal(VLC_OBJECT(a),b,c,d,e)
199
200
201 #endif /* VLC_LUA_H */
202