vlc.h 6.72 KB
Newer Older
1
/*****************************************************************************
2
 * vlc.h: VLC specific lua library functions.
3
 *****************************************************************************
4
 * Copyright (C) 2007-2008 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * $Id$
 *
 * Authors: Antoine Cellerier <dionoea at videolan tod org>
 *          Pierre d'Herbemont <pdherbemont # videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25
#ifndef VLC_LUA_H
26 27 28 29 30
#define VLC_LUA_H
/*****************************************************************************
 * Preamble
 *****************************************************************************/

31
#include <vlc_common.h>
32 33 34 35 36 37 38
#include <vlc_input.h>
#include <vlc_playlist.h>
#include <vlc_meta.h>
#include <vlc_url.h>
#include <vlc_strings.h>
#include <vlc_stream.h>

39
#define LUA_COMPAT_MODULE
40 41 42
#include <lua.h>        /* Low level lua C API */
#include <lauxlib.h>    /* Higher level C API */
#include <lualib.h>     /* Lua libs */
43 44 45 46 47
#if LUA_VERSION_NUM >= 502
#define lua_equal(L,idx1,idx2)		lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_objlen(L,idx)			lua_rawlen(L,idx)
#define lua_strlen(L,idx)			lua_rawlen(L,idx)
#endif
48 49 50 51

/*****************************************************************************
 * Module entry points
 *****************************************************************************/
52
int ReadMeta( vlc_object_t * );
Pierre's avatar
Pierre committed
53
int FetchMeta( vlc_object_t * );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
54
int FindArt( vlc_object_t * );
55

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
56 57
int Import_LuaPlaylist( vlc_object_t * );
void Close_LuaPlaylist( vlc_object_t * );
58

59
#define TELNETPORT_DEFAULT 4212
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
60 61
int Open_LuaIntf( vlc_object_t * );
void Close_LuaIntf( vlc_object_t * );
62 63 64 65
int Open_LuaHTTP( vlc_object_t * );
int Open_LuaCLI( vlc_object_t * );
int Open_LuaTelnet( vlc_object_t * );

66

Jean-Philippe André's avatar
Jean-Philippe André committed
67 68 69
int Open_Extension( vlc_object_t * );
void Close_Extension( vlc_object_t * );

70 71
int Open_LuaSD( vlc_object_t * );
void Close_LuaSD( vlc_object_t * );
72 73 74 75 76 77 78 79

/*****************************************************************************
 * Lua debug
 *****************************************************************************/
static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
{
    va_list ap;
    va_start( ap, ppz_fmt );
80
    msg_GenericVa( p_this, VLC_MSG_DBG, MODULE_STRING, ppz_fmt, ap );
81 82 83 84 85 86
    va_end( ap );
}

/*****************************************************************************
 * Functions that should be in lua ... but aren't for some obscure reason
 *****************************************************************************/
87
static inline bool luaL_checkboolean( lua_State *L, int narg )
88 89 90 91 92
{
    luaL_checktype( L, narg, LUA_TBOOLEAN ); /* can raise an error */
    return lua_toboolean( L, narg );
}

93 94 95 96 97
static inline int luaL_optboolean( lua_State *L, int narg, int def )
{
    return luaL_opt( L, luaL_checkboolean, narg, def );
}

98 99 100 101 102 103 104
static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
{
    if( lua_isnil( L, narg ) )
        return NULL;
    return luaL_checkstring( L, narg );
}

105 106 107 108 109 110 111
static inline char *luaL_strdupornull( lua_State *L, int narg )
{
    if( lua_isstring( L, narg ) )
        return strdup( luaL_checkstring( L, narg ) );
    return NULL;
}

112 113
void vlclua_set_this( lua_State *, vlc_object_t * );
#define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
114
vlc_object_t * vlclua_get_this( lua_State * );
115

116 117 118
struct intf_sys_t;
void vlclua_set_intf( lua_State *, struct intf_sys_t * );

119 120 121 122 123 124 125 126 127 128 129
/*****************************************************************************
 * Lua function bridge
 *****************************************************************************/
#define vlclua_error( L ) luaL_error( L, "VLC lua error in file %s line %d (function %s)", __FILE__, __LINE__, __func__ )
int vlclua_push_ret( lua_State *, int i_error );

/*****************************************************************************
 * Will execute func on all scripts in luadirname, and stop if func returns
 * success.
 *****************************************************************************/
int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname,
130 131
        int (*func)(vlc_object_t *, const char *, void *),
        void * user_data );
132
int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char ***pppsz_dir_list );
133
void vlclua_dir_list_free( char **ppsz_dir_list );
Antoine Cellerier's avatar
Antoine Cellerier committed
134
char *vlclua_find_file( vlc_object_t *p_this, const char *psz_luadirname, const char *psz_name );
135

136 137 138 139 140
/*****************************************************************************
 * Replace Lua file reader by VLC input. Allows loadings scripts in Zip pkg.
 *****************************************************************************/
int vlclua_dofile( vlc_object_t *p_this, lua_State *L, const char *url );

141 142 143
/*****************************************************************************
 * Playlist and meta data internal utilities.
 *****************************************************************************/
144 145 146 147 148 149 150 151 152 153 154 155 156
void vlclua_read_options( vlc_object_t *, lua_State *, int *, char *** );
#define vlclua_read_options( a, b, c, d ) vlclua_read_options( VLC_OBJECT( a ), b, c, d )
void vlclua_read_meta_data( vlc_object_t *, lua_State *, input_item_t * );
#define vlclua_read_meta_data( a, b, c ) vlclua_read_meta_data( VLC_OBJECT( a ), b, c )
void vlclua_read_custom_meta_data( vlc_object_t *, lua_State *,
                                   input_item_t *);
#define vlclua_read_custom_meta_data( a, b, c ) vlclua_read_custom_meta_data( VLC_OBJECT( a ), b, c )
int vlclua_playlist_add_internal( vlc_object_t *, lua_State *, playlist_t *,
                                  input_item_t *, bool );
#define vlclua_playlist_add_internal( a, b, c, d, e ) vlclua_playlist_add_internal( VLC_OBJECT( a ), b, c, d, e )

int vlclua_add_modules_path( vlc_object_t *, lua_State *, const char *psz_filename );
#define vlclua_add_modules_path( a, b, c ) vlclua_add_modules_path( VLC_OBJECT( a ), b, c )
157

158 159 160 161 162 163 164 165 166 167 168 169 170
/**
 * Per-interface private state
 */
struct intf_sys_t
{
    char *psz_filename;
    lua_State *L;

    vlc_thread_t thread;
    vlc_mutex_t lock;
    vlc_cond_t wait;
    bool exiting;
};
171 172 173

#endif /* VLC_LUA_H */