vlc.h 5.52 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 39 40 41 42 43 44 45
#include <vlc_input.h>
#include <vlc_playlist.h>
#include <vlc_meta.h>
#include <vlc_url.h>
#include <vlc_strings.h>
#include <vlc_stream.h>

#include <lua.h>        /* Low level lua C API */
#include <lauxlib.h>    /* Higher level C API */
#include <lualib.h>     /* Lua libs */

/*****************************************************************************
 * Module entry points
 *****************************************************************************/
46
int ReadMeta( vlc_object_t * );
Pierre's avatar
Pierre committed
47
int FetchMeta( vlc_object_t * );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
48
int FindArt( vlc_object_t * );
49

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
50 51
int Import_LuaPlaylist( vlc_object_t * );
void Close_LuaPlaylist( vlc_object_t * );
52

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
53 54
int Open_LuaIntf( vlc_object_t * );
void Close_LuaIntf( vlc_object_t * );
55

JPeg's avatar
JPeg committed
56 57 58
int Open_Extension( vlc_object_t * );
void Close_Extension( vlc_object_t * );

59 60
int Open_LuaSD( vlc_object_t * );
void Close_LuaSD( vlc_object_t * );
61 62 63 64 65 66 67 68

/*****************************************************************************
 * Lua debug
 *****************************************************************************/
static inline void lua_Dbg( vlc_object_t * p_this, const char * ppz_fmt, ... )
{
    va_list ap;
    va_start( ap, ppz_fmt );
69
    msg_GenericVa( p_this, VLC_MSG_DBG, MODULE_STRING, ppz_fmt, ap );
70 71 72 73 74 75 76 77 78 79 80 81
    va_end( ap );
}

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

82 83 84 85 86
static inline int luaL_optboolean( lua_State *L, int narg, int def )
{
    return luaL_opt( L, luaL_checkboolean, narg, def );
}

87 88 89 90 91 92 93
static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
{
    if( lua_isnil( L, narg ) )
        return NULL;
    return luaL_checkstring( L, narg );
}

94
vlc_object_t * vlclua_get_this( lua_State * );
95

96 97 98 99 100 101 102 103 104 105 106 107 108
/*****************************************************************************
 * 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,
        int (*func)(vlc_object_t *, const char *, lua_State *, void *),
        lua_State * L, void * user_data );
109
int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list );
110
void vlclua_dir_list_free( char **ppsz_dir_list );
dionoea's avatar
dionoea committed
111
char *vlclua_find_file( vlc_object_t *p_this, const char *psz_luadirname, const char *psz_name );
112 113 114 115 116 117 118 119 120 121 122 123

/*****************************************************************************
 * Playlist and meta data internal utilities.
 *****************************************************************************/
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 *,
124
                                    input_item_t *, bool );
125 126
#define vlclua_playlist_add_internal(a,b,c,d,e) __vlclua_playlist_add_internal(VLC_OBJECT(a),b,c,d,e)

127 128 129 130 131 132 133 134 135 136 137 138 139
/**
 * 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;
};
140 141 142

#endif /* VLC_LUA_H */