]> git.sesse.net Git - vlc/commitdiff
Implement Lua objects in the C code directly. Fix most type checks. Move every thing...
authorAntoine Cellerier <dionoea@videolan.org>
Wed, 11 Jun 2008 13:57:58 +0000 (15:57 +0200)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 15 Jun 2008 11:05:50 +0000 (13:05 +0200)
34 files changed:
modules/misc/lua/Modules.am
modules/misc/lua/acl.c [deleted file]
modules/misc/lua/demux.c [moved from modules/misc/lua/playlist.c with 96% similarity]
modules/misc/lua/intf.c
modules/misc/lua/libs.h [new file with mode: 0644]
modules/misc/lua/libs/acl.c [new file with mode: 0644]
modules/misc/lua/libs/configuration.c [moved from modules/misc/lua/configuration.c with 84% similarity]
modules/misc/lua/libs/httpd.c [moved from modules/misc/lua/httpd.c with 70% similarity]
modules/misc/lua/libs/input.c [new file with mode: 0644]
modules/misc/lua/libs/input.h [new file with mode: 0644]
modules/misc/lua/libs/messages.c [new file with mode: 0644]
modules/misc/lua/libs/misc.c [new file with mode: 0644]
modules/misc/lua/libs/misc.h [new file with mode: 0644]
modules/misc/lua/libs/net.c [moved from modules/misc/lua/net.c with 62% similarity]
modules/misc/lua/libs/objects.c [moved from modules/misc/lua/objects.c with 69% similarity]
modules/misc/lua/libs/objects.h [new file with mode: 0644]
modules/misc/lua/libs/osd.c [new file with mode: 0644]
modules/misc/lua/libs/playlist.c [new file with mode: 0644]
modules/misc/lua/libs/playlist.h [new file with mode: 0644]
modules/misc/lua/libs/sd.c [moved from modules/misc/lua/sd.c with 79% similarity]
modules/misc/lua/libs/stream.c [new file with mode: 0644]
modules/misc/lua/libs/strings.c [new file with mode: 0644]
modules/misc/lua/libs/variables.c [moved from modules/misc/lua/callbacks.c with 56% similarity]
modules/misc/lua/libs/variables.h [new file with mode: 0644]
modules/misc/lua/libs/video.c [new file with mode: 0644]
modules/misc/lua/libs/vlm.c [moved from modules/misc/lua/vlm.c with 63% similarity]
modules/misc/lua/libs/volume.c [new file with mode: 0644]
modules/misc/lua/meta.c
modules/misc/lua/variables.c [deleted file]
modules/misc/lua/vlc.c
modules/misc/lua/vlc.h
share/Makefile.am
share/lua/intf/modules/acl.lua [deleted file]
share/lua/intf/modules/httpd.lua [deleted file]

index c1b8780ec73f239af8cd92b6049d3d425358f9b1..a220db0fe5b8f47189d4bc0cf28c344477cbb382 100644 (file)
@@ -1,3 +1,31 @@
-SOURCES_lua = playlist.c meta.c intf.c vlc.c vlc.h callbacks.c objects.c variables.c configuration.c net.c vlm.c httpd.c acl.c sd.c
+SOURCES_lua = \
+       intf.c \
+       meta.c \
+       demux.c \
+       vlc.c \
+       vlc.h \
+       libs.h \
+       libs/acl.c \
+       libs/configuration.c \
+       libs/httpd.c \
+       libs/input.c \
+       libs/input.h \
+       libs/messages.c \
+       libs/misc.c \
+       libs/net.c \
+       libs/objects.c \
+       libs/objects.h \
+       libs/osd.c \
+       libs/playlist.c \
+       libs/playlist.h \
+       libs/sd.c \
+       libs/stream.c \
+       libs/strings.c \
+       libs/variables.c \
+       libs/variables.h \
+       libs/video.c \
+       libs/vlm.c \
+       libs/volume.c \
+       $(NULL)
 
 libvlc_LTLIBRARIES += liblua_plugin.la
diff --git a/modules/misc/lua/acl.c b/modules/misc/lua/acl.c
deleted file mode 100644 (file)
index 065c64c..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*****************************************************************************
- * acl.c: Access list related functions
- *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
- * $Id$
- *
- * Authors: Antoine Cellerier <dionoea at videolan tod 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#ifndef  _GNU_SOURCE
-#   define  _GNU_SOURCE
-#endif
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_acl.h>
-
-#include <lua.h>        /* Low level lua C API */
-#include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
-
-#include "vlc.h"
-
-/*****************************************************************************
- *
- *****************************************************************************/
-int vlclua_acl_create( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    bool b_allow = luaL_checkboolean( L, 1 ) ? true : false;
-    vlc_acl_t *p_acl = ACL_Create( p_this, b_allow );
-    if( !p_acl )
-        return luaL_error( L, "ACL creation failed." );
-    lua_pushlightuserdata( L, p_acl ); /* FIXME */
-    return 1;
-}
-
-int vlclua_acl_delete( lua_State *L )
-{
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    ACL_Destroy( p_acl );
-    return 0;
-}
-
-int vlclua_acl_check( lua_State *L )
-{
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    const char *psz_ip = luaL_checkstring( L, 2 );
-    lua_pushinteger( L, ACL_Check( p_acl, psz_ip ) );
-    return 1;
-}
-
-int vlclua_acl_duplicate( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    vlc_acl_t *p_acl_new = ACL_Duplicate( p_this, p_acl );
-    lua_pushlightuserdata( L, p_acl_new );
-    return 1;
-}
-
-int vlclua_acl_add_host( lua_State *L )
-{
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    const char *psz_ip = luaL_checkstring( L, 2 );
-    bool b_allow = luaL_checkboolean( L, 3 ) ? true : false;
-    lua_pushinteger( L, ACL_AddHost( p_acl, psz_ip, b_allow ) );
-    return 1;
-}
-
-int vlclua_acl_add_net( lua_State *L )
-{
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    const char *psz_ip = luaL_checkstring( L, 2 );
-    int i_len = luaL_checkint( L, 3 );
-    bool b_allow = luaL_checkboolean( L, 4 ) ? true : false;
-    lua_pushinteger( L, ACL_AddNet( p_acl, psz_ip, i_len, b_allow ) );
-    return 1;
-}
-
-int vlclua_acl_load_file( lua_State *L )
-{
-    vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
-    const char *psz_path = luaL_checkstring( L, 2 );
-    lua_pushinteger( L, ACL_LoadFile( p_acl, psz_path ) );
-    return 1;
-}
similarity index 96%
rename from modules/misc/lua/playlist.c
rename to modules/misc/lua/demux.c
index 60602fd6efb28cef84a6348e4a648a6de5b0b053..890b643c7b59523a9c61b899dd597c5755d9635c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * playlist.c :  Lua playlist demux module
+ * demux.c :  Lua playlist demux module
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
@@ -40,6 +40,7 @@
 #endif
 
 #include "vlc.h"
+#include "libs.h"
 
 
 /*****************************************************************************
@@ -49,7 +50,7 @@ static int Demux( demux_t *p_demux );
 static int Control( demux_t *p_demux, int i_query, va_list args );
 
 /*****************************************************************************
- *
+ * Demux specific functions
  *****************************************************************************/
 struct demux_sys_t
 {
@@ -57,10 +58,6 @@ struct demux_sys_t
     char *psz_filename;
 };
 
-/*****************************************************************************
- *
- *****************************************************************************/
-
 static int vlclua_demux_peek( lua_State *L )
 {
     demux_t *p_demux = (demux_t *)vlclua_get_this( L );
@@ -97,17 +94,13 @@ static int vlclua_demux_readline( lua_State *L )
     return 1;
 }
 
-
+/*****************************************************************************
+ *
+ *****************************************************************************/
 /* Functions to register */
 static luaL_Reg p_reg[] =
 {
     { "peek", vlclua_demux_peek },
-    { "decode_uri", vlclua_decode_uri },
-    { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
-    { "msg_dbg", vlclua_msg_dbg },
-    { "msg_warn", vlclua_msg_warn },
-    { "msg_err", vlclua_msg_err },
-    { "msg_info", vlclua_msg_info },
     { NULL, NULL }
 };
 
@@ -215,6 +208,8 @@ int Import_LuaPlaylist( vlc_object_t *p_this )
     luaL_openlibs( L ); /* FIXME: Don't open all the libs? */
 
     luaL_register( L, "vlc", p_reg );
+    luaopen_msg( L );
+    luaopen_strings( L );
     lua_pushlightuserdata( L, p_demux );
     lua_setfield( L, -2, "private" );
     lua_pushstring( L, p_demux->psz_path );
index a77971777486c5afb848a10e6dcac39f91ca611c..4cf530241f694dd3984c8bca08721b1b7ca023f7 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * intf.c: Generic lua interface functions
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_aout.h>
-#include <vlc_vout.h>
-#include <vlc_osd.h>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
 #include <lualib.h>     /* Lua libs */
 
 #include "vlc.h"
+#include "libs.h"
 
+/*****************************************************************************
+ * Prototypes
+ *****************************************************************************/
 struct intf_sys_t
 {
     char *psz_filename;
     lua_State *L;
 };
 
-/*****************************************************************************
- * Internal lua<->vlc utils
- *****************************************************************************/
-playlist_t *vlclua_get_playlist_internal( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    return pl_Yield( p_this );
-}
-
-static input_thread_t * vlclua_get_input_internal( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    input_thread_t *p_input = p_playlist->p_input;
-    if( p_input ) vlc_object_yield( p_input );
-    vlc_object_release( p_playlist );
-    return p_input;
-}
-
-/* FIXME: This is high level logic. Should be implemented in lua */
-#define vlclua_var_toggle_or_set(a,b,c) \
-        __vlclua_var_toggle_or_set(a,VLC_OBJECT(b),c)
-static int __vlclua_var_toggle_or_set( lua_State *L, vlc_object_t *p_obj,
-                                       const char *psz_name )
-{
-    bool b_bool;
-    if( lua_gettop( L ) > 1 ) return vlclua_error( L );
-
-    if( lua_gettop( L ) == 0 )
-        b_bool = !var_GetBool( p_obj, psz_name );
-    else /* lua_gettop( L ) == 1 */
-    {
-        b_bool = luaL_checkboolean( L, -1 )?true:false;
-        lua_pop( L, 1 );
-    }
-
-    if( b_bool != var_GetBool( p_obj, psz_name ) )
-        var_SetBool( p_obj, psz_name, b_bool );
-
-    lua_pushboolean( L, b_bool );
-    return 1;
-}
-
-/*****************************************************************************
- * Libvlc TODO: move to vlc.c
- *****************************************************************************/
-static int vlclua_get_libvlc( lua_State *L )
-{
-    vlclua_push_vlc_object( L, vlclua_get_this( L )->p_libvlc,
-                            NULL );
-    return 1;
-}
-
-/*****************************************************************************
- * Input handling
- *****************************************************************************/
-static int vlclua_get_input( lua_State *L )
-{
-    input_thread_t *p_input = vlclua_get_input_internal( L );
-    if( p_input )
-    {
-        vlclua_push_vlc_object( L, p_input, vlclua_gc_release );
-    }
-    else lua_pushnil( L );
-    return 1;
-}
-
-static int vlclua_input_info( lua_State *L )
-{
-    input_thread_t * p_input = vlclua_get_input_internal( L );
-    int i_cat;
-    int i;
-    if( !p_input ) return vlclua_error( L );
-    //vlc_mutex_lock( &input_GetItem(p_input)->lock );
-    i_cat = input_GetItem(p_input)->i_categories;
-    lua_createtable( L, 0, i_cat );
-    for( i = 0; i < i_cat; i++ )
-    {
-        info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
-        int i_infos = p_category->i_infos;
-        int j;
-        lua_pushstring( L, p_category->psz_name );
-        lua_createtable( L, 0, i_infos );
-        for( j = 0; j < i_infos; j++ )
-        {
-            info_t *p_info = p_category->pp_infos[j];
-            lua_pushstring( L, p_info->psz_name );
-            lua_pushstring( L, p_info->psz_value );
-            lua_settable( L, -3 );
-        }
-        lua_settable( L, -3 );
-    }
-    //vlc_object_release( p_input );
-    return 1;
-}
-
-static int vlclua_is_playing( lua_State *L )
-{
-    input_thread_t * p_input = vlclua_get_input_internal( L );
-    lua_pushboolean( L, !!p_input );
-    return 1;
-}
-
-static int vlclua_get_title( lua_State *L )
-{
-    input_thread_t *p_input = vlclua_get_input_internal( L );
-    if( !p_input )
-        lua_pushnil( L );
-    else
-    {
-        lua_pushstring( L, input_GetItem(p_input)->psz_name );
-        vlc_object_release( p_input );
-    }
-    return 1;
-}
-
-static int vlclua_input_stats( lua_State *L )
-{
-    input_thread_t *p_input = vlclua_get_input_internal( L );
-    input_item_t *p_item = p_input && p_input->p ? input_GetItem( p_input ) : NULL;
-    lua_newtable( L );
-    if( p_item )
-    {
-#define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
-                       lua_setfield( L, -2, #n );
-#define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
-                         lua_setfield( L, -2, #n );
-        STATS_INT( read_bytes )
-        STATS_FLOAT( input_bitrate )
-        STATS_INT( demux_read_bytes )
-        STATS_FLOAT( demux_bitrate )
-        STATS_INT( decoded_video )
-        STATS_INT( displayed_pictures )
-        STATS_INT( lost_pictures )
-        STATS_INT( decoded_audio )
-        STATS_INT( played_abuffers )
-        STATS_INT( lost_abuffers )
-        STATS_INT( sent_packets )
-        STATS_INT( sent_bytes )
-        STATS_FLOAT( send_bitrate )
-#undef STATS_INT
-#undef STATS_FLOAT
-    }
-    return 1;
-}
-
-/*****************************************************************************
- * Vout control
- *****************************************************************************/
-static int vlclua_fullscreen( lua_State *L )
-{
-    vout_thread_t *p_vout;
-    int i_ret;
-
-    input_thread_t * p_input = vlclua_get_input_internal( L );
-    if( !p_input ) return vlclua_error( L );
-
-    p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
-    if( !p_vout ) return vlclua_error( L );
-
-    i_ret = vlclua_var_toggle_or_set( L, p_vout, "fullscreen" );
-    vlc_object_release( p_vout );
-    vlc_object_release( p_input );
-    return i_ret;
-}
-
-static int vlc_osd_icon_from_string( const char *psz_name )
-{
-    static const struct
-    {
-        int i_icon;
-        const char *psz_name;
-    } pp_icons[] =
-        { { OSD_PAUSE_ICON, "pause" },
-          { OSD_PLAY_ICON, "play" },
-          { OSD_SPEAKER_ICON, "speaker" },
-          { OSD_MUTE_ICON, "mute" },
-          { 0, NULL } };
-    int i;
-    for( i = 0; pp_icons[i].psz_name; i++ )
-    {
-        if( !strcmp( psz_name, pp_icons[i].psz_name ) )
-            return pp_icons[i].i_icon;
-    }
-    return 0;
-}
-
-static int vlclua_osd_icon( lua_State *L )
-{
-    const char *psz_icon = luaL_checkstring( L, 1 );
-    int i_icon = vlc_osd_icon_from_string( psz_icon );
-    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
-    if( !i_icon )
-        return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
-    else
-    {
-        vlc_object_t *p_this = vlclua_get_this( L );
-        vout_OSDIcon( p_this, i_chan, i_icon );
-        return 0;
-    }
-}
-
-static int vlclua_osd_message( lua_State *L )
-{
-    const char *psz_message = luaL_checkstring( L, 1 );
-    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_OSDMessage( p_this, i_chan, psz_message );
-    return 0;
-}
-
-static int vlc_osd_slider_type_from_string( const char *psz_name )
-{
-    static const struct
-    {
-        int i_type;
-        const char *psz_name;
-    } pp_types[] =
-        { { OSD_HOR_SLIDER, "horizontal" },
-          { OSD_VERT_SLIDER, "vertical" },
-          { 0, NULL } };
-    int i;
-    for( i = 0; pp_types[i].psz_name; i++ )
-    {
-        if( !strcmp( psz_name, pp_types[i].psz_name ) )
-            return pp_types[i].i_type;
-    }
-    return 0;
-}
-
-static int vlclua_osd_slider( lua_State *L )
-{
-    int i_position = luaL_checkint( L, 1 );
-    const char *psz_type = luaL_checkstring( L, 2 );
-    int i_type = vlc_osd_slider_type_from_string( psz_type );
-    int i_chan = luaL_optint( L, 3, DEFAULT_CHAN );
-    if( !i_type )
-        return luaL_error( L, "\"%s\" is not a valid slider type.",
-                           psz_type );
-    else
-    {
-        vlc_object_t *p_this = vlclua_get_this( L );
-        vout_OSDSlider( p_this, i_chan, i_position, i_type );
-        return 0;
-    }
-}
-
-static int vlclua_spu_channel_register( lua_State *L )
-{
-    int i_chan;
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
-    if( !p_vout )
-        return luaL_error( L, "Unable to find vout." );
-
-    spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER, &i_chan );
-    vlc_object_release( p_vout );
-    lua_pushinteger( L, i_chan );
-    return 1;
-}
-
-static int vlclua_spu_channel_clear( lua_State *L )
-{
-    int i_chan = luaL_checkint( L, 1 );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
-    if( !p_vout )
-        return luaL_error( L, "Unable to find vout." );
-
-    spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, i_chan );
-    vlc_object_release( p_vout );
-    return 0;
-}
+static void Run( intf_thread_t *p_intf );
 
 /*****************************************************************************
- * Playlist control
+ *
  *****************************************************************************/
-static int vlclua_get_playlist( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    if( p_playlist )
-    {
-        vlclua_push_vlc_object( L, p_playlist, vlclua_gc_release );
-    }
-    else lua_pushnil( L );
-    return 1;
-}
-
-static int vlclua_playlist_prev( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Prev( p_playlist );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_next( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Next( p_playlist );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_skip( lua_State * L )
-{
-    int i_skip = luaL_checkint( L, 1 );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Skip( p_playlist, i_skip );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_play( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Play( p_playlist );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_pause( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Pause( p_playlist );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_stop( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Stop( p_playlist );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_clear( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_Stop( p_playlist ); /* Isn't this already implied by Clear? */
-    playlist_Clear( p_playlist, false );
-    vlc_object_release( p_playlist );
-    return 0;
-}
-
-static int vlclua_playlist_repeat( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "repeat" );
-    vlc_object_release( p_playlist );
-    return i_ret;
-}
-
-static int vlclua_playlist_loop( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "loop" );
-    vlc_object_release( p_playlist );
-    return i_ret;
-}
-
-static int vlclua_playlist_random( lua_State * L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "random" );
-    vlc_object_release( p_playlist );
-    return i_ret;
-}
-
-static int vlclua_playlist_goto( lua_State * L )
-{
-    int i_id = luaL_checkint( L, 1 );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    int i_ret = playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
-                                  true, NULL,
-                                  playlist_ItemGetById( p_playlist, i_id,
-                                                        true ) );
-    vlc_object_release( p_playlist );
-    return vlclua_push_ret( L, i_ret );
-}
-
-static int vlclua_playlist_add( lua_State *L )
-{
-    int i_count;
-    vlc_object_t *p_this = vlclua_get_this( L );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
-                                            NULL, true );
-    vlc_object_release( p_playlist );
-    lua_pushinteger( L, i_count );
-    return 1;
-}
-
-static int vlclua_playlist_enqueue( lua_State *L )
-{
-    int i_count;
-    vlc_object_t *p_this = vlclua_get_this( L );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
-                                            NULL, false );
-    vlc_object_release( p_playlist );
-    lua_pushinteger( L, i_count );
-    return 1;
-}
-
-static void push_playlist_item( lua_State *L, playlist_item_t *p_item );
-static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
-{
-    input_item_t *p_input = p_item->p_input;
-    int i_flags = p_item->i_flags;
-    lua_newtable( L );
-    lua_pushinteger( L, p_item->i_id );
-    lua_setfield( L, -2, "id" );
-    lua_newtable( L );
-#define CHECK_AND_SET_FLAG( name, label ) \
-    if( i_flags & PLAYLIST_ ## name ## _FLAG ) \
-    { \
-        lua_pushboolean( L, 1 ); \
-        lua_setfield( L, -2, #label ); \
-    }
-    CHECK_AND_SET_FLAG( SAVE, save )
-    CHECK_AND_SET_FLAG( SKIP, skip )
-    CHECK_AND_SET_FLAG( DBL, disabled )
-    CHECK_AND_SET_FLAG( RO, ro )
-    CHECK_AND_SET_FLAG( REMOVE, remove )
-    CHECK_AND_SET_FLAG( EXPANDED, expanded )
-#undef CHECK_AND_SET_FLAG
-    lua_setfield( L, -2, "flags" );
-    if( p_input )
-    {
-        lua_pushstring( L, p_input->psz_name );
-        lua_setfield( L, -2, "name" );
-        lua_pushstring( L, p_input->psz_uri );
-        lua_setfield( L, -2, "path" );
-        if( p_input->i_duration < 0 )
-            lua_pushnumber( L, -1 );
-        else
-            lua_pushnumber( L, ((double)p_input->i_duration)*1e-6 );
-        lua_setfield( L, -2, "duration" );
-        lua_pushinteger( L, p_input->i_nb_played );
-        lua_setfield( L, -2, "nb_played" );
-        /* TODO: add (optional) info categories, meta, options, es */
-    }
-    if( p_item->i_children >= 0 )
-    {
-        int i;
-        lua_createtable( L, p_item->i_children, 0 );
-        for( i = 0; i < p_item->i_children; i++ )
-        {
-            push_playlist_item( L, p_item->pp_children[i] );
-            lua_rawseti( L, -2, i+1 );
-        }
-        lua_setfield( L, -2, "children" );
-    }
-}
-
-static int vlclua_playlist_get( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    int b_category = luaL_optboolean( L, 2, 1 ); /* Default to tree playlist (discared when 1st argument is a playlist_item's id) */
-    playlist_item_t *p_item = NULL;
-
-    if( lua_isnumber( L, 1 ) )
-    {
-        int i_id = lua_tointeger( L, 1 );
-        p_item = playlist_ItemGetById( p_playlist, i_id, true );
-        if( !p_item )
-        {
-            vlc_object_release( p_playlist );
-            return 0; /* Should we return an error instead? */
-        }
-    }
-    else if( lua_isstring( L, 1 ) )
-    {
-        const char *psz_what = lua_tostring( L, 1 );
-        if( !strcasecmp( psz_what, "normal" )
-         || !strcasecmp( psz_what, "playlist" ) )
-            p_item = b_category ? p_playlist->p_local_category
-                                : p_playlist->p_local_onelevel;
-        else if( !strcasecmp( psz_what, "ml" )
-              || !strcasecmp( psz_what, "media library" ) )
-            p_item = b_category ? p_playlist->p_ml_category
-                                : p_playlist->p_ml_onelevel;
-        else if( !strcasecmp( psz_what, "root" ) )
-            p_item = b_category ? p_playlist->p_root_category
-                                : p_playlist->p_root_onelevel;
-        else
-        {
-            int i;
-            for( i = 0; i < p_playlist->i_sds; i++ )
-            {
-                if( !strcasecmp( psz_what,
-                                 p_playlist->pp_sds[i]->p_sd->psz_module ) )
-                {
-                    p_item = b_category ? p_playlist->pp_sds[i]->p_cat
-                                        : p_playlist->pp_sds[i]->p_one;
-                    break;
-                }
-            }
-            if( !p_item )
-            {
-                vlc_object_release( p_playlist );
-                return 0; /* Should we return an error instead? */
-            }
-        }
-    }
-    else
-    {
-        p_item = b_category ? p_playlist->p_root_category
-                            : p_playlist->p_root_onelevel;
-    }
-    push_playlist_item( L, p_item );
-    vlc_object_release( p_playlist );
-    return 1;
-}
-
-static int vlclua_playlist_search( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    const char *psz_string = luaL_optstring( L, 1, "" );
-    int b_category = luaL_optboolean( L, 2, 1 ); /* default to category */
-    playlist_item_t *p_item = b_category ? p_playlist->p_root_category
-                                         : p_playlist->p_root_onelevel;
-    playlist_LiveSearchUpdate( p_playlist, p_item, psz_string );
-    push_playlist_item( L, p_item );
-    vlc_object_release( p_playlist );
-    return 1;
-}
-
-static int vlclua_playlist_current( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    lua_pushinteger( L, var_GetInteger( p_playlist, "playlist-current" ) );
-    vlc_object_release( p_playlist );
-    return 1;
-}
-
-static int vlc_sort_key_from_string( const char *psz_name )
-{
-    static const struct
-    {
-        const char *psz_name;
-        int i_key;
-    } pp_keys[] =
-        { { "id", SORT_ID },
-          { "title", SORT_TITLE },
-          { "title nodes first", SORT_TITLE_NODES_FIRST },
-          { "artist", SORT_ARTIST },
-          { "genre", SORT_GENRE },
-          { "random", SORT_RANDOM },
-          { "duration", SORT_DURATION },
-          { "title numeric", SORT_TITLE_NUMERIC },
-          { "album", SORT_ALBUM },
-          { NULL, -1 } };
-    int i;
-    for( i = 0; pp_keys[i].psz_name; i++ )
-    {
-        if( !strcmp( psz_name, pp_keys[i].psz_name ) )
-            return pp_keys[i].i_key;
-    }
-    return -1;
-}
-
-static int vlclua_playlist_sort( lua_State *L )
-{
-    /* allow setting the different sort keys */
-    int i_mode = vlc_sort_key_from_string( luaL_checkstring( L, 1 ) );
-    if( i_mode == -1 )
-        return luaL_error( L, "Invalid search key." );
-    int i_type = luaL_optboolean( L, 2, 0 ) ? ORDER_REVERSE : ORDER_NORMAL;
-    int b_category = luaL_optboolean( L, 3, 1 ); /* default to category */
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_item_t *p_root = b_category ? p_playlist->p_local_category
-                                         : p_playlist->p_local_onelevel;
-    int i_ret = playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
-                                            i_type );
-    vlc_object_release( p_playlist );
-    return vlclua_push_ret( L, i_ret );
-}
-
-/* FIXME: split this in 3 different functions? */
-static int vlclua_playlist_status( lua_State *L )
-{
-    intf_thread_t *p_intf = (intf_thread_t *)vlclua_get_this( L );
-    playlist_t *p_playlist = pl_Yield( p_intf );
-    /*
-    int i_count = 0;
-    lua_settop( L, 0 );*/
-    if( p_playlist->p_input )
-    {
-        /*char *psz_uri =
-            input_item_GetURI( input_GetItem( p_playlist->p_input ) );
-        lua_pushstring( L, psz_uri );
-        free( psz_uri );
-        lua_pushnumber( L, config_GetInt( p_intf, "volume" ) );*/
-        vlc_mutex_lock( &p_playlist->object_lock );
-        switch( p_playlist->status.i_status )
-        {
-            case PLAYLIST_STOPPED:
-                lua_pushstring( L, "stopped" );
-                break;
-            case PLAYLIST_RUNNING:
-                lua_pushstring( L, "playing" );
-                break;
-            case PLAYLIST_PAUSED:
-                lua_pushstring( L, "paused" );
-                break;
-            default:
-                lua_pushstring( L, "unknown" );
-                break;
-        }
-        vlc_mutex_unlock( &p_playlist->object_lock );
-        /*i_count += 3;*/
-    }
-    else
-    {
-        lua_pushstring( L, "stopped" );
-    }
-    vlc_object_release( p_playlist );
-    return 1;
-}
-
-
-static int vlclua_lock_and_wait( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int b_quit = vlc_object_lock_and_wait( p_this );
-    lua_pushboolean( L, b_quit );
-    return 1;
-}
-
-static int vlclua_signal( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vlc_object_signal( p_this );
-    return 0;
-}
-
-static int vlclua_mdate( lua_State *L )
-{
-    lua_pushnumber( L, mdate() );
-    return 1;
-}
-
-static int vlclua_intf_should_die( lua_State *L )
-{
-    intf_thread_t *p_intf = (intf_thread_t*)vlclua_get_this( L );
-    lua_pushboolean( L, intf_ShouldDie( p_intf ) );
-    return 1;
-}
-
-static luaL_Reg p_reg[] =
-{
-    { "input_info", vlclua_input_info },
-    { "is_playing", vlclua_is_playing },
-    { "get_title", vlclua_get_title },
-
-    { "fullscreen", vlclua_fullscreen },
-
-    { "mdate", vlclua_mdate },
-
-    { "module_command", vlclua_module_command },
-    { "libvlc_command", vlclua_libvlc_command },
-
-    { "decode_uri", vlclua_decode_uri },
-    { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
-    { "convert_xml_special_chars", vlclua_convert_xml_special_chars },
-
-    { "lock_and_wait", vlclua_lock_and_wait },
-    { "signal", vlclua_signal },
-
-    { "version", vlclua_version },
-    { "license", vlclua_license },
-    { "copyright", vlclua_copyright },
-    { "should_die", vlclua_intf_should_die },
-    { "quit", vlclua_quit },
-
-    { "homedir", vlclua_homedir },
-    { "datadir", vlclua_datadir },
-    { "configdir", vlclua_configdir },
-    { "cachedir", vlclua_cachedir },
-    { "datadir_list", vlclua_datadir_list },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_object[] =
-{
-    { "input", vlclua_get_input },              /* This is fast */
-    { "playlist", vlclua_get_playlist },        /* This is fast */
-    { "libvlc", vlclua_get_libvlc },            /* This is fast */
-
-    { "find", vlclua_object_find },             /* This is slow */
-    { "find_name", vlclua_object_find_name },   /* This is slow */
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_var[] =
-{
-    { "get", vlclua_var_get },
-    { "get_list", vlclua_var_get_list },
-    { "set", vlclua_var_set },
-    { "add_callback", vlclua_add_callback },
-    { "del_callback", vlclua_del_callback },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_config[] =
-{
-    { "get", vlclua_config_get },
-    { "set", vlclua_config_set },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_msg[] =
-{
-    { "dbg", vlclua_msg_dbg },
-    { "warn", vlclua_msg_warn },
-    { "err", vlclua_msg_err },
-    { "info", vlclua_msg_info },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_playlist[] =
-{
-    { "prev", vlclua_playlist_prev },
-    { "next", vlclua_playlist_next },
-    { "skip", vlclua_playlist_skip },
-    { "play", vlclua_playlist_play },
-    { "pause", vlclua_playlist_pause },
-    { "stop", vlclua_playlist_stop },
-    { "clear", vlclua_playlist_clear },
-    { "repeat_", vlclua_playlist_repeat },
-    { "loop", vlclua_playlist_loop },
-    { "random", vlclua_playlist_random },
-    { "goto", vlclua_playlist_goto },
-    { "status", vlclua_playlist_status },
-    { "add", vlclua_playlist_add },
-    { "enqueue", vlclua_playlist_enqueue },
-    { "get", vlclua_playlist_get },
-    { "search", vlclua_playlist_search },
-    { "sort", vlclua_playlist_sort },
-    { "current", vlclua_playlist_current },
-
-    { "stats", vlclua_input_stats },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_sd[] =
-{
-    { "get_services_names", vlclua_sd_get_services_names },
-    { "add", vlclua_sd_add },
-    { "remove", vlclua_sd_remove },
-    { "is_loaded", vlclua_sd_is_loaded },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_volume[] =
-{
-    { "get", vlclua_volume_get },
-    { "set", vlclua_volume_set },
-    { "up", vlclua_volume_up },
-    { "down", vlclua_volume_down },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_osd[] =
-{
-    { "icon", vlclua_osd_icon },
-    { "message", vlclua_osd_message },
-    { "slider", vlclua_osd_slider },
-    { "channel_register", vlclua_spu_channel_register },
-    { "channel_clear", vlclua_spu_channel_clear },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_net[] =
-{
-    { "url_parse", vlclua_url_parse },
-    { "listen_tcp", vlclua_net_listen_tcp },
-    { "listen_close", vlclua_net_listen_close },
-    { "accept", vlclua_net_accept },
-    { "close", vlclua_net_close },
-    { "send", vlclua_net_send },
-    { "recv", vlclua_net_recv },
-    { "select", vlclua_net_select },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_fd[] =
-{
-/*    { "open", vlclua_fd_open },*/
-    { "read", vlclua_fd_read },
-    { "write", vlclua_fd_write },
-    { "stat", vlclua_stat },
-
-    { "opendir", vlclua_opendir },
-
-    { "new_fd_set", vlclua_fd_set_new },
-    { "fd_clr", vlclua_fd_clr },
-    { "fd_isset", vlclua_fd_isset },
-    { "fd_set", vlclua_fd_set },
-    { "fd_zero", vlclua_fd_zero },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_vlm[] =
-{
-    { "new", vlclua_vlm_new },
-    { "delete", vlclua_vlm_delete },
-    { "execute_command", vlclua_vlm_execute_command },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_httpd[] =
-{
-    { "host_new", vlclua_httpd_tls_host_new },
-    { "host_delete", vlclua_httpd_host_delete },
-    { "handler_new", vlclua_httpd_handler_new },
-    { "handler_delete", vlclua_httpd_handler_delete },
-    { "file_new", vlclua_httpd_file_new },
-    { "file_delete", vlclua_httpd_file_delete },
-    { "redirect_new", vlclua_httpd_redirect_new },
-    { "redirect_delete", vlclua_httpd_redirect_delete },
-
-    { NULL, NULL }
-};
-
-static luaL_Reg p_reg_acl[] =
-{
-    { "create", vlclua_acl_create },
-    { "delete", vlclua_acl_delete },
-    { "check", vlclua_acl_check },
-    { "duplicate", vlclua_acl_duplicate },
-    { "add_host", vlclua_acl_add_host },
-    { "add_net", vlclua_acl_add_net },
-    { "load_file", vlclua_acl_load_file },
-
-    { NULL, NULL }
-};
-
-static void Run( intf_thread_t *p_intf );
-
-static char *FindFile( intf_thread_t *p_intf, const char *psz_name )
+static char *FindFile( const char *psz_name )
 {
     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
     char **ppsz_dir;
-    vlclua_dir_list( VLC_OBJECT(p_intf), "intf", ppsz_dir_list );
+    vlclua_dir_list( "intf", ppsz_dir_list );
     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
     {
         char *psz_filename;
@@ -991,6 +142,8 @@ static const char *GetModuleName( intf_thread_t *p_intf )
     return config_GetPsz( p_intf, "lua-intf" );
 }
 
+static luaL_Reg p_reg[] = { { NULL, NULL } };
+
 int Open_LuaIntf( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
@@ -1008,7 +161,7 @@ int Open_LuaIntf( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
     p_sys = p_intf->p_sys;
-    p_sys->psz_filename = FindFile( p_intf, psz_name );
+    p_sys->psz_filename = FindFile( psz_name );
     if( !p_sys->psz_filename )
     {
         msg_Err( p_intf, "Couldn't find lua interface script \"%s\".",
@@ -1025,27 +178,35 @@ int Open_LuaIntf( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    luaL_openlibs( L ); /* FIXME: we don't want to have all the libs */
+    luaL_openlibs( L );
 
     /* register our functions */
     luaL_register( L, "vlc", p_reg );
-    /* store a pointer to p_intf */
+
+    /* store a pointer to p_intf (FIXME: user could overwrite this) */
     lua_pushlightuserdata( L, p_intf );
     lua_setfield( L, -2, "private" );
+
     /* register submodules */
-    luaL_register_submodule( L, "object", p_reg_object );
-    luaL_register_submodule( L, "var", p_reg_var );
-    luaL_register_submodule( L, "config", p_reg_config );
-    luaL_register_submodule( L, "msg", p_reg_msg );
-    luaL_register_submodule( L, "playlist", p_reg_playlist );
-    luaL_register_submodule( L, "sd", p_reg_sd );
-    luaL_register_submodule( L, "volume", p_reg_volume );
-    luaL_register_submodule( L, "osd", p_reg_osd );
-    luaL_register_submodule( L, "net", p_reg_net );
-    luaL_register_submodule( L, "fd", p_reg_fd );
-    luaL_register_submodule( L, "vlm", p_reg_vlm );
-    luaL_register_submodule( L, "httpd", p_reg_httpd );
-    luaL_register_submodule( L, "acl", p_reg_acl );
+    luaopen_acl( L );
+    luaopen_config( L );
+    luaopen_volume( L );
+    luaopen_httpd( L );
+    luaopen_input( L );
+    luaopen_msg( L );
+    luaopen_misc( L );
+    luaopen_net( L );
+    luaopen_object( L );
+    luaopen_osd( L );
+    luaopen_playlist( L );
+    luaopen_sd( L );
+    luaopen_stream( L );
+    luaopen_strings( L );
+    luaopen_variables( L );
+    luaopen_video( L );
+    luaopen_vlm( L );
+    luaopen_volume( L );
+
     /* clean up */
     lua_pop( L, 1 );
 
diff --git a/modules/misc/lua/libs.h b/modules/misc/lua/libs.h
new file mode 100644 (file)
index 0000000..689025e
--- /dev/null
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * libs.h: VLC Lua wrapper libraries
+ *****************************************************************************
+ * Copyright (C) 2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_LIBS_H
+#define VLC_LUA_LIBS_H
+
+void luaopen_acl( lua_State * );
+void luaopen_config( lua_State * );
+void luaopen_volume( lua_State * );
+void luaopen_httpd( lua_State * );
+void luaopen_input( lua_State * );
+void luaopen_msg( lua_State * );
+void luaopen_misc( lua_State * );
+void luaopen_net( lua_State * );
+void luaopen_object( lua_State * );
+void luaopen_osd( lua_State * );
+void luaopen_playlist( lua_State * );
+void luaopen_sd( lua_State * );
+void luaopen_stream( lua_State * );
+void luaopen_strings( lua_State * );
+void luaopen_variables( lua_State * );
+void luaopen_video( lua_State * );
+void luaopen_vlm( lua_State * );
+void luaopen_volume( lua_State * );
+
+#endif
diff --git a/modules/misc/lua/libs/acl.c b/modules/misc/lua/libs/acl.c
new file mode 100644 (file)
index 0000000..bbe0c86
--- /dev/null
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ * acl.c: Access list related functions
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_acl.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_acl_create_inner( lua_State *, vlc_acl_t * );
+static int vlclua_acl_delete( lua_State * );
+static int vlclua_acl_check( lua_State * );
+static int vlclua_acl_duplicate( lua_State * );
+static int vlclua_acl_add_host( lua_State * );
+static int vlclua_acl_add_net( lua_State * );
+static int vlclua_acl_load_file( lua_State * );
+
+static const luaL_Reg vlclua_acl_reg[] = {
+    { "check", vlclua_acl_check },
+    { "duplicate", vlclua_acl_duplicate },
+    { "add_host", vlclua_acl_add_host },
+    { "add_net", vlclua_acl_add_net },
+    { "load_file", vlclua_acl_load_file },
+    { NULL, NULL }
+};
+
+static int vlclua_acl_create( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    bool b_allow = luaL_checkboolean( L, 1 ) ? true : false;
+    vlc_acl_t *p_acl = ACL_Create( p_this, b_allow );
+    return vlclua_acl_create_inner( L, p_acl );
+}
+
+static int vlclua_acl_create_inner( lua_State *L, vlc_acl_t *p_acl )
+{
+    if( !p_acl )
+        return luaL_error( L, "ACL creation failed." );
+
+    vlc_acl_t **pp_acl = lua_newuserdata( L, sizeof( vlc_acl_t * ) );
+    *pp_acl = p_acl;
+
+    if( luaL_newmetatable( L, "acl" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_acl_reg );
+        lua_setfield( L, -2, "__index" );
+        lua_pushcfunction( L, vlclua_acl_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
+    return 1;
+}
+
+static int vlclua_acl_delete( lua_State *L )
+{
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    ACL_Destroy( *pp_acl );
+    return 0;
+}
+
+static int vlclua_acl_check( lua_State *L )
+{
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    const char *psz_ip = luaL_checkstring( L, 2 );
+    lua_pushinteger( L, ACL_Check( *pp_acl, psz_ip ) );
+    return 1;
+}
+
+static int vlclua_acl_duplicate( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    vlc_acl_t *p_acl_new = ACL_Duplicate( p_this, *pp_acl );
+    return vlclua_acl_create_inner( L, p_acl_new );
+}
+
+static int vlclua_acl_add_host( lua_State *L )
+{
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    const char *psz_ip = luaL_checkstring( L, 2 );
+    bool b_allow = luaL_checkboolean( L, 3 ) ? true : false;
+    lua_pushinteger( L, ACL_AddHost( *pp_acl, psz_ip, b_allow ) );
+    return 1;
+}
+
+static int vlclua_acl_add_net( lua_State *L )
+{
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    const char *psz_ip = luaL_checkstring( L, 2 );
+    int i_len = luaL_checkint( L, 3 );
+    bool b_allow = luaL_checkboolean( L, 4 ) ? true : false;
+    lua_pushinteger( L, ACL_AddNet( *pp_acl, psz_ip, i_len, b_allow ) );
+    return 1;
+}
+
+static int vlclua_acl_load_file( lua_State *L )
+{
+    vlc_acl_t **pp_acl = (vlc_acl_t**)luaL_checkudata( L, 1, "acl" );
+    const char *psz_path = luaL_checkstring( L, 2 );
+    lua_pushinteger( L, ACL_LoadFile( *pp_acl, psz_path ) );
+    return 1;
+}
+
+void luaopen_acl( lua_State *L )
+{
+    lua_pushcfunction( L, vlclua_acl_create );
+    lua_setfield( L, -2, "acl" );
+}
similarity index 84%
rename from modules/misc/lua/configuration.c
rename to modules/misc/lua/libs/configuration.c
index d003b2e7176bb24bdd47c4fd17773fe7eba3a015..1ef90acc57c36d393eb157a85a63fc43831a123b 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * configuration.c: Generic lua<->vlc config interface
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
 
 /*****************************************************************************
  * Config handling
  *****************************************************************************/
-int vlclua_config_get( lua_State *L )
+static int vlclua_config_get( lua_State *L )
 {
     vlc_object_t * p_this = vlclua_get_this( L );
     const char *psz_name;
@@ -76,7 +76,7 @@ int vlclua_config_get( lua_State *L )
     return 1;
 }
 
-int vlclua_config_set( lua_State *L )
+static int vlclua_config_set( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
     const char *psz_name;
@@ -108,3 +108,19 @@ int vlclua_config_set( lua_State *L )
     }
     return 0;
 }
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_config_reg[] = {
+    { "get", vlclua_config_get },
+    { "set", vlclua_config_set },
+    { NULL, NULL }
+};
+
+void luaopen_config( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_config_reg );
+    lua_setfield( L, -2, "config" );
+}
similarity index 70%
rename from modules/misc/lua/httpd.c
rename to modules/misc/lua/libs/httpd.c
index 5538b799b1036b642e45bb46295ab2aa7eb0d23e..09ca8a4ec47e8cacb5eea92c09d842814091b789 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * httpd.c: HTTPd wrapper
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #include <lauxlib.h>    /* Higher level C API */
 #include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
 static uint8_t *vlclua_todata( lua_State *L, int narg, int *i_data );
 
+static int vlclua_httpd_host_delete( lua_State * );
+static int vlclua_httpd_handler_new( lua_State * );
+static int vlclua_httpd_handler_delete( lua_State * );
+static int vlclua_httpd_file_new( lua_State * );
+static int vlclua_httpd_file_delete( lua_State * );
+static int vlclua_httpd_redirect_new( lua_State * );
+static int vlclua_httpd_redirect_delete( lua_State * );
+
 /*****************************************************************************
  * HTTPD Host
  *****************************************************************************/
-#if 0
-/* This is kind of a useless function since TLS with the 4 last args
- * unset does the same thing as far as I know. */
-int vlclua_httpd_host_new( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    const char *psz_host = luaL_checkstring( L, 1 );
-    int i_port = luaL_checkint( L, 2 );
-    httpd_host_t *p_httpd_host = httpd_HostNew( p_this, psz_host, i_port );
-    if( !p_httpd_host )
-        return luaL_error( L, "Failed to create HTTP host \"%s:%d\".",
-                           psz_host, i_port );
-    vlclua_push_vlc_object( L, p_httpd_host, vlclua_httpd_host_delete );
-    return 1;
-}
-#endif
+static const luaL_Reg vlclua_httpd_reg[] = {
+    { "handler", vlclua_httpd_handler_new },
+    { "file", vlclua_httpd_file_new },
+    { "redirect", vlclua_httpd_redirect_new },
+    { NULL, NULL }
+};
 
-int vlclua_httpd_tls_host_new( lua_State *L )
+static int vlclua_httpd_tls_host_new( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
     const char *psz_host = luaL_checkstring( L, 1 );
@@ -75,24 +74,35 @@ int vlclua_httpd_tls_host_new( lua_State *L )
     const char *psz_key = luaL_optstring( L, 4, NULL );
     const char *psz_ca = luaL_optstring( L, 5, NULL );
     const char *psz_crl = luaL_optstring( L, 6, NULL );
-    httpd_host_t *p_httpd_host = httpd_TLSHostNew( p_this, psz_host, i_port,
+    httpd_host_t *p_host = httpd_TLSHostNew( p_this, psz_host, i_port,
                                                    psz_cert, psz_key,
                                                    psz_ca, psz_crl );
-    if( !p_httpd_host )
+    if( !p_host )
         return luaL_error( L, "Failed to create HTTP TLS host \"%s:%d\" "
                            "(cert: \"%s\", key: \"%s\", ca: \"%s\", "
                            "crl: \"%s\").", psz_host, i_port,
                            psz_cert, psz_key, psz_ca, psz_crl );
-    vlclua_push_vlc_object( L, (vlc_object_t*)p_httpd_host, vlclua_httpd_host_delete );
+
+    httpd_host_t **pp_host = lua_newuserdata( L, sizeof( httpd_host_t * ) );
+    *pp_host = p_host;
+
+    if( luaL_newmetatable( L, "httpd_host" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_httpd_reg );
+        lua_setfield( L, -2, "__index" );
+        lua_pushcfunction( L, vlclua_httpd_host_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-#define ARG_1_IS_HTTPD_HOST httpd_host_t *p_httpd_host = \
-    (httpd_host_t*)vlclua_checkobject( L, 1, VLC_OBJECT_HTTPD_HOST );
-int vlclua_httpd_host_delete( lua_State *L )
+static int vlclua_httpd_host_delete( lua_State *L )
 {
-    ARG_1_IS_HTTPD_HOST
-    httpd_HostDelete( p_httpd_host );
+    httpd_host_t **pp_host = (httpd_host_t **)luaL_checkudata( L, 1, "httpd_host" );
+    httpd_HostDelete( *pp_host );
     return 0;
 }
 
@@ -148,13 +158,13 @@ static int vlclua_httpd_handler_callback(
     return VLC_SUCCESS;
 }
 
-int vlclua_httpd_handler_new( lua_State * L )
+static int vlclua_httpd_handler_new( lua_State * L )
 {
-    ARG_1_IS_HTTPD_HOST
+    httpd_host_t **pp_host = (httpd_host_t **)luaL_checkudata( L, 1, "httpd_host" );
     const char *psz_url = luaL_checkstring( L, 2 );
     const char *psz_user = luaL_nilorcheckstring( L, 3 );
     const char *psz_password = luaL_nilorcheckstring( L, 4 );
-    const vlc_acl_t *p_acl = NULL; /* FIXME 5 */
+    const vlc_acl_t *p_acl = lua_isnil( L, 5 ) ? NULL : luaL_checkudata( L, 5, "acl" );
     /* Stack item 6 is the callback function */
     luaL_argcheck( L, lua_isfunction( L, 6 ), 6, "Should be a function" );
     /* Stack item 7 is the callback data */
@@ -169,18 +179,31 @@ int vlclua_httpd_handler_new( lua_State * L )
      * the callback's stack. */
     lua_xmove( L, p_sys->L, 2 );
     httpd_handler_t *p_handler = httpd_HandlerNew(
-                            p_httpd_host, psz_url, psz_user, psz_password,
+                            *pp_host, psz_url, psz_user, psz_password,
                             p_acl, vlclua_httpd_handler_callback, p_sys );
     if( !p_handler )
+    {
+        free( p_sys );
         return luaL_error( L, "Failed to create HTTPd handler." );
-    lua_pushlightuserdata( L, p_handler ); /* FIXME */
+    }
+
+    httpd_handler_t **pp_handler = lua_newuserdata( L, sizeof( httpd_handler_t * ) );
+    *pp_handler = p_handler;
+
+    if( luaL_newmetatable( L, "httpd_handler" ) )
+    {
+        lua_pushcfunction( L, vlclua_httpd_handler_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-int vlclua_httpd_handler_delete( lua_State *L )
+static int vlclua_httpd_handler_delete( lua_State *L )
 {
-    httpd_handler_t *p_handler = (httpd_handler_t*)luaL_checklightuserdata( L, 1 ); /* FIXME */
-    httpd_handler_sys_t *p_sys = httpd_HandlerDelete( p_handler );
+    httpd_handler_t **pp_handler = (httpd_handler_t**)luaL_checkudata( L, 1, "httpd_handler" );
+    httpd_handler_sys_t *p_sys = httpd_HandlerDelete( *pp_handler );
     luaL_unref( p_sys->L, LUA_REGISTRYINDEX, p_sys->ref );
     free( p_sys );
     return 0;
@@ -226,14 +249,14 @@ static int vlclua_httpd_file_callback(
     return VLC_SUCCESS;
 }
 
-int vlclua_httpd_file_new( lua_State *L )
+static int vlclua_httpd_file_new( lua_State *L )
 {
-    ARG_1_IS_HTTPD_HOST
+    httpd_host_t **pp_host = (httpd_host_t **)luaL_checkudata( L, 1, "httpd_host" );
     const char *psz_url = luaL_checkstring( L, 2 );
     const char *psz_mime = luaL_nilorcheckstring( L, 3 );
     const char *psz_user = luaL_nilorcheckstring( L, 4 );
     const char *psz_password = luaL_nilorcheckstring( L, 5 );
-    const vlc_acl_t *p_acl = lua_isnil( L, 6 ) ? NULL : luaL_checklightuserdata( L, 6 );
+    const vlc_acl_t *p_acl = lua_isnil( L, 6 ) ? NULL : luaL_checkudata( L, 6, "acl" );
     /* Stack item 7 is the callback function */
     luaL_argcheck( L, lua_isfunction( L, 7 ), 7, "Should be a function" );
     /* Stack item 8 is the callback data */
@@ -244,20 +267,32 @@ int vlclua_httpd_file_new( lua_State *L )
     p_sys->L = lua_newthread( L );
     p_sys->ref = luaL_ref( L, LUA_REGISTRYINDEX ); /* pops the object too */
     lua_xmove( L, p_sys->L, 2 );
-    httpd_file_t *p_file = httpd_FileNew( p_httpd_host, psz_url, psz_mime,
+    httpd_file_t *p_file = httpd_FileNew( *pp_host, psz_url, psz_mime,
                                           psz_user, psz_password, p_acl,
                                           vlclua_httpd_file_callback, p_sys );
     if( !p_file )
+    {
+        free( p_sys );
         return luaL_error( L, "Failed to create HTTPd file." );
-    lua_pushlightuserdata( L, p_file ); /* FIXME */
+    }
+
+    httpd_file_t **pp_file = lua_newuserdata( L, sizeof( httpd_file_t * ) );
+    *pp_file = p_file;
+
+    if( luaL_newmetatable( L, "httpd_file" ) )
+    {
+        lua_pushcfunction( L, vlclua_httpd_file_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-int vlclua_httpd_file_delete( lua_State *L )
+static int vlclua_httpd_file_delete( lua_State *L )
 {
-    httpd_file_t *p_file = (httpd_file_t*)luaL_checklightuserdata( L, 1 ); /* FIXME */
-    /* FIXME: How do we delete p_sys ? the struct is hidden in the VLC core */
-    httpd_file_sys_t *p_sys = httpd_FileDelete( p_file );
+    httpd_file_t **pp_file = (httpd_file_t**)luaL_checkudata( L, 1, "httpd_file" );
+    httpd_file_sys_t *p_sys = httpd_FileDelete( *pp_file );
     luaL_unref( p_sys->L, LUA_REGISTRYINDEX, p_sys->ref );
     free( p_sys );
     return 0;
@@ -266,24 +301,34 @@ int vlclua_httpd_file_delete( lua_State *L )
 /*****************************************************************************
  * HTTPd Redirect
  *****************************************************************************/
-int vlclua_httpd_redirect_new( lua_State *L )
+static int vlclua_httpd_redirect_new( lua_State *L )
 {
-    ARG_1_IS_HTTPD_HOST
+    httpd_host_t **pp_host = (httpd_host_t **)luaL_checkudata( L, 1, "httpd_host" );
     const char *psz_url_dst = luaL_checkstring( L, 2 );
     const char *psz_url_src = luaL_checkstring( L, 3 );
-    httpd_redirect_t *p_redirect = httpd_RedirectNew( p_httpd_host,
+    httpd_redirect_t *p_redirect = httpd_RedirectNew( *pp_host,
                                                       psz_url_dst,
                                                       psz_url_src );
     if( !p_redirect )
         return luaL_error( L, "Failed to create HTTPd redirect." );
-    lua_pushlightuserdata( L, p_redirect ); /* FIXME */
+
+    httpd_redirect_t **pp_redirect = lua_newuserdata( L, sizeof( httpd_redirect_t * ) );
+    *pp_redirect = p_redirect;
+
+    if( luaL_newmetatable( L, "httpd_redirect" ) )
+    {
+        lua_pushcfunction( L, vlclua_httpd_redirect_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-int vlclua_httpd_redirect_delete( lua_State *L )
+static int vlclua_httpd_redirect_delete( lua_State *L )
 {
-    httpd_redirect_t *p_redirect = (httpd_redirect_t*)luaL_checklightuserdata( L, 1 ); /* FIXME */
-    httpd_RedirectDelete( p_redirect );
+    httpd_redirect_t **pp_redirect = (httpd_redirect_t**)luaL_checkudata( L, 1, "httpd_redirect" );
+    httpd_RedirectDelete( *pp_redirect );
     return 0;
 }
 
@@ -304,3 +349,12 @@ static uint8_t *vlclua_todata( lua_State *L, int narg, int *pi_data )
     memcpy( p_data, psz_data, i_data );
     return p_data;
 }
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void luaopen_httpd( lua_State *L )
+{
+    lua_pushcfunction( L, vlclua_httpd_tls_host_new );
+    lua_setfield( L, -2, "httpd" );
+}
diff --git a/modules/misc/lua/libs/input.c b/modules/misc/lua/libs/input.c
new file mode 100644 (file)
index 0000000..650b99a
--- /dev/null
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * input.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+
+#include <vlc_playlist.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "input.h"
+#include "playlist.h"
+#include "../vlc.h"
+#include "../libs.h"
+
+input_thread_t * vlclua_get_input_internal( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    input_thread_t *p_input = p_playlist->p_input;
+    if( p_input ) vlc_object_yield( p_input );
+    vlc_object_release( p_playlist );
+    return p_input;
+}
+
+static int vlclua_input_info( lua_State *L )
+{
+    input_thread_t * p_input = vlclua_get_input_internal( L );
+    int i_cat;
+    int i;
+    if( !p_input ) return vlclua_error( L );
+    //vlc_mutex_lock( &input_GetItem(p_input)->lock );
+    i_cat = input_GetItem(p_input)->i_categories;
+    lua_createtable( L, 0, i_cat );
+    for( i = 0; i < i_cat; i++ )
+    {
+        info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
+        int i_infos = p_category->i_infos;
+        int j;
+        lua_pushstring( L, p_category->psz_name );
+        lua_createtable( L, 0, i_infos );
+        for( j = 0; j < i_infos; j++ )
+        {
+            info_t *p_info = p_category->pp_infos[j];
+            lua_pushstring( L, p_info->psz_name );
+            lua_pushstring( L, p_info->psz_value );
+            lua_settable( L, -3 );
+        }
+        lua_settable( L, -3 );
+    }
+    //vlc_object_release( p_input );
+    return 1;
+}
+
+static int vlclua_is_playing( lua_State *L )
+{
+    input_thread_t * p_input = vlclua_get_input_internal( L );
+    lua_pushboolean( L, !!p_input );
+    return 1;
+}
+
+static int vlclua_get_title( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( !p_input )
+        lua_pushnil( L );
+    else
+    {
+        lua_pushstring( L, input_GetItem(p_input)->psz_name );
+        vlc_object_release( p_input );
+    }
+    return 1;
+}
+
+static int vlclua_input_stats( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    input_item_t *p_item = p_input && p_input->p ? input_GetItem( p_input ) : NULL;
+    lua_newtable( L );
+    if( p_item )
+    {
+#define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
+                       lua_setfield( L, -2, #n );
+#define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
+                         lua_setfield( L, -2, #n );
+        STATS_INT( read_bytes )
+        STATS_FLOAT( input_bitrate )
+        STATS_INT( demux_read_bytes )
+        STATS_FLOAT( demux_bitrate )
+        STATS_INT( decoded_video )
+        STATS_INT( displayed_pictures )
+        STATS_INT( lost_pictures )
+        STATS_INT( decoded_audio )
+        STATS_INT( played_abuffers )
+        STATS_INT( lost_abuffers )
+        STATS_INT( sent_packets )
+        STATS_INT( sent_bytes )
+        STATS_FLOAT( send_bitrate )
+#undef STATS_INT
+#undef STATS_FLOAT
+    }
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_input_reg[] = {
+    { "info", vlclua_input_info },
+    { "is_playing", vlclua_is_playing },
+    { "get_title", vlclua_get_title },
+    { "stats", vlclua_input_stats },
+    { NULL, NULL }
+};
+
+void luaopen_input( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_input_reg );
+    lua_setfield( L, -2, "input" );
+}
diff --git a/modules/misc/lua/libs/input.h b/modules/misc/lua/libs/input.h
new file mode 100644 (file)
index 0000000..dbe76df
--- /dev/null
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * input.h
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_INPUT_H
+#define VLC_LUA_INPUT_H
+
+input_thread_t * vlclua_get_input_internal( lua_State * );
+
+#endif
diff --git a/modules/misc/lua/libs/messages.c b/modules/misc/lua/libs/messages.c
new file mode 100644 (file)
index 0000000..5d3dce0
--- /dev/null
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * messages.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+#include <vlc_aout.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+#include <lualib.h>     /* Lua libs */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * Messaging facilities
+ *****************************************************************************/
+static int vlclua_msg_dbg( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+        msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
+    return 0;
+}
+
+static int vlclua_msg_warn( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+        msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
+    return 0;
+}
+
+static int vlclua_msg_err( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+        msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
+    return 0;
+}
+
+static int vlclua_msg_info( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+        msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
+    return 0;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_msg_reg[] = {
+    { "dbg", vlclua_msg_dbg },
+    { "warn", vlclua_msg_warn },
+    { "err", vlclua_msg_err },
+    { "info", vlclua_msg_info },
+    { NULL, NULL }
+};
+
+void luaopen_msg( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_msg_reg );
+    lua_setfield( L, -2, "msg" );
+}
diff --git a/modules/misc/lua/libs/misc.c b/modules/misc/lua/libs/misc.c
new file mode 100644 (file)
index 0000000..2f8a5b5
--- /dev/null
@@ -0,0 +1,222 @@
+/*****************************************************************************
+ * misc.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+#include <vlc_aout.h>
+#include <vlc_interface.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+#include <lualib.h>     /* Lua libs */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * Internal lua<->vlc utils
+ *****************************************************************************/
+vlc_object_t * vlclua_get_this( lua_State *L )
+{
+    vlc_object_t * p_this;
+    lua_getglobal( L, "vlc" );
+    lua_getfield( L, -1, "private" );
+    p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) );
+    lua_pop( L, 2 );
+    return p_this;
+}
+
+/*****************************************************************************
+ * VLC error code translation
+ *****************************************************************************/
+int vlclua_push_ret( lua_State *L, int i_error )
+{
+    lua_pushnumber( L, i_error );
+    lua_pushstring( L, vlc_error( i_error ) );
+    return 2;
+}
+
+/*****************************************************************************
+ * Get the VLC version string
+ *****************************************************************************/
+static int vlclua_version( lua_State *L )
+{
+    lua_pushstring( L, VLC_Version() );
+    return 1;
+}
+
+/*****************************************************************************
+ * Get the VLC copyright
+ *****************************************************************************/
+static int vlclua_copyright( lua_State *L )
+{
+    lua_pushstring( L, COPYRIGHT_MESSAGE );
+    return 1;
+}
+
+/*****************************************************************************
+ * Get the VLC license msg/disclaimer
+ *****************************************************************************/
+static int vlclua_license( lua_State *L )
+{
+    lua_pushstring( L, LICENSE_MSG );
+    return 1;
+}
+
+/*****************************************************************************
+ * Quit VLC
+ *****************************************************************************/
+static int vlclua_quit( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    /* The rc.c code also stops the playlist ... not sure if this is needed
+     * though. */
+    vlc_object_kill( p_this->p_libvlc );
+    return 0;
+}
+
+/*****************************************************************************
+ * Global properties getters
+ *****************************************************************************/
+static int vlclua_datadir( lua_State *L )
+{
+    lua_pushstring( L, config_GetDataDir() );
+    return 1;
+}
+
+static int vlclua_homedir( lua_State *L )
+{
+    lua_pushstring( L, config_GetHomeDir() );
+    return 1;
+}
+
+static int vlclua_configdir( lua_State *L )
+{
+    char *dir = config_GetUserConfDir();
+    lua_pushstring( L, dir );
+    free( dir );
+    return 1;
+}
+
+static int vlclua_cachedir( lua_State *L )
+{
+    char *dir = config_GetCacheDir();
+    lua_pushstring( L, dir );
+    free( dir );
+    return 1;
+}
+
+static int vlclua_datadir_list( lua_State *L )
+{
+    const char *psz_dirname = luaL_checkstring( L, 1 );
+    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
+    char **ppsz_dir = ppsz_dir_list;
+    int i = 1;
+
+    if( vlclua_dir_list( psz_dirname, ppsz_dir_list ) != VLC_SUCCESS )
+        return 0;
+    lua_newtable( L );
+    for( ; *ppsz_dir; ppsz_dir++ )
+    {
+        lua_pushstring( L, *ppsz_dir );
+        lua_rawseti( L, -2, i );
+        i ++;
+    }
+    return 1;
+}
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_lock_and_wait( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int b_quit = vlc_object_lock_and_wait( p_this );
+    lua_pushboolean( L, b_quit );
+    return 1;
+}
+
+static int vlclua_signal( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    vlc_object_signal( p_this );
+    return 0;
+}
+
+static int vlclua_mdate( lua_State *L )
+{
+    lua_pushnumber( L, mdate() );
+    return 1;
+}
+
+static int vlclua_intf_should_die( lua_State *L )
+{
+    intf_thread_t *p_intf = (intf_thread_t*)vlclua_get_this( L );
+    lua_pushboolean( L, intf_ShouldDie( p_intf ) );
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_misc_reg[] = {
+    { "version", vlclua_version },
+    { "copyright", vlclua_copyright },
+    { "license", vlclua_license },
+
+    { "datadir", vlclua_datadir },
+    { "homedir", vlclua_homedir },
+    { "configdir", vlclua_configdir },
+    { "cachedir", vlclua_cachedir },
+    { "datadir_list", vlclua_datadir_list },
+
+    { "mdate", vlclua_mdate },
+
+    { "lock_and_wait", vlclua_lock_and_wait },
+    { "signal", vlclua_signal },
+
+    { "should_die", vlclua_intf_should_die },
+    { "quit", vlclua_quit },
+
+    { NULL, NULL }
+};
+
+void luaopen_misc( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_misc_reg );
+    lua_setfield( L, -2, "misc" );
+}
diff --git a/modules/misc/lua/libs/misc.h b/modules/misc/lua/libs/misc.h
new file mode 100644 (file)
index 0000000..67a386e
--- /dev/null
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * misc.h
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_MISC_H
+#define VLC_LUA_MISC_H
+
+vlc_object_t * vlclua_get_this( lua_State * );
+
+int vlclua_push_ret( lua_State *, int );
+
+#endif
+
similarity index 62%
rename from modules/misc/lua/net.c
rename to modules/misc/lua/libs/net.c
index 73a4c4b646b324933eb568fb95a5ee94f1e7dbf3..f9210b54441e7487f443468fcb0f0cfe892c4762 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * net.c: Network related functions
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
 
 /*****************************************************************************
  *
  *****************************************************************************/
-int vlclua_url_parse( lua_State *L )
+static int vlclua_url_parse( lua_State *L )
 {
     const char *psz_url = luaL_checkstring( L, 1 );
     const char *psz_option = luaL_optstring( L, 2, NULL );
@@ -74,7 +74,18 @@ int vlclua_url_parse( lua_State *L )
     return 1;
 }
 
-int vlclua_net_listen_tcp( lua_State *L )
+/*****************************************************************************
+ * Net listen
+ *****************************************************************************/
+static int vlclua_net_listen_close( lua_State * );
+static int vlclua_net_accept( lua_State * );
+
+static const luaL_Reg vlclua_net_listen_reg[] = {
+    { "accept", vlclua_net_accept },
+    { NULL, NULL }
+};
+
+static int vlclua_net_listen_tcp( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
     const char *psz_host = luaL_checkstring( L, 1 );
@@ -82,35 +93,51 @@ int vlclua_net_listen_tcp( lua_State *L )
     int *pi_fd = net_ListenTCP( p_this, psz_host, i_port );
     if( pi_fd == NULL )
         return luaL_error( L, "Cannot listen on %s:%d", psz_host, i_port );
-    lua_pushlightuserdata( L, pi_fd );
+
+    int **ppi_fd = lua_newuserdata( L, sizeof( int * ) );
+    *ppi_fd = pi_fd;
+
+    if( luaL_newmetatable( L, "net_listen" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_net_listen_reg );
+        lua_setfield( L, -2, "__index" );
+        lua_pushcfunction( L, vlclua_net_listen_close );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-int vlclua_net_listen_close( lua_State *L )
+static int vlclua_net_listen_close( lua_State *L )
 {
-    int *pi_fd = (int*)luaL_checklightuserdata( L, 1 );
-    net_ListenClose( pi_fd );
+    int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
+    net_ListenClose( *ppi_fd );
     return 0;
 }
 
-int vlclua_net_accept( lua_State *L )
+static int vlclua_net_accept( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
-    int *pi_fd = (int*)luaL_checklightuserdata( L, 1 );
+    int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
     mtime_t i_wait = luaL_optint( L, 2, -1 ); /* default to block */
-    int i_fd = net_Accept( p_this, pi_fd, i_wait );
+    int i_fd = net_Accept( p_this, *ppi_fd, i_wait );
     lua_pushinteger( L, i_fd );
     return 1;
 }
 
-int vlclua_net_close( lua_State *L )
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_net_close( lua_State *L )
 {
     int i_fd = luaL_checkint( L, 1 );
     net_Close( i_fd );
     return 0;
 }
 
-int vlclua_net_send( lua_State *L )
+static int vlclua_net_send( lua_State *L )
 {
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len;
@@ -121,7 +148,7 @@ int vlclua_net_send( lua_State *L )
     return 1;
 }
 
-int vlclua_net_recv( lua_State *L )
+static int vlclua_net_recv( lua_State *L )
 {
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len = luaL_optint( L, 2, 1 );
@@ -131,12 +158,15 @@ int vlclua_net_recv( lua_State *L )
     return 1;
 }
 
-int vlclua_net_select( lua_State *L )
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_net_select( lua_State *L )
 {
     int i_ret;
     size_t i_nfds = luaL_checkint( L, 1 );
-    fd_set *fds_read = (fd_set*)luaL_checkuserdata( L, 2, sizeof( fd_set ) );
-    fd_set *fds_write = (fd_set*)luaL_checkuserdata( L, 3, sizeof( fd_set ) );
+    fd_set *fds_read = (fd_set*)luaL_checkudata( L, 2, "fd_set" );
+    fd_set *fds_write = (fd_set*)luaL_checkudata( L, 3, "fd_set" );
     double f_timeout = luaL_checknumber( L, 4 );
     struct timeval timeout;
 
@@ -152,30 +182,57 @@ int vlclua_net_select( lua_State *L )
     return 2;
 }
 
-int vlclua_fd_set_new( lua_State *L )
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_fd_clr( lua_State * );
+static int vlclua_fd_isset( lua_State * );
+static int vlclua_fd_set( lua_State * );
+static int vlclua_fd_zero( lua_State * );
+
+static const luaL_Reg vlclua_fd_set_reg[] = {
+    { "clr", vlclua_fd_clr },
+    { "isset", vlclua_fd_isset },
+    { "set", vlclua_fd_set },
+    { "zero", vlclua_fd_zero },
+    { NULL, NULL }
+};
+
+static int vlclua_fd_set_new( lua_State *L )
 {
     fd_set *fds = (fd_set*)lua_newuserdata( L, sizeof( fd_set ) );
     FD_ZERO( fds );
+
+    if( luaL_newmetatable( L, "fd_set" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_fd_set_reg );
+        lua_setfield( L, -2, "__index" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
 }
 
-int vlclua_fd_clr( lua_State *L )
+static int vlclua_fd_clr( lua_State *L )
 {
-    fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
+    fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
     int i_fd = luaL_checkint( L, 2 );
     FD_CLR( i_fd, fds );
     return 0;
 }
-int vlclua_fd_isset( lua_State *L )
+
+static int vlclua_fd_isset( lua_State *L )
 {
-    fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
+    fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
     int i_fd = luaL_checkint( L, 2 );
     lua_pushboolean( L, FD_ISSET( i_fd, fds ) );
     return 1;
 }
-int vlclua_fd_set( lua_State *L )
+
+static int vlclua_fd_set( lua_State *L )
 {
-    fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
+    fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
     size_t i_fd = luaL_checkint( L, 2 );
     /* FIXME: we should really use poll() instead here, but that breaks the
      * VLC/LUA API. On Windows, overflow protection is built-in FD_SET, not
@@ -186,20 +243,24 @@ int vlclua_fd_set( lua_State *L )
         FD_SET( i_fd, fds );
     return 0;
 }
-int vlclua_fd_zero( lua_State *L )
+
+static int vlclua_fd_zero( lua_State *L )
 {
-    fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
+    fd_set *fds = (fd_set*)luaL_checkudata( L, 1, "fd_set" );
     FD_ZERO( fds );
     return 0;
 }
 
+/*****************************************************************************
+ *
+ *****************************************************************************/
 /*
-int vlclua_fd_open( lua_State *L )
+static int vlclua_fd_open( lua_State *L )
 {
 }
 */
 
-int vlclua_fd_write( lua_State *L )
+static int vlclua_fd_write( lua_State *L )
 {
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len;
@@ -211,7 +272,7 @@ int vlclua_fd_write( lua_State *L )
     return 1;
 }
 
-int vlclua_fd_read( lua_State *L )
+static int vlclua_fd_read( lua_State *L )
 {
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len = luaL_optint( L, 2, 1 );
@@ -221,7 +282,10 @@ int vlclua_fd_read( lua_State *L )
     return 1;
 }
 
-int vlclua_stat( lua_State *L )
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int vlclua_stat( lua_State *L )
 {
 #ifdef HAVE_SYS_STAT_H
     const char *psz_path = luaL_checkstring( L, 1 );
@@ -278,7 +342,7 @@ int vlclua_stat( lua_State *L )
 #endif
 }
 
-int vlclua_opendir( lua_State *L )
+static int vlclua_opendir( lua_State *L )
 {
     const char *psz_dir = luaL_checkstring( L, 1 );
     DIR *p_dir;
@@ -300,3 +364,28 @@ int vlclua_opendir( lua_State *L )
     closedir( p_dir );
     return 1;
 }
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_net_reg[] = {
+    { "url_parse", vlclua_url_parse },
+    { "listen_tcp", vlclua_net_listen_tcp },
+    { "close", vlclua_net_close },
+    { "send", vlclua_net_send },
+    { "recv", vlclua_net_recv },
+    { "select", vlclua_net_select },
+    { "fd_set_new", vlclua_fd_set_new },
+    { "fd_read", vlclua_fd_read },
+    { "fd_write", vlclua_fd_write },
+    { "stat", vlclua_stat }, /* Not really "net" */
+    { "opendir", vlclua_opendir }, /* Not really "net" */
+    { NULL, NULL }
+};
+
+void luaopen_net( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_net_reg );
+    lua_setfield( L, -2, "net" );
+}
similarity index 69%
rename from modules/misc/lua/objects.c
rename to modules/misc/lua/libs/objects.c
index c492d5a8f30538c1b847b3ee788c3393d4058230..f5c2f2f3e48bfa2f1ccf886b08add930575be3fd 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * objects.c: Generic lua<->vlc object wrapper
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
+#include "objects.h"
+#include "playlist.h"
+#include "input.h"
 
 typedef struct
 {
@@ -51,20 +54,21 @@ typedef struct
 int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
                               lua_CFunction pf_gc )
 {
-    vlclua_object_t *p_ud = (vlclua_object_t *)
-        lua_newuserdata( L, sizeof( vlclua_object_t ) );
-    p_ud->p_obj = p_obj;
-    lua_newtable( L );
-    /* Hide the metatable */
-    lua_pushstring( L, "__metatable" );
-    lua_pushstring( L, "none of your business" );
-    lua_settable( L, -3 );
-    if( pf_gc )
+    vlc_object_t **udata = (vlc_object_t **)
+        lua_newuserdata( L, sizeof( vlc_object_t * ) );
+    *udata = p_obj;
+
+    if( luaL_newmetatable( L, "vlc_object" ) )
     {
-        /* Set the garbage collector if needed */
-        lua_pushstring( L, "__gc" );
-        lua_pushcfunction( L, pf_gc );
-        lua_settable( L, -3 );
+        /* Hide the metatable */
+        lua_pushstring( L, "none of your business" );
+        lua_setfield( L, -2, "__metatable" );
+        if( pf_gc ) /* FIXME */
+        {
+            /* Set the garbage collector if needed */
+            lua_pushcfunction( L, pf_gc );
+            lua_setfield( L, -2, "__gc" );
+        }
     }
     lua_setmetatable( L, -2 );
     return 1;
@@ -72,34 +76,12 @@ int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
 
 int vlclua_gc_release( lua_State *L )
 {
-    vlclua_object_t *p_ud = (vlclua_object_t *)lua_touserdata( L, -1 );
+    vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
     lua_pop( L, 1 );
-    vlc_object_release( p_ud->p_obj );
+    vlc_object_release( *p_obj );
     return 0;
 }
 
-vlc_object_t *vlclua_checkobject( lua_State *L, int narg, int i_type )
-{
-    vlclua_object_t *p_obj = (vlclua_object_t *)luaL_checkuserdata( L, narg, sizeof( vlclua_object_t ) );
-    /* TODO: add some metatable based method to check that this isn't
-     * any userdata, but really some vlc object */
-    if( i_type )
-    {
-        if( p_obj->p_obj->i_object_type == i_type )
-            return p_obj->p_obj;
-        else
-        {
-            luaL_error( L, "VLC object type doesn't match requirements." );
-            return NULL; /* luaL_error alread longjmp-ed out of here.
-                          * This is to make gcc happy */
-        }
-    }
-    else
-    {
-        return p_obj->p_obj;
-    }
-}
-
 static int vlc_object_type_from_string( const char *psz_name )
 {
     static const struct
@@ -125,6 +107,7 @@ static int vlc_object_type_from_string( const char *psz_name )
           { VLC_OBJECT_FILTER, "filter" },
           { VLC_OBJECT_OSDMENU, "osdmenu" },
           { VLC_OBJECT_HTTPD_HOST, "httpd_host" },
+          { VLC_OBJECT_INTERACTION, "interaction" },
           { VLC_OBJECT_GENERIC, "generic" },
           { 0, "" } };
     int i;
@@ -156,7 +139,7 @@ static int vlc_object_search_mode_from_string( const char *psz_name )
     return 0;
 }
 
-int vlclua_object_find( lua_State *L )
+static int vlclua_object_find( lua_State *L )
 {
     const char *psz_type = luaL_checkstring( L, 2 );
     const char *psz_mode = luaL_checkstring( L, 3 );
@@ -174,7 +157,10 @@ int vlclua_object_find( lua_State *L )
     if( lua_type( L, 1 ) == LUA_TNIL )
         p_this = vlclua_get_this( L );
     else
-        p_this = vlclua_checkobject( L, 1, 0 );
+    {
+        vlc_object_t **p_obj = luaL_checkudata( L, 1, "vlc_object" );
+        p_this = *p_obj;
+    }
 
     p_result = vlc_object_find( p_this, i_type, i_mode );
     if( !p_result )
@@ -184,7 +170,7 @@ int vlclua_object_find( lua_State *L )
     return 1;
 }
 
-int vlclua_object_find_name( lua_State *L )
+static int vlclua_object_find_name( lua_State *L )
 {
     const char *psz_name = luaL_checkstring( L, 2 );
     const char *psz_mode = luaL_checkstring( L, 3 );
@@ -200,7 +186,10 @@ int vlclua_object_find_name( lua_State *L )
     if( lua_type( L, 1 ) == LUA_TNIL )
         p_this = vlclua_get_this( L );
     else
-        p_this = vlclua_checkobject( L, 1, 0 );
+    {
+        vlc_object_t **p_obj = luaL_checkudata( L, 1, "vlc_object" );
+        p_this = *p_obj;
+    }
 
     p_result = vlc_object_find_name( p_this, psz_name, i_mode );
     if( !p_result )
@@ -209,3 +198,51 @@ int vlclua_object_find_name( lua_State *L )
         vlclua_push_vlc_object( L, p_result, vlclua_gc_release );
     return 1;
 }
+
+static int vlclua_get_libvlc( lua_State *L )
+{
+    vlclua_push_vlc_object( L, vlclua_get_this( L )->p_libvlc,
+                            NULL );
+    return 1;
+}
+
+static int vlclua_get_playlist( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    if( p_playlist )
+    {
+        vlclua_push_vlc_object( L, p_playlist, vlclua_gc_release );
+    }
+    else lua_pushnil( L );
+    return 1;
+}
+
+static int vlclua_get_input( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
+    {
+        vlclua_push_vlc_object( L, p_input, vlclua_gc_release );
+    }
+    else lua_pushnil( L );
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_object_reg[] = {
+    { "input", vlclua_get_input },
+    { "playlist", vlclua_get_playlist },
+    { "libvlc", vlclua_get_libvlc },
+    { "find", vlclua_object_find },
+    { "find_name", vlclua_object_find_name },
+    { NULL, NULL }
+};
+
+void luaopen_object( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_object_reg );
+    lua_setfield( L, -2, "object" );
+}
diff --git a/modules/misc/lua/libs/objects.h b/modules/misc/lua/libs/objects.h
new file mode 100644 (file)
index 0000000..cc91fab
--- /dev/null
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * objects.c: Generic lua<->vlc object wrapper
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_OBJECTS_H
+#define VLC_LUA_OBJECTS_H
+
+int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
+                              lua_CFunction pf_gc );
+#define vlclua_push_vlc_object( a, b, c ) \
+        __vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
+int vlclua_gc_release( lua_State *L );
+
+#endif
+
diff --git a/modules/misc/lua/libs/osd.c b/modules/misc/lua/libs/osd.c
new file mode 100644 (file)
index 0000000..c0a43cc
--- /dev/null
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * intf.c: Generic lua interface functions
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_vout.h>
+#include <vlc_osd.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * OSD
+ *****************************************************************************/
+static int vlc_osd_icon_from_string( const char *psz_name )
+{
+    static const struct
+    {
+        int i_icon;
+        const char *psz_name;
+    } pp_icons[] =
+        { { OSD_PAUSE_ICON, "pause" },
+          { OSD_PLAY_ICON, "play" },
+          { OSD_SPEAKER_ICON, "speaker" },
+          { OSD_MUTE_ICON, "mute" },
+          { 0, NULL } };
+    int i;
+    for( i = 0; pp_icons[i].psz_name; i++ )
+    {
+        if( !strcmp( psz_name, pp_icons[i].psz_name ) )
+            return pp_icons[i].i_icon;
+    }
+    return 0;
+}
+
+static int vlclua_osd_icon( lua_State *L )
+{
+    const char *psz_icon = luaL_checkstring( L, 1 );
+    int i_icon = vlc_osd_icon_from_string( psz_icon );
+    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
+    if( !i_icon )
+        return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
+    else
+    {
+        vlc_object_t *p_this = vlclua_get_this( L );
+        vout_OSDIcon( p_this, i_chan, i_icon );
+        return 0;
+    }
+}
+
+static int vlclua_osd_message( lua_State *L )
+{
+    const char *psz_message = luaL_checkstring( L, 1 );
+    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    vout_OSDMessage( p_this, i_chan, psz_message );
+    return 0;
+}
+
+static int vlc_osd_slider_type_from_string( const char *psz_name )
+{
+    static const struct
+    {
+        int i_type;
+        const char *psz_name;
+    } pp_types[] =
+        { { OSD_HOR_SLIDER, "horizontal" },
+          { OSD_VERT_SLIDER, "vertical" },
+          { 0, NULL } };
+    int i;
+    for( i = 0; pp_types[i].psz_name; i++ )
+    {
+        if( !strcmp( psz_name, pp_types[i].psz_name ) )
+            return pp_types[i].i_type;
+    }
+    return 0;
+}
+
+static int vlclua_osd_slider( lua_State *L )
+{
+    int i_position = luaL_checkint( L, 1 );
+    const char *psz_type = luaL_checkstring( L, 2 );
+    int i_type = vlc_osd_slider_type_from_string( psz_type );
+    int i_chan = luaL_optint( L, 3, DEFAULT_CHAN );
+    if( !i_type )
+        return luaL_error( L, "\"%s\" is not a valid slider type.",
+                           psz_type );
+    else
+    {
+        vlc_object_t *p_this = vlclua_get_this( L );
+        vout_OSDSlider( p_this, i_chan, i_position, i_type );
+        return 0;
+    }
+}
+
+static int vlclua_spu_channel_register( lua_State *L )
+{
+    int i_chan;
+    vlc_object_t *p_this = vlclua_get_this( L );
+    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
+                                             FIND_ANYWHERE );
+    if( !p_vout )
+        return luaL_error( L, "Unable to find vout." );
+
+    spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER, &i_chan );
+    vlc_object_release( p_vout );
+    lua_pushinteger( L, i_chan );
+    return 1;
+}
+
+static int vlclua_spu_channel_clear( lua_State *L )
+{
+    int i_chan = luaL_checkint( L, 1 );
+    vlc_object_t *p_this = vlclua_get_this( L );
+    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
+                                             FIND_ANYWHERE );
+    if( !p_vout )
+        return luaL_error( L, "Unable to find vout." );
+
+    spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, i_chan );
+    vlc_object_release( p_vout );
+    return 0;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_osd_reg[] = {
+    { "icon", vlclua_osd_icon },
+    { "message", vlclua_osd_message },
+    { "slider", vlclua_osd_slider },
+    { "channel_register", vlclua_spu_channel_register },
+    { "channel_clear", vlclua_spu_channel_clear },
+    { NULL, NULL }
+};
+
+void luaopen_osd( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_osd_reg );
+    lua_setfield( L, -2, "osd" );
+}
diff --git a/modules/misc/lua/libs/playlist.c b/modules/misc/lua/libs/playlist.c
new file mode 100644 (file)
index 0000000..5f16040
--- /dev/null
@@ -0,0 +1,422 @@
+/*****************************************************************************
+ * playlist.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+#include <vlc_interface.h>
+#include <vlc_playlist.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+#include "playlist.h"
+#include "variables.h"
+
+/*****************************************************************************
+ * Internal lua<->vlc utils
+ *****************************************************************************/
+playlist_t *vlclua_get_playlist_internal( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    return pl_Yield( p_this );
+}
+
+static int vlclua_playlist_prev( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Prev( p_playlist );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_next( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Next( p_playlist );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_skip( lua_State * L )
+{
+    int i_skip = luaL_checkint( L, 1 );
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Skip( p_playlist, i_skip );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_play( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Play( p_playlist );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_pause( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Pause( p_playlist );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_stop( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Stop( p_playlist );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_clear( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_Stop( p_playlist ); /* Isn't this already implied by Clear? */
+    playlist_Clear( p_playlist, false );
+    vlc_object_release( p_playlist );
+    return 0;
+}
+
+static int vlclua_playlist_repeat( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "repeat" );
+    vlc_object_release( p_playlist );
+    return i_ret;
+}
+
+static int vlclua_playlist_loop( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "loop" );
+    vlc_object_release( p_playlist );
+    return i_ret;
+}
+
+static int vlclua_playlist_random( lua_State * L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "random" );
+    vlc_object_release( p_playlist );
+    return i_ret;
+}
+
+static int vlclua_playlist_goto( lua_State * L )
+{
+    int i_id = luaL_checkint( L, 1 );
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    int i_ret = playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
+                                  true, NULL,
+                                  playlist_ItemGetById( p_playlist, i_id,
+                                                        true ) );
+    vlc_object_release( p_playlist );
+    return vlclua_push_ret( L, i_ret );
+}
+
+static int vlclua_playlist_add( lua_State *L )
+{
+    int i_count;
+    vlc_object_t *p_this = vlclua_get_this( L );
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
+                                            NULL, true );
+    vlc_object_release( p_playlist );
+    lua_pushinteger( L, i_count );
+    return 1;
+}
+
+static int vlclua_playlist_enqueue( lua_State *L )
+{
+    int i_count;
+    vlc_object_t *p_this = vlclua_get_this( L );
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
+                                            NULL, false );
+    vlc_object_release( p_playlist );
+    lua_pushinteger( L, i_count );
+    return 1;
+}
+
+static void push_playlist_item( lua_State *L, playlist_item_t *p_item );
+static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
+{
+    input_item_t *p_input = p_item->p_input;
+    int i_flags = p_item->i_flags;
+    lua_newtable( L );
+    lua_pushinteger( L, p_item->i_id );
+    lua_setfield( L, -2, "id" );
+    lua_newtable( L );
+#define CHECK_AND_SET_FLAG( name, label ) \
+    if( i_flags & PLAYLIST_ ## name ## _FLAG ) \
+    { \
+        lua_pushboolean( L, 1 ); \
+        lua_setfield( L, -2, #label ); \
+    }
+    CHECK_AND_SET_FLAG( SAVE, save )
+    CHECK_AND_SET_FLAG( SKIP, skip )
+    CHECK_AND_SET_FLAG( DBL, disabled )
+    CHECK_AND_SET_FLAG( RO, ro )
+    CHECK_AND_SET_FLAG( REMOVE, remove )
+    CHECK_AND_SET_FLAG( EXPANDED, expanded )
+#undef CHECK_AND_SET_FLAG
+    lua_setfield( L, -2, "flags" );
+    if( p_input )
+    {
+        lua_pushstring( L, p_input->psz_name );
+        lua_setfield( L, -2, "name" );
+        lua_pushstring( L, p_input->psz_uri );
+        lua_setfield( L, -2, "path" );
+        if( p_input->i_duration < 0 )
+            lua_pushnumber( L, -1 );
+        else
+            lua_pushnumber( L, ((double)p_input->i_duration)*1e-6 );
+        lua_setfield( L, -2, "duration" );
+        lua_pushinteger( L, p_input->i_nb_played );
+        lua_setfield( L, -2, "nb_played" );
+        /* TODO: add (optional) info categories, meta, options, es */
+    }
+    if( p_item->i_children >= 0 )
+    {
+        int i;
+        lua_createtable( L, p_item->i_children, 0 );
+        for( i = 0; i < p_item->i_children; i++ )
+        {
+            push_playlist_item( L, p_item->pp_children[i] );
+            lua_rawseti( L, -2, i+1 );
+        }
+        lua_setfield( L, -2, "children" );
+    }
+}
+
+static int vlclua_playlist_get( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    int b_category = luaL_optboolean( L, 2, 1 ); /* Default to tree playlist (discared when 1st argument is a playlist_item's id) */
+    playlist_item_t *p_item = NULL;
+
+    if( lua_isnumber( L, 1 ) )
+    {
+        int i_id = lua_tointeger( L, 1 );
+        p_item = playlist_ItemGetById( p_playlist, i_id, true );
+        if( !p_item )
+        {
+            vlc_object_release( p_playlist );
+            return 0; /* Should we return an error instead? */
+        }
+    }
+    else if( lua_isstring( L, 1 ) )
+    {
+        const char *psz_what = lua_tostring( L, 1 );
+        if( !strcasecmp( psz_what, "normal" )
+         || !strcasecmp( psz_what, "playlist" ) )
+            p_item = b_category ? p_playlist->p_local_category
+                                : p_playlist->p_local_onelevel;
+        else if( !strcasecmp( psz_what, "ml" )
+              || !strcasecmp( psz_what, "media library" ) )
+            p_item = b_category ? p_playlist->p_ml_category
+                                : p_playlist->p_ml_onelevel;
+        else if( !strcasecmp( psz_what, "root" ) )
+            p_item = b_category ? p_playlist->p_root_category
+                                : p_playlist->p_root_onelevel;
+        else
+        {
+            int i;
+            for( i = 0; i < p_playlist->i_sds; i++ )
+            {
+                if( !strcasecmp( psz_what,
+                                 p_playlist->pp_sds[i]->p_sd->psz_module ) )
+                {
+                    p_item = b_category ? p_playlist->pp_sds[i]->p_cat
+                                        : p_playlist->pp_sds[i]->p_one;
+                    break;
+                }
+            }
+            if( !p_item )
+            {
+                vlc_object_release( p_playlist );
+                return 0; /* Should we return an error instead? */
+            }
+        }
+    }
+    else
+    {
+        p_item = b_category ? p_playlist->p_root_category
+                            : p_playlist->p_root_onelevel;
+    }
+    push_playlist_item( L, p_item );
+    vlc_object_release( p_playlist );
+    return 1;
+}
+
+static int vlclua_playlist_search( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    const char *psz_string = luaL_optstring( L, 1, "" );
+    int b_category = luaL_optboolean( L, 2, 1 ); /* default to category */
+    playlist_item_t *p_item = b_category ? p_playlist->p_root_category
+                                         : p_playlist->p_root_onelevel;
+    playlist_LiveSearchUpdate( p_playlist, p_item, psz_string );
+    push_playlist_item( L, p_item );
+    vlc_object_release( p_playlist );
+    return 1;
+}
+
+static int vlclua_playlist_current( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    lua_pushinteger( L, var_GetInteger( p_playlist, "playlist-current" ) );
+    vlc_object_release( p_playlist );
+    return 1;
+}
+
+static int vlc_sort_key_from_string( const char *psz_name )
+{
+    static const struct
+    {
+        const char *psz_name;
+        int i_key;
+    } pp_keys[] =
+        { { "id", SORT_ID },
+          { "title", SORT_TITLE },
+          { "title nodes first", SORT_TITLE_NODES_FIRST },
+          { "artist", SORT_ARTIST },
+          { "genre", SORT_GENRE },
+          { "random", SORT_RANDOM },
+          { "duration", SORT_DURATION },
+          { "title numeric", SORT_TITLE_NUMERIC },
+          { "album", SORT_ALBUM },
+          { NULL, -1 } };
+    int i;
+    for( i = 0; pp_keys[i].psz_name; i++ )
+    {
+        if( !strcmp( psz_name, pp_keys[i].psz_name ) )
+            return pp_keys[i].i_key;
+    }
+    return -1;
+}
+
+static int vlclua_playlist_sort( lua_State *L )
+{
+    /* allow setting the different sort keys */
+    int i_mode = vlc_sort_key_from_string( luaL_checkstring( L, 1 ) );
+    if( i_mode == -1 )
+        return luaL_error( L, "Invalid search key." );
+    int i_type = luaL_optboolean( L, 2, 0 ) ? ORDER_REVERSE : ORDER_NORMAL;
+    int b_category = luaL_optboolean( L, 3, 1 ); /* default to category */
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    playlist_item_t *p_root = b_category ? p_playlist->p_local_category
+                                         : p_playlist->p_local_onelevel;
+    int i_ret = playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
+                                            i_type );
+    vlc_object_release( p_playlist );
+    return vlclua_push_ret( L, i_ret );
+}
+
+/* FIXME: split this in 3 different functions? */
+static int vlclua_playlist_status( lua_State *L )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)vlclua_get_this( L );
+    playlist_t *p_playlist = pl_Yield( p_intf );
+    /*
+    int i_count = 0;
+    lua_settop( L, 0 );*/
+    if( p_playlist->p_input )
+    {
+        /*char *psz_uri =
+            input_item_GetURI( input_GetItem( p_playlist->p_input ) );
+        lua_pushstring( L, psz_uri );
+        free( psz_uri );
+        lua_pushnumber( L, config_GetInt( p_intf, "volume" ) );*/
+        vlc_mutex_lock( &p_playlist->object_lock );
+        switch( p_playlist->status.i_status )
+        {
+            case PLAYLIST_STOPPED:
+                lua_pushstring( L, "stopped" );
+                break;
+            case PLAYLIST_RUNNING:
+                lua_pushstring( L, "playing" );
+                break;
+            case PLAYLIST_PAUSED:
+                lua_pushstring( L, "paused" );
+                break;
+            default:
+                lua_pushstring( L, "unknown" );
+                break;
+        }
+        vlc_mutex_unlock( &p_playlist->object_lock );
+        /*i_count += 3;*/
+    }
+    else
+    {
+        lua_pushstring( L, "stopped" );
+    }
+    vlc_object_release( p_playlist );
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_playlist_reg[] = {
+    { "prev", vlclua_playlist_prev },
+    { "next", vlclua_playlist_next },
+    { "skip", vlclua_playlist_skip },
+    { "play", vlclua_playlist_play },
+    { "pause", vlclua_playlist_pause },
+    { "stop", vlclua_playlist_stop },
+    { "clear", vlclua_playlist_clear },
+    { "repeat", vlclua_playlist_repeat },
+    { "loop", vlclua_playlist_loop },
+    { "random", vlclua_playlist_random },
+    { "goto", vlclua_playlist_goto },
+    { "add", vlclua_playlist_add },
+    { "enqueue", vlclua_playlist_enqueue },
+    { "get", vlclua_playlist_get },
+    { "search", vlclua_playlist_search },
+    { "current", vlclua_playlist_current },
+    { "sort", vlclua_playlist_sort },
+    { "status", vlclua_playlist_status },
+    { NULL, NULL }
+};
+
+void luaopen_playlist( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_playlist_reg );
+    lua_setfield( L, -2, "playlist" );
+}
diff --git a/modules/misc/lua/libs/playlist.h b/modules/misc/lua/libs/playlist.h
new file mode 100644 (file)
index 0000000..5015c4c
--- /dev/null
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * playlist.h
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_PLAYLIST_H
+#define VLC_LUA_PLAYLIST_H
+
+playlist_t *vlclua_get_playlist_internal( lua_State * );
+
+#endif
+
similarity index 79%
rename from modules/misc/lua/sd.c
rename to modules/misc/lua/libs/sd.c
index eb159d07ea1e943df0996d22e591d79a60e32f29..205fe92e8691796f39faf2fc3d2a390e07003277 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * sd.c: Services discovery related functions
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #include <lauxlib.h>    /* Higher level C API */
 #include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
+#include "playlist.h"
 
 /*****************************************************************************
  *
  *****************************************************************************/
-int vlclua_sd_get_services_names( lua_State *L )
+static int vlclua_sd_get_services_names( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
     char **ppsz_longnames;
@@ -69,7 +71,7 @@ int vlclua_sd_get_services_names( lua_State *L )
     return 1;
 }
 
-int vlclua_sd_add( lua_State *L )
+static int vlclua_sd_add( lua_State *L )
 {
     const char *psz_sd = luaL_checkstring( L, 1 );
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
@@ -78,7 +80,7 @@ int vlclua_sd_add( lua_State *L )
     return vlclua_push_ret( L, i_ret );
 }
 
-int vlclua_sd_remove( lua_State *L )
+static int vlclua_sd_remove( lua_State *L )
 {
     const char *psz_sd = luaL_checkstring( L, 1 );
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
@@ -87,7 +89,7 @@ int vlclua_sd_remove( lua_State *L )
     return vlclua_push_ret( L, i_ret );
 }
 
-int vlclua_sd_is_loaded( lua_State *L )
+static int vlclua_sd_is_loaded( lua_State *L )
 {
     const char *psz_sd = luaL_checkstring( L, 1 );
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
@@ -95,3 +97,21 @@ int vlclua_sd_is_loaded( lua_State *L )
     vlc_object_release( p_playlist );
     return 1;
 }
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_sd_reg[] = {
+    { "get_services_names", vlclua_sd_get_services_names },
+    { "add", vlclua_sd_add },
+    { "remove", vlclua_sd_remove },
+    { "is_loaded", vlclua_sd_is_loaded },
+    { NULL, NULL }
+};
+
+void luaopen_sd( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_sd_reg );
+    lua_setfield( L, -2, "sd" );
+}
diff --git a/modules/misc/lua/libs/stream.c b/modules/misc/lua/libs/stream.c
new file mode 100644 (file)
index 0000000..5e8cb81
--- /dev/null
@@ -0,0 +1,128 @@
+/*****************************************************************************
+ * stream.c: stream functions
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+#include <vlc_aout.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * Stream handling
+ *****************************************************************************/
+static int vlclua_stream_read( lua_State * );
+static int vlclua_stream_readline( lua_State * );
+static int vlclua_stream_delete( lua_State * );
+
+static const luaL_Reg vlclua_stream_reg[] = {
+    { "read", vlclua_stream_read },
+    { "readline", vlclua_stream_readline },
+    { NULL, NULL }
+};
+
+static int vlclua_stream_new( lua_State *L )
+{
+    vlc_object_t * p_this = vlclua_get_this( L );
+    stream_t * p_stream;
+    const char * psz_url;
+    psz_url = luaL_checkstring( L, -1 );
+    p_stream = stream_UrlNew( p_this, psz_url );
+    if( !p_stream )
+        return luaL_error( L, "Error when opening url: `%s'", psz_url );
+
+    stream_t **pp_stream = lua_newuserdata( L, sizeof( stream_t * ) );
+    *pp_stream = p_stream;
+
+    if( luaL_newmetatable( L, "stream" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_stream_reg );
+        lua_setfield( L, -2, "__index" );
+        lua_pushcfunction( L, vlclua_stream_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
+    return 1;
+}
+
+static int vlclua_stream_read( lua_State *L )
+{
+    int i_read;
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    int n = luaL_checkint( L, 2 );
+    uint8_t *p_read = malloc( n );
+    if( !p_read ) return vlclua_error( L );
+    i_read = stream_Read( *pp_stream, p_read, n );
+    lua_pushlstring( L, (const char *)p_read, i_read );
+    free( p_read );
+    return 1;
+}
+
+static int vlclua_stream_readline( lua_State *L )
+{
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    char *psz_line = stream_ReadLine( *pp_stream );
+    if( psz_line )
+    {
+        lua_pushstring( L, psz_line );
+        free( psz_line );
+    }
+    else
+        lua_pushnil( L );
+    return 1;
+}
+
+static int vlclua_stream_delete( lua_State *L )
+{
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    stream_Delete( *pp_stream );
+    return 0;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void luaopen_stream( lua_State *L )
+{
+    lua_pushcfunction( L, vlclua_stream_new );
+    lua_setfield( L, -2, "stream" );
+}
diff --git a/modules/misc/lua/libs/strings.c b/modules/misc/lua/libs/strings.c
new file mode 100644 (file)
index 0000000..f1a1f3d
--- /dev/null
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * strings.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+#include <vlc_aout.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * String transformations
+ *****************************************************************************/
+static int vlclua_decode_uri( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+    {
+        const char *psz_cstring = luaL_checkstring( L, 1 );
+        char *psz_string = strdup( psz_cstring );
+        lua_remove( L, 1 ); /* remove elements to prevent being limited by
+                             * the stack's size (this function will work with
+                             * up to (stack size - 1) arguments */
+        decode_URI( psz_string );
+        lua_pushstring( L, psz_string );
+        free( psz_string );
+    }
+    return i_top;
+}
+
+static int vlclua_resolve_xml_special_chars( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+    {
+        const char *psz_cstring = luaL_checkstring( L, 1 );
+        char *psz_string = strdup( psz_cstring );
+        lua_remove( L, 1 ); /* remove elements to prevent being limited by
+                             * the stack's size (this function will work with
+                             * up to (stack size - 1) arguments */
+        resolve_xml_special_chars( psz_string );
+        lua_pushstring( L, psz_string );
+        free( psz_string );
+    }
+    return i_top;
+}
+
+static int vlclua_convert_xml_special_chars( lua_State *L )
+{
+    int i_top = lua_gettop( L );
+    int i;
+    for( i = 1; i <= i_top; i++ )
+    {
+        char *psz_string = convert_xml_special_chars( luaL_checkstring(L,1) );
+        lua_remove( L, 1 );
+        lua_pushstring( L, psz_string );
+        free( psz_string );
+    }
+    return i_top;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_strings_reg[] = {
+    { "decode_uri", vlclua_decode_uri },
+    { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
+    { "convert_xml_special_chars", vlclua_convert_xml_special_chars },
+    { NULL, NULL }
+};
+
+void luaopen_strings( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_strings_reg );
+    lua_setfield( L, -2, "strings" );
+}
similarity index 56%
rename from modules/misc/lua/callbacks.c
rename to modules/misc/lua/libs/variables.c
index 0a9b6cf490c97ee68b8839d1c3e04843b97b2293..a0b1a6a1fad922492b5f16792553963304ebbb1b 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * callbacks.c: Generic lua<->vlc callbacks interface
+ * variables.c: Generic lua<->vlc variables interface
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #include <lauxlib.h>    /* Higher level C API */
 #include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
+#include "variables.h"
+#include "objects.h"
+
+/*****************************************************************************
+ * Variables handling
+ *****************************************************************************/
+int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val )
+{
+    switch( i_type &= 0xf0 )
+    {
+        case VLC_VAR_VOID:
+            vlclua_error( L );
+            break;
+        case VLC_VAR_BOOL:
+            lua_pushboolean( L, val.b_bool );
+            break;
+        case VLC_VAR_INTEGER:
+            lua_pushinteger( L, val.i_int );
+            break;
+        case VLC_VAR_STRING:
+            lua_pushstring( L, val.psz_string );
+            break;
+        case VLC_VAR_FLOAT:
+            lua_pushnumber( L, val.f_float );
+            break;
+        case VLC_VAR_TIME:
+            /* FIXME? (we're losing some precision, but does it really matter?) */
+            lua_pushnumber( L, ((double)val.i_time)/1000000. );
+            break;
+        case VLC_VAR_ADDRESS:
+            vlclua_error( L );
+            break;
+        case VLC_VAR_MUTEX:
+            vlclua_error( L );
+            break;
+        case VLC_VAR_LIST:
+            {
+                int i_count = val.p_list->i_count;
+                int i;
+                lua_createtable( L, i_count, 0 );
+                for( i = 0; i < i_count; i++ )
+                {
+                    lua_pushinteger( L, i+1 );
+                    if( !vlclua_pushvalue( L, val.p_list->pi_types[i],
+                                           val.p_list->p_values[i] ) )
+                        lua_pushnil( L );
+                    lua_settable( L, -3 );
+                }
+            }
+            break;
+        default:
+            vlclua_error( L );
+    }
+    return 1;
+}
+
+static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
+{
+    switch( i_type & 0xf0 )
+    {
+        case VLC_VAR_VOID:
+            break;
+        case VLC_VAR_BOOL:
+            val->b_bool = luaL_checkboolean( L, -1 );
+            break;
+        case VLC_VAR_INTEGER:
+            val->i_int = luaL_checkint( L, -1 );
+            break;
+        case VLC_VAR_STRING:
+            val->psz_string = (char*)luaL_checkstring( L, -1 ); /* XXX: Beware, this only stays valid as long as (L,-1) stays in the stack */
+            break;
+        case VLC_VAR_FLOAT:
+            val->f_float = luaL_checknumber( L, -1 );
+            break;
+        case VLC_VAR_TIME:
+            {
+                double f = luaL_checknumber( L, -1 );
+                val->i_time = (int64_t)(f*1000000.);
+            }
+            break;
+        case VLC_VAR_ADDRESS:
+            vlclua_error( L );
+            break;
+        case VLC_VAR_MUTEX:
+            vlclua_error( L );
+            break;
+        case VLC_VAR_LIST:
+            vlclua_error( L );
+            break;
+        default:
+            vlclua_error( L );
+    }
+    return 1;
+}
+
+static int vlclua_var_get( lua_State *L )
+{
+    int i_type;
+    vlc_value_t val;
+    vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
+    const char *psz_var = luaL_checkstring( L, 2 );
+    i_type = var_Type( *pp_obj, psz_var );
+    var_Get( *pp_obj, psz_var, &val );
+    lua_pop( L, 2 );
+    return vlclua_pushvalue( L, i_type, val );
+}
+
+static int vlclua_var_set( lua_State *L )
+{
+    int i_type;
+    vlc_value_t val;
+    vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
+    const char *psz_var = luaL_checkstring( L, 2 );
+    int i_ret;
+    i_type = var_Type( *pp_obj, psz_var );
+    vlclua_tovalue( L, i_type, &val );
+    i_ret = var_Set( *pp_obj, psz_var, val );
+    lua_pop( L, 3 );
+    return vlclua_push_ret( L, i_ret );
+}
+
+static int vlclua_var_get_list( lua_State *L )
+{
+    vlc_value_t val;
+    vlc_value_t text;
+    vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
+    const char *psz_var = luaL_checkstring( L, 2 );
+    int i_ret = var_Change( *pp_obj, psz_var, VLC_VAR_GETLIST, &val, &text );
+    if( i_ret < 0 ) return vlclua_push_ret( L, i_ret );
+    vlclua_pushvalue( L, VLC_VAR_LIST, val );
+    vlclua_pushvalue( L, VLC_VAR_LIST, text );
+    var_Change( *pp_obj, psz_var, VLC_VAR_FREELIST, &val, &text );
+    return 2;
+}
+
+static int vlclua_command( lua_State *L )
+{
+    vlc_object_t * p_this = vlclua_get_this( L );
+    const char *psz_name;
+    const char *psz_cmd;
+    const char *psz_arg;
+    char *psz_msg;
+    psz_name = luaL_checkstring( L, 1 );
+    psz_cmd = luaL_checkstring( L, 2 );
+    psz_arg = luaL_checkstring( L, 3 );
+    lua_pop( L, 3 );
+    var_Command( p_this, psz_name, psz_cmd, psz_arg, &psz_msg );
+    if( psz_msg )
+    {
+        lua_pushstring( L, psz_msg );
+        free( psz_msg );
+    }
+    else
+    {
+        lua_pushstring( L, "" );
+    }
+    return 1;
+}
+
+static int vlclua_libvlc_command( lua_State *L )
+{
+    vlc_object_t * p_this = vlclua_get_this( L );
+    const char *psz_cmd;
+    vlc_value_t val_arg;
+    psz_cmd = luaL_checkstring( L, 1 );
+    val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
+    lua_pop( L, 2 );
+    if( !var_Type( p_this->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
+    {
+        free( val_arg.psz_string );
+        return luaL_error( L, "libvlc's \"%s\" is not a command",
+                           psz_cmd );
+    }
+
+    return vlclua_push_ret( L,
+                            var_Set( p_this->p_libvlc, psz_cmd, val_arg ) );
+}
+
+int __vlclua_var_toggle_or_set( lua_State *L, vlc_object_t *p_obj,
+                                const char *psz_name )
+{
+    bool b_bool;
+    if( lua_gettop( L ) > 1 ) return vlclua_error( L );
+
+    if( lua_gettop( L ) == 0 )
+        b_bool = !var_GetBool( p_obj, psz_name );
+    else /* lua_gettop( L ) == 1 */
+    {
+        b_bool = luaL_checkboolean( L, -1 )?true:false;
+        lua_pop( L, 1 );
+    }
+
+    if( b_bool != var_GetBool( p_obj, psz_name ) )
+        var_SetBool( p_obj, psz_name, b_bool );
+
+    lua_pushboolean( L, b_bool );
+    return 1;
+}
+
+static inline const void *luaL_checklightuserdata( lua_State *L, int narg )
+{
+    luaL_checktype( L, narg, LUA_TLIGHTUSERDATA ); /* can raise an error */
+    return lua_topointer( L, narg );
+}
 
 typedef struct
 {
@@ -97,11 +302,11 @@ static int vlclua_callback( vlc_object_t *p_this, char const *psz_var,
     return VLC_SUCCESS;
 }
 
-int vlclua_add_callback( lua_State *L )
+static int vlclua_add_callback( lua_State *L )
 {
     vlclua_callback_t *p_callback;
     static int i_index = 0;
-    vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
+    vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
     const char *psz_var = luaL_checkstring( L, 2 );
     lua_settop( L, 4 ); /* makes sure that optional data arg is set */
     if( !lua_isfunction( L, 3 ) )
@@ -142,7 +347,7 @@ int vlclua_add_callback( lua_State *L )
     /* obj var callbacks index cbtable func */
     lua_setfield( L, -2, "callback" );
     /* obj var callbacks index cbtable */
-    lua_pushlightuserdata( L, p_obj ); /* will be needed in vlclua_del_callback */
+    lua_pushlightuserdata( L, *pp_obj ); /* will be needed in vlclua_del_callback */
     /* obj var callbacks index cbtable p_obj */
     lua_setfield( L, -2, "private1" );
     /* obj var callbacks index cbtable */
@@ -162,18 +367,18 @@ int vlclua_add_callback( lua_State *L )
     /* Do not move this before the lua specific code (it somehow changes
      * the function in the stack to nil) */
     p_callback->i_index = i_index;
-    p_callback->i_type = var_Type( p_obj, psz_var );
+    p_callback->i_type = var_Type( *pp_obj, psz_var );
     p_callback->L = lua_newthread( L ); /* Do we have to keep a reference to this thread somewhere to prevent garbage collection? */
 
-    var_AddCallback( p_obj, psz_var, vlclua_callback, p_callback );
+    var_AddCallback( *pp_obj, psz_var, vlclua_callback, p_callback );
     return 0;
 }
 
-int vlclua_del_callback( lua_State *L )
+static int vlclua_del_callback( lua_State *L )
 {
     vlclua_callback_t *p_callback;
     bool b_found = false;
-    vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
+    vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
     const char *psz_var = luaL_checkstring( L, 2 );
     lua_settop( L, 4 ); /* makes sure that optional data arg is set */
     if( !lua_isfunction( L, 3 ) )
@@ -217,7 +422,7 @@ int vlclua_del_callback( lua_State *L )
                         lua_getfield( L, -1, "private1" );
                         /* obj var func data callbacks index value private1 */
                         p_obj2 = (vlc_object_t*)luaL_checklightuserdata( L, -1 );
-                        if( p_obj2 == p_obj ) /* object is equal */
+                        if( p_obj2 == *pp_obj ) /* object is equal */
                         {
                             lua_pop( L, 1 );
                             /* obj var func data callbacks index value */
@@ -267,7 +472,7 @@ int vlclua_del_callback( lua_State *L )
     /* else */
         /* obj var func data callbacks index*/
 
-    var_DelCallback( p_obj, psz_var, vlclua_callback, p_callback );
+    var_DelCallback( *pp_obj, psz_var, vlclua_callback, p_callback );
     free( p_callback );
 
     /* obj var func data callbacks index */
@@ -279,3 +484,24 @@ int vlclua_del_callback( lua_State *L )
     /* <empty stack> */
     return 0;
 }
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_var_reg[] = {
+    { "get", vlclua_var_get },
+    { "get_list", vlclua_var_get_list },
+    { "set", vlclua_var_set },
+    { "add_callback", vlclua_add_callback },
+    { "del_callback", vlclua_del_callback },
+    { "command", vlclua_command },
+    { "libvlc_command", vlclua_libvlc_command },
+    { NULL, NULL }
+};
+
+void luaopen_variables( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_var_reg );
+    lua_setfield( L, -2, "var" );
+}
diff --git a/modules/misc/lua/libs/variables.h b/modules/misc/lua/libs/variables.h
new file mode 100644 (file)
index 0000000..1155d7e
--- /dev/null
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * variables.h: Generic lua<->vlc variables interface
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+#ifndef VLC_LUA_VARIABLES_H
+#define VLC_LUA_VARIABLES_H
+
+int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
+
+#define vlclua_var_toggle_or_set(a,b,c) \
+    __vlclua_var_toggle_or_set(a,VLC_OBJECT(b),c)
+int __vlclua_var_toggle_or_set( lua_State *, vlc_object_t *, const char * );
+
+#endif
+
diff --git a/modules/misc/lua/libs/video.c b/modules/misc/lua/libs/video.c
new file mode 100644 (file)
index 0000000..ff26fee
--- /dev/null
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * intf.c: Generic lua interface functions
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_vout.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+
+#include "../vlc.h"
+#include "../libs.h"
+#include "input.h"
+#include "variables.h"
+
+/*****************************************************************************
+ * Vout control
+ *****************************************************************************/
+static int vlclua_fullscreen( lua_State *L )
+{
+    vout_thread_t *p_vout;
+    int i_ret;
+
+    input_thread_t * p_input = vlclua_get_input_internal( L );
+    if( !p_input ) return vlclua_error( L );
+
+    p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
+    if( !p_vout ) return vlclua_error( L );
+
+    i_ret = vlclua_var_toggle_or_set( L, p_vout, "fullscreen" );
+    vlc_object_release( p_vout );
+    vlc_object_release( p_input );
+    return i_ret;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_video_reg[] = {
+    { "fullscreen", vlclua_fullscreen },
+    { NULL, NULL }
+};
+
+void luaopen_video( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_video_reg );
+    lua_setfield( L, -2, "video" );
+}
similarity index 63%
rename from modules/misc/lua/vlm.c
rename to modules/misc/lua/libs/vlm.c
index d64f07957ef173308f7bc7559c3c0af56adec5ff..32f448e024fec9daf2abc836c1ca3380b340173d 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * objects.c: Generic lua VLM wrapper
+ * vlm.c: Generic lua VLM wrapper
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 
 #include <lua.h>        /* Low level lua C API */
 #include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
 
-#include "vlc.h"
+#include "../vlc.h"
+#include "../libs.h"
 
 /*****************************************************************************
  *
  *****************************************************************************/
-int vlclua_vlm_new( lua_State *L )
-{
 #ifdef ENABLE_VLM
+static int vlclua_vlm_delete( lua_State * );
+static int vlclua_vlm_execute_command( lua_State * );
+
+static const luaL_Reg vlclua_vlm_reg[] = {
+    { "execute_command", vlclua_vlm_execute_command },
+    { NULL, NULL }
+};
+
+static int vlclua_vlm_new( lua_State *L )
+{
     vlc_object_t *p_this = vlclua_get_this( L );
     vlm_t *p_vlm = vlm_New( p_this );
     if( !p_vlm )
-        goto err;
-    __vlclua_push_vlc_object( L, (vlc_object_t*)p_vlm, NULL );
+        return luaL_error( L, "Cannot start VLM." );
+
+    vlm_t **pp_vlm = lua_newuserdata( L, sizeof( vlm_t * ) );
+    *pp_vlm = p_vlm;
+
+    if( luaL_newmetatable( L, "vlm" ) )
+    {
+        lua_newtable( L );
+        luaL_register( L, NULL, vlclua_vlm_reg );
+        lua_setfield( L, -2, "__index" );
+        lua_pushcfunction( L, vlclua_vlm_delete );
+        lua_setfield( L, -2, "__gc" );
+    }
+
+    lua_setmetatable( L, -2 );
     return 1;
-err:
-#endif
-    return luaL_error( L, "Cannot start VLM." );
 }
 
-int vlclua_vlm_delete( lua_State *L )
+static int vlclua_vlm_delete( lua_State *L )
 {
-#ifdef ENABLE_VLM
-    vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC );
-    vlm_Delete( p_vlm );
-#endif
+    vlm_t **pp_vlm = (vlm_t**)luaL_checkudata( L, 1, "vlm" );
+    vlm_Delete( *pp_vlm );
     return 0;
 }
 
-#ifdef ENABLE_VLM
 static void push_message( lua_State *L, vlm_message_t *message )
 {
     lua_createtable( L, 0, 2 );
@@ -92,21 +107,31 @@ static void push_message( lua_State *L, vlm_message_t *message )
     }
 }
 
-int vlclua_vlm_execute_command( lua_State *L )
+static int vlclua_vlm_execute_command( lua_State *L )
 {
-    vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_GENERIC );
+    vlm_t **pp_vlm = (vlm_t**)luaL_checkudata( L, 1, "vlm" );
     const char *psz_command = luaL_checkstring( L, 2 );
     vlm_message_t *message;
     int i_ret;
-    i_ret = vlm_ExecuteCommand( p_vlm, psz_command, &message );
+    i_ret = vlm_ExecuteCommand( *pp_vlm, psz_command, &message );
     lua_settop( L, 0 );
     push_message( L, message );
     vlm_MessageDelete( message );
     return 1 + vlclua_push_ret( L, i_ret );
 }
+
 #else
-int vlclua_vlm_execute_command( lua_State *L )
+static int vlclua_vlm_new( lua_State *L )
 {
-    return 1 + vlclua_push_ret( L, VLC_EGENERIC );
+    return luaL_error( L, "Cannot start VLM because it was disabled when compiling VLC." );
 }
 #endif
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void luaopen_vlm( lua_State *L )
+{
+    lua_pushcfunction( L, vlclua_vlm_new );
+    lua_setfield( L, -2, "vlm" );
+}
diff --git a/modules/misc/lua/libs/volume.c b/modules/misc/lua/libs/volume.c
new file mode 100644 (file)
index 0000000..2ebd4a4
--- /dev/null
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * volume.c
+ *****************************************************************************
+ * Copyright (C) 2007-2008 the VideoLAN team
+ * $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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_meta.h>
+#include <vlc_charset.h>
+#include <vlc_aout.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+#include <lualib.h>     /* Lua libs */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * Volume related
+ *****************************************************************************/
+static int vlclua_volume_set( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    int i_volume = luaL_checkint( L, 1 );
+    /* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
+    return vlclua_push_ret( L, aout_VolumeSet( p_this, i_volume ) );
+}
+
+static int vlclua_volume_get( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    audio_volume_t i_volume;
+    if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
+        lua_pushnumber( L, i_volume );
+    else
+        lua_pushnil( L );
+    return 1;
+}
+
+static int vlclua_volume_up( lua_State *L )
+{
+    audio_volume_t i_volume;
+    aout_VolumeUp( vlclua_get_this( L ),
+                   luaL_optint( L, 1, 1 ),
+                   &i_volume );
+    lua_pushnumber( L, i_volume );
+    return 1;
+}
+
+static int vlclua_volume_down( lua_State *L )
+{
+    audio_volume_t i_volume;
+    aout_VolumeDown( vlclua_get_this( L ),
+                     luaL_optint( L, 1, 1 ),
+                     &i_volume );
+    lua_pushnumber( L, i_volume );
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_volume_reg[] = {
+    { "get", vlclua_volume_get },
+    { "set", vlclua_volume_set },
+    { "up", vlclua_volume_up },
+    { "down", vlclua_volume_down },
+    { NULL, NULL }
+};
+
+void luaopen_volume( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_volume_reg );
+    lua_setfield( L, -2, "volume" );
+}
index def7c5e37bc866b3f5ff39766f902b6dc0652283..3f89e0546808e10ddcbd9aa36bbb145391344d8a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * meta.c: Get meta/artwork using lua scripts
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #include <vlc_charset.h>
 
 #include "vlc.h"
+#include "libs.h"
 
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
-                       lua_State * L, void * user_data );
 static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
                       lua_State * L, void * user_data );
 static lua_State *vlclua_meta_init( vlc_object_t *p_this,
                                     input_item_t * p_item );
 
 
-/*****************************************************************************
- * Lua function bridge
- *****************************************************************************/
-/* Functions to register */
-static luaL_Reg p_reg[] =
-{
-    /* TODO: make an object out of the stream stuff, so we can do something
-     * like:
-     *
-     * s = vlc.stream_new( "http://www.videolan.org" )
-     * page = s:read( 2^16 )
-     * s:delete()
-     *
-     * instead of (which could be problematic since we don't check if
-     * s is really a stream object):
-     *
-     * s = vlc.stream_new( "http://www.videolan.org" )
-     * page = vlc.stream_read( s, 2^16 )
-     * vlc.stream_delete( s )
-     */
-    { "stream_new", vlclua_stream_new },
-    { "stream_read", vlclua_stream_read },
-    { "stream_readline", vlclua_stream_readline },
-    { "stream_delete", vlclua_stream_delete },
-    { "decode_uri", vlclua_decode_uri },
-    { "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
-    { "msg_dbg", vlclua_msg_dbg },
-    { "msg_warn", vlclua_msg_warn },
-    { "msg_err", vlclua_msg_err },
-    { "msg_info", vlclua_msg_info },
-    { NULL, NULL }
-};
-
 /*****************************************************************************
  * Init lua
  *****************************************************************************/
@@ -105,7 +71,11 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
     /* Load Lua libraries */
     luaL_openlibs( L ); /* XXX: Don't open all the libs? */
 
-    luaL_register( L, "vlc", p_reg );
+    luaL_register( L, "vlc", NULL /* FIXME ? */ );
+
+    luaopen_msg( L );
+    luaopen_stream( L );
+    luaopen_strings( L );
 
     lua_pushlightuserdata( L, p_this );
     lua_setfield( L, -2, "private" );
@@ -211,73 +181,6 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
     return i_ret;
 }
 
-/*****************************************************************************
- * Called through lua_scripts_batch_execute to call 'fetch_meta' on the script
- * pointed by psz_filename.
- *****************************************************************************/
-static int fetch_meta( vlc_object_t *p_this, const char * psz_filename,
-                       lua_State * L, void * user_data )
-{
-    input_item_t * p_input = user_data;
-
-    /* In lua, setting a variable to nil is equivalent to deleting it */
-    lua_pushnil( L );
-    lua_setglobal( L, "fetch_meta" );
-
-    /* Load and run the script(s) */
-    if( luaL_dofile( L, psz_filename ) )
-    {
-        msg_Warn( p_this, "Error loading script %s: %s", psz_filename,
-                  lua_tostring( L, lua_gettop( L ) ) );
-        lua_pop( L, 1 );
-        return VLC_EGENERIC;
-    }
-
-    lua_getglobal( L, "fetch_meta" );
-
-    if( !lua_isfunction( L, lua_gettop( L ) ) )
-    {
-        msg_Warn( p_this, "Error while runing script %s, "
-                  "function fetch_meta() not found", psz_filename );
-        lua_pop( L, 1 );
-        return VLC_EGENERIC;
-    }
-
-    if( lua_pcall( L, 0, 1, 0 ) )
-    {
-        msg_Warn( p_this, "Error while runing script %s, "
-                  "function fetch_meta(): %s", psz_filename,
-                  lua_tostring( L, lua_gettop( L ) ) );
-        lua_pop( L, 1 );
-        return VLC_EGENERIC;
-    }
-
-
-    if( lua_gettop( L ) )
-    {
-        if( lua_istable( L, -1 ) )
-        {
-            /* ... item */
-            vlclua_read_meta_data( p_this, L, p_input );
-            vlclua_read_custom_meta_data( p_this, L, p_input );
-        }
-        else
-        {
-            msg_Err( p_this, "Lua playlist script %s: "
-                     "didn't return a table", psz_filename );
-        }
-    }
-    else
-    {
-        msg_Err( p_this, "Script went completely foobar" );
-    }
-
-    /* We tell the batch thing to continue, hence all script
-     * will get the change to add its meta. This behaviour could
-     * be changed. */
-    return VLC_EGENERIC;
-}
-
 /*****************************************************************************
  * Module entry point for art.
  *****************************************************************************/
diff --git a/modules/misc/lua/variables.c b/modules/misc/lua/variables.c
deleted file mode 100644 (file)
index ec4beb5..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-/*****************************************************************************
- * variables.c: Generic lua<->vlc variables interface
- *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
- * $Id$
- *
- * Authors: Antoine Cellerier <dionoea at videolan tod 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#ifndef  _GNU_SOURCE
-#   define  _GNU_SOURCE
-#endif
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-
-#include <lua.h>        /* Low level lua C API */
-#include <lauxlib.h>    /* Higher level C API */
-#include <lualib.h>     /* Lua libs */
-
-#include "vlc.h"
-
-/*****************************************************************************
- * Variables handling
- *****************************************************************************/
-int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val )
-{
-    switch( i_type &= 0xf0 )
-    {
-        case VLC_VAR_VOID:
-            vlclua_error( L );
-            break;
-        case VLC_VAR_BOOL:
-            lua_pushboolean( L, val.b_bool );
-            break;
-        case VLC_VAR_INTEGER:
-            lua_pushinteger( L, val.i_int );
-            break;
-        case VLC_VAR_STRING:
-            lua_pushstring( L, val.psz_string );
-            break;
-        case VLC_VAR_FLOAT:
-            lua_pushnumber( L, val.f_float );
-            break;
-        case VLC_VAR_TIME:
-            /* FIXME? (we're losing some precision, but does it really matter?) */
-            lua_pushnumber( L, ((double)val.i_time)/1000000. );
-            break;
-        case VLC_VAR_ADDRESS:
-            vlclua_error( L );
-            break;
-        case VLC_VAR_MUTEX:
-            vlclua_error( L );
-            break;
-        case VLC_VAR_LIST:
-            {
-                int i_count = val.p_list->i_count;
-                int i;
-                lua_createtable( L, i_count, 0 );
-                for( i = 0; i < i_count; i++ )
-                {
-                    lua_pushinteger( L, i+1 );
-                    if( !vlclua_pushvalue( L, val.p_list->pi_types[i],
-                                           val.p_list->p_values[i] ) )
-                        lua_pushnil( L );
-                    lua_settable( L, -3 );
-                }
-            }
-            break;
-        default:
-            vlclua_error( L );
-    }
-    return 1;
-}
-
-static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
-{
-    switch( i_type & 0xf0 )
-    {
-        case VLC_VAR_VOID:
-            break;
-        case VLC_VAR_BOOL:
-            val->b_bool = luaL_checkboolean( L, -1 );
-            break;
-        case VLC_VAR_INTEGER:
-            val->i_int = luaL_checkint( L, -1 );
-            break;
-        case VLC_VAR_STRING:
-            val->psz_string = (char*)luaL_checkstring( L, -1 ); /* XXX: Beware, this only stays valid as long as (L,-1) stays in the stack */
-            break;
-        case VLC_VAR_FLOAT:
-            val->f_float = luaL_checknumber( L, -1 );
-            break;
-        case VLC_VAR_TIME:
-            {
-                double f = luaL_checknumber( L, -1 );
-                val->i_time = (int64_t)(f*1000000.);
-            }
-            break;
-        case VLC_VAR_ADDRESS:
-            vlclua_error( L );
-            break;
-        case VLC_VAR_MUTEX:
-            vlclua_error( L );
-            break;
-        case VLC_VAR_LIST:
-            vlclua_error( L );
-            break;
-        default:
-            vlclua_error( L );
-    }
-    return 1;
-}
-
-int vlclua_var_get( lua_State *L )
-{
-    int i_type;
-    vlc_value_t val;
-    vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
-    const char *psz_var = luaL_checkstring( L, 2 );
-    i_type = var_Type( p_obj, psz_var );
-    var_Get( p_obj, psz_var, &val );
-    lua_pop( L, 2 );
-    return vlclua_pushvalue( L, i_type, val );
-}
-
-int vlclua_var_set( lua_State *L )
-{
-    int i_type;
-    vlc_value_t val;
-    vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
-    const char *psz_var = luaL_checkstring( L, 2 );
-    int i_ret;
-    i_type = var_Type( p_obj, psz_var );
-    vlclua_tovalue( L, i_type, &val );
-    i_ret = var_Set( p_obj, psz_var, val );
-    lua_pop( L, 3 );
-    return vlclua_push_ret( L, i_ret );
-}
-
-int vlclua_var_get_list( lua_State *L )
-{
-    vlc_value_t val;
-    vlc_value_t text;
-    vlc_object_t *p_obj = vlclua_checkobject( L, 1, 0 );
-    const char *psz_var = luaL_checkstring( L, 2 );
-    int i_ret = var_Change( p_obj, psz_var, VLC_VAR_GETLIST, &val, &text );
-    if( i_ret < 0 ) return vlclua_push_ret( L, i_ret );
-    vlclua_pushvalue( L, VLC_VAR_LIST, val );
-    vlclua_pushvalue( L, VLC_VAR_LIST, text );
-    var_Change( p_obj, psz_var, VLC_VAR_FREELIST, &val, &text );
-    return 2;
-}
-
-int vlclua_module_command( lua_State *L )
-{
-    vlc_object_t * p_this = vlclua_get_this( L );
-    const char *psz_name;
-    const char *psz_cmd;
-    const char *psz_arg;
-    char *psz_msg;
-    psz_name = luaL_checkstring( L, 1 );
-    psz_cmd = luaL_checkstring( L, 2 );
-    psz_arg = luaL_checkstring( L, 3 );
-    lua_pop( L, 3 );
-    var_Command( p_this, psz_name, psz_cmd, psz_arg, &psz_msg );
-    if( psz_msg )
-    {
-        lua_pushstring( L, psz_msg );
-        free( psz_msg );
-    }
-    else
-    {
-        lua_pushstring( L, "" );
-    }
-    return 1;
-}
-
-int vlclua_libvlc_command( lua_State *L )
-{
-    vlc_object_t * p_this = vlclua_get_this( L );
-    const char *psz_cmd;
-    vlc_value_t val_arg;
-    psz_cmd = luaL_checkstring( L, 1 );
-    val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
-    lua_pop( L, 2 );
-    if( !var_Type( p_this->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
-    {
-        free( val_arg.psz_string );
-        return luaL_error( L, "libvlc's \"%s\" is not a command",
-                           psz_cmd );
-    }
-
-    return vlclua_push_ret( L,
-                            var_Set( p_this->p_libvlc, psz_cmd, val_arg ) );
-}
index c86dd2bb1f7b2b8a03bb72adca41eea1c013ba9c..32cc2ab35907cc20815ffddab79588e9e80319c7 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vlc.c: Generic lua interface functions
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
 #define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")
 
 vlc_module_begin();
-    add_submodule();
         set_shortname( N_( "Lua Art" ) );
         set_description( N_("Fetch artwork using lua scripts") );
         set_capability( "art finder", 10 );
         set_callbacks( FindArt, NULL );
+
     add_submodule();
         add_shortcut( "luaplaylist" );
         set_category( CAT_INPUT );
@@ -71,6 +71,7 @@ vlc_module_begin();
         set_description( N_("Lua Playlist Parser Interface") );
         set_capability( "demux", 2 );
         set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist );
+
     add_submodule();
         add_shortcut( "luaintf" );
         add_shortcut( "luarc" );
@@ -90,305 +91,6 @@ vlc_module_begin();
         set_callbacks( Open_LuaIntf, Close_LuaIntf );
 vlc_module_end();
 
-/*****************************************************************************
- * Internal lua<->vlc utils
- *****************************************************************************/
-vlc_object_t * vlclua_get_this( lua_State *L )
-{
-    vlc_object_t * p_this;
-    lua_getglobal( L, "vlc" );
-    lua_getfield( L, -1, "private" );
-    p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) );
-    lua_pop( L, 2 );
-    return p_this;
-}
-
-/*****************************************************************************
- * VLC error code translation
- *****************************************************************************/
-int vlclua_push_ret( lua_State *L, int i_error )
-{
-    lua_pushnumber( L, i_error );
-    lua_pushstring( L, vlc_error( i_error ) );
-    return 2;
-}
-
-/*****************************************************************************
- * Get the VLC version string
- *****************************************************************************/
-int vlclua_version( lua_State *L )
-{
-    lua_pushstring( L, VLC_Version() );
-    return 1;
-}
-
-/*****************************************************************************
- * Get the VLC copyright
- *****************************************************************************/
-int vlclua_copyright( lua_State *L )
-{
-    lua_pushstring( L, COPYRIGHT_MESSAGE );
-    return 1;
-}
-
-/*****************************************************************************
- * Get the VLC license msg/disclaimer
- *****************************************************************************/
-int vlclua_license( lua_State *L )
-{
-    lua_pushstring( L, LICENSE_MSG );
-    return 1;
-}
-
-/*****************************************************************************
- * Quit VLC
- *****************************************************************************/
-int vlclua_quit( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    /* The rc.c code also stops the playlist ... not sure if this is needed
-     * though. */
-    vlc_object_kill( p_this->p_libvlc );
-    return 0;
-}
-
-/*****************************************************************************
- * Global properties getters
- *****************************************************************************/
-int vlclua_datadir( lua_State *L )
-{
-    lua_pushstring( L, config_GetDataDir() );
-    return 1;
-}
-int vlclua_homedir( lua_State *L )
-{
-    lua_pushstring( L, config_GetHomeDir() );
-    return 1;
-}
-int vlclua_configdir( lua_State *L )
-{
-    char *dir = config_GetUserConfDir();
-    lua_pushstring( L, dir );
-    free( dir );
-    return 1;
-}
-int vlclua_cachedir( lua_State *L )
-{
-    char *dir = config_GetCacheDir();
-    lua_pushstring( L, dir );
-    free( dir );
-    return 1;
-}
-int vlclua_datadir_list( lua_State *L )
-{
-    const char *psz_dirname = luaL_checkstring( L, 1 );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
-    char **ppsz_dir = ppsz_dir_list;
-    int i = 1;
-
-    if( vlclua_dir_list( p_this, psz_dirname, ppsz_dir_list ) != VLC_SUCCESS )
-        return 0;
-    lua_newtable( L );
-    for( ; *ppsz_dir; ppsz_dir++ )
-    {
-        lua_pushstring( L, *ppsz_dir );
-        lua_rawseti( L, -2, i );
-        i ++;
-    }
-    return 1;
-}
-
-/*****************************************************************************
- * Volume related
- *****************************************************************************/
-int vlclua_volume_set( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int i_volume = luaL_checkint( L, 1 );
-    /* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
-    return vlclua_push_ret( L, aout_VolumeSet( p_this, i_volume ) );
-}
-
-int vlclua_volume_get( lua_State *L )
-{
-    vlc_object_t *p_this = vlclua_get_this( L );
-    audio_volume_t i_volume;
-    if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
-        lua_pushnumber( L, i_volume );
-    else
-        lua_pushnil( L );
-    return 1;
-}
-
-int vlclua_volume_up( lua_State *L )
-{
-    audio_volume_t i_volume;
-    aout_VolumeUp( vlclua_get_this( L ),
-                   luaL_optint( L, 1, 1 ),
-                   &i_volume );
-    lua_pushnumber( L, i_volume );
-    return 1;
-}
-
-int vlclua_volume_down( lua_State *L )
-{
-    audio_volume_t i_volume;
-    aout_VolumeDown( vlclua_get_this( L ),
-                     luaL_optint( L, 1, 1 ),
-                     &i_volume );
-    lua_pushnumber( L, i_volume );
-    return 1;
-}
-
-/*****************************************************************************
- * Stream handling
- *****************************************************************************/
-int vlclua_stream_new( lua_State *L )
-{
-    vlc_object_t * p_this = vlclua_get_this( L );
-    stream_t * p_stream;
-    const char * psz_url;
-    psz_url = luaL_checkstring( L, -1 );
-    p_stream = stream_UrlNew( p_this, psz_url );
-    if( !p_stream )
-        return luaL_error( L, "Error when opening url: `%s'", psz_url );
-    lua_pushlightuserdata( L, p_stream );
-    return 1;
-}
-
-int vlclua_stream_read( lua_State *L )
-{
-    stream_t * p_stream;
-    int n;
-    uint8_t *p_read;
-    int i_read;
-    p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
-    n = luaL_checkint( L, 2 );
-    p_read = malloc( n );
-    if( !p_read ) return vlclua_error( L );
-    i_read = stream_Read( p_stream, p_read, n );
-    lua_pushlstring( L, (const char *)p_read, i_read );
-    free( p_read );
-    return 1;
-}
-
-int vlclua_stream_readline( lua_State *L )
-{
-    stream_t * p_stream;
-    p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
-    char *psz_line = stream_ReadLine( p_stream );
-    if( psz_line )
-    {
-        lua_pushstring( L, psz_line );
-        free( psz_line );
-    }
-    else
-        lua_pushnil( L );
-    return 1;
-}
-
-int vlclua_stream_delete( lua_State *L )
-{
-    stream_t * p_stream;
-    p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
-    stream_Delete( p_stream );
-    return 0;
-}
-
-/*****************************************************************************
- * String transformations
- *****************************************************************************/
-int vlclua_decode_uri( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-    {
-        const char *psz_cstring = luaL_checkstring( L, 1 );
-        char *psz_string = strdup( psz_cstring );
-        lua_remove( L, 1 ); /* remove elements to prevent being limited by
-                             * the stack's size (this function will work with
-                             * up to (stack size - 1) arguments */
-        decode_URI( psz_string );
-        lua_pushstring( L, psz_string );
-        free( psz_string );
-    }
-    return i_top;
-}
-
-int vlclua_resolve_xml_special_chars( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-    {
-        const char *psz_cstring = luaL_checkstring( L, 1 );
-        char *psz_string = strdup( psz_cstring );
-        lua_remove( L, 1 ); /* remove elements to prevent being limited by
-                             * the stack's size (this function will work with
-                             * up to (stack size - 1) arguments */
-        resolve_xml_special_chars( psz_string );
-        lua_pushstring( L, psz_string );
-        free( psz_string );
-    }
-    return i_top;
-}
-
-int vlclua_convert_xml_special_chars( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-    {
-        char *psz_string = convert_xml_special_chars( luaL_checkstring(L,1) );
-        lua_remove( L, 1 );
-        lua_pushstring( L, psz_string );
-        free( psz_string );
-    }
-    return i_top;
-}
-
-/*****************************************************************************
- * Messaging facilities
- *****************************************************************************/
-int vlclua_msg_dbg( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-        msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
-    return 0;
-}
-int vlclua_msg_warn( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-        msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
-    return 0;
-}
-int vlclua_msg_err( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-        msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
-    return 0;
-}
-int vlclua_msg_info( lua_State *L )
-{
-    int i_top = lua_gettop( L );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    int i;
-    for( i = 1; i <= i_top; i++ )
-        msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
-    return 0;
-}
-
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -403,8 +105,7 @@ static int file_compare( const char **a, const char **b )
     return strcmp( *a, *b );
 }
 
-int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname,
-                     char **ppsz_dir_list )
+int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list )
 {
     int i = 0;
     char *datadir = config_GetUserDataDir();
@@ -475,7 +176,7 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
     char **ppsz_dir;
 
-    i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
+    i_ret = vlclua_dir_list( luadirname, ppsz_dir_list );
     if( i_ret != VLC_SUCCESS )
         return i_ret;
     i_ret = VLC_EGENERIC;
index 037e309b3490928f14fd6d16860fb23fc00fb3b0..b47e8502a8432b59848b884454bb7890a64f465a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * luameta.c: Get meta/artwork using lua scripts
+ * vlc.h: VLC specific lua library functions.
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea at videolan tod org>
@@ -83,20 +83,6 @@ static inline int luaL_optboolean( lua_State *L, int narg, int def )
     return luaL_opt( L, luaL_checkboolean, narg, def );
 }
 
-static inline const void *luaL_checklightuserdata( lua_State *L, int narg )
-{
-    luaL_checktype( L, narg, LUA_TLIGHTUSERDATA ); /* can raise an error */
-    return lua_topointer( L, narg );
-}
-
-static inline const void *luaL_checkuserdata( lua_State *L, int narg, size_t size )
-{
-    luaL_checktype( L, narg, LUA_TUSERDATA ); /* can raise an error */
-    if( size && size != lua_objlen( L, narg ) ) /* this isn't worth much ... but it might still prevent a few errors */
-        luaL_error( L, "user data size doesn't match" );
-    return lua_topointer( L, narg );
-}
-
 static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
 {
     if( lua_isnil( L, narg ) )
@@ -104,70 +90,7 @@ static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
     return luaL_checkstring( L, narg );
 }
 
-/*****************************************************************************
- * Lua vlc_object_t wrapper
- *****************************************************************************/
-int __vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
-                              lua_CFunction pf_gc );
-#define vlclua_push_vlc_object( a, b, c ) \
-        __vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
-vlc_object_t *vlclua_checkobject( lua_State *L, int narg, int i_type );
-int vlclua_gc_release( lua_State *L );
-int vlclua_object_find( lua_State *L );
-int vlclua_object_find_name( lua_State *L );
-
 vlc_object_t * vlclua_get_this( lua_State * );
-playlist_t *vlclua_get_playlist_internal( lua_State * );
-
-int vlclua_add_callback( lua_State * );
-int vlclua_del_callback( lua_State * );
-
-int vlclua_url_parse( lua_State * );
-int vlclua_net_listen_tcp( lua_State * );
-int vlclua_net_listen_close( lua_State * );
-int vlclua_net_accept( lua_State * );
-int vlclua_net_close( lua_State * );
-int vlclua_net_send( lua_State * );
-int vlclua_net_recv( lua_State * );
-int vlclua_net_select( lua_State * );
-
-int vlclua_fd_set_new( lua_State * );
-int vlclua_fd_clr( lua_State * );
-int vlclua_fd_isset( lua_State * );
-int vlclua_fd_set( lua_State * );
-int vlclua_fd_zero( lua_State * );
-int vlclua_fd_read( lua_State * );
-int vlclua_fd_write( lua_State * );
-
-int vlclua_stat( lua_State * );
-int vlclua_opendir( lua_State * );
-
-int vlclua_vlm_new( lua_State * );
-int vlclua_vlm_delete( lua_State * );
-int vlclua_vlm_execute_command( lua_State * );
-
-int vlclua_httpd_tls_host_new( lua_State *L );
-int vlclua_httpd_host_delete( lua_State *L );
-int vlclua_httpd_handler_new( lua_State * L );
-int vlclua_httpd_handler_delete( lua_State *L );
-int vlclua_httpd_file_new( lua_State *L );
-int vlclua_httpd_file_delete( lua_State *L );
-int vlclua_httpd_redirect_new( lua_State *L );
-int vlclua_httpd_redirect_delete( lua_State *L );
-
-int vlclua_acl_create( lua_State * );
-int vlclua_acl_delete( lua_State * );
-int vlclua_acl_check( lua_State * );
-int vlclua_acl_duplicate( lua_State * );
-int vlclua_acl_add_host( lua_State * );
-int vlclua_acl_add_net( lua_State * );
-int vlclua_acl_load_file( lua_State * );
-
-int vlclua_sd_get_services_names( lua_State * );
-int vlclua_sd_add( lua_State * );
-int vlclua_sd_remove( lua_State * );
-int vlclua_sd_is_loaded( lua_State * );
-
 
 /*****************************************************************************
  * Lua function bridge
@@ -175,46 +98,6 @@ int vlclua_sd_is_loaded( lua_State * );
 #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 );
 
-int vlclua_version( lua_State * );
-int vlclua_license( lua_State * );
-int vlclua_copyright( lua_State * );
-int vlclua_quit( lua_State * );
-
-int vlclua_datadir( lua_State * );
-int vlclua_homedir( lua_State * );
-int vlclua_configdir( lua_State * );
-int vlclua_cachedir( lua_State * );
-int vlclua_datadir_list( lua_State * );
-
-int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
-int vlclua_var_get( lua_State * );
-int vlclua_var_get_list( lua_State * );
-int vlclua_var_set( lua_State * );
-int vlclua_module_command( lua_State * );
-int vlclua_libvlc_command( lua_State * );
-
-int vlclua_config_get( lua_State * );
-int vlclua_config_set( lua_State * );
-
-int vlclua_volume_set( lua_State * );
-int vlclua_volume_get( lua_State * );
-int vlclua_volume_up( lua_State * );
-int vlclua_volume_down( lua_State * );
-
-int vlclua_stream_new( lua_State * );
-int vlclua_stream_read( lua_State * );
-int vlclua_stream_readline( lua_State * );
-int vlclua_stream_delete( lua_State * );
-
-int vlclua_decode_uri( lua_State * );
-int vlclua_resolve_xml_special_chars( lua_State * );
-int vlclua_convert_xml_special_chars( lua_State * );
-
-int vlclua_msg_dbg( lua_State * );
-int vlclua_msg_warn( lua_State * );
-int vlclua_msg_err( lua_State * );
-int vlclua_msg_info( lua_State * );
-
 /*****************************************************************************
  * Will execute func on all scripts in luadirname, and stop if func returns
  * success.
@@ -222,7 +105,7 @@ int vlclua_msg_info( lua_State * );
 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 );
-int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list );
+int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list );
 
 /*****************************************************************************
  * Playlist and meta data internal utilities.
index e48615b859e4f9195dbea2d8d19933222e7ff7eb..6e5a767a6e5492f97cc2a7ed53c83cf2f0cd5418 100644 (file)
@@ -295,8 +295,6 @@ DIST_lua= \
        lua/intf/hotkeys.lua \
        lua/intf/modules/common.lua \
        lua/intf/modules/host.lua \
-       lua/intf/modules/httpd.lua \
-       lua/intf/modules/acl.lua \
        lua/intf/modules/sandbox.lua \
        lua/intf/telnet.lua \
        lua/intf/dummy.lua
diff --git a/share/lua/intf/modules/acl.lua b/share/lua/intf/modules/acl.lua
deleted file mode 100644 (file)
index d93f546..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
---[==========================================================================[
- acl.lua: VLC Lua interface ACL object
---[==========================================================================[
- Copyright (C) 2007 the VideoLAN team
- $Id$
-
- Authors: Antoine Cellerier <dionoea at videolan dot 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.
---]==========================================================================]
-
---[==========================================================================[
-require "acl"
-local a = acl.new(true) -> new ACL with default set to allow
-a:check("10.0.0.1") -> 0 == allow, 1 == deny, -1 == error
-a("10.0.0.1") -> same as a:check("10.0.0.1")
-a:duplicate() -> duplicate ACL object
-a:add_host("10.0.0.1",true) -> allow 10.0.0.1
-a:add_net("10.0.0.0",24,true) -> allow 10.0.0.0/24 (not sure)
-a:load_file("/path/to/acl") -> load ACL from file
---]==========================================================================]
-
-module("acl",package.seeall)
-
-methods = {
-    check = function(this,ip)
-        return vlc.acl.check(this.private,ip)
-    end,
-    duplicate = function(this)
-        return setmetatable({ private = vlc.acl.duplicate( rawget(this,"private") ) },metatable)
-    end,
-    add_host = function(this,ip,allow)
-        return vlc.acl.add_host(this.private,ip,allow)
-    end,
-    add_net = function(this,ip,len,allow)
-        return vlc.acl.add_net(this.private,ip,len,allow)
-    end,
-    load_file = function(this,path)
-        return vlc.acl.load_file(this.private,path)
-    end,
-}
-
-metatable = {
-    __index = function(this,key)
-        if methods[key] then
-            return methods[key]
-        elseif key == "private" then
-            error("Forbidden")
-        else
-            return rawget(this,key)
-        end
-    end,
-    __newindex = function(this,key,value)
-        if key == "private" or methods[key] then
-            error("Forbidden")
-        else
-            rawset(this,key,value)
-        end
-    end,
-    __call = methods.check,
-    __gc = function(this)
-        vlc.acl.delete(this.private)
-    end,
-    __metatable = "None of your business.",
-}
-
-function new( allow )
-    return setmetatable({ private = vlc.acl.create( allow ) },metatable)
-end
diff --git a/share/lua/intf/modules/httpd.lua b/share/lua/intf/modules/httpd.lua
deleted file mode 100644 (file)
index ff0ecb4..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
---[==========================================================================[
- httpd.lua: VLC Lua interface HTTPd module
---[==========================================================================[
- Copyright (C) 2007 the VideoLAN team
- $Id$
-
- Authors: Antoine Cellerier <dionoea at videolan dot 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.
---]==========================================================================]
-
---[==========================================================================[
---]==========================================================================]
-
-module("httpd",package.seeall)
-
-local function generic_metatable(methods,destructor)
-    return {
-        __index = function(this,key)
-            if methods and methods[key] then
-                return methods[key]
-            elseif key == "private" then
-                error("Forbidden")
-            else
-                return rawget(this,key)
-            end
-        end,
-        __newindex = function(this,key,value)
-            if key == "private" or (methods and methods[key]) then
-                error("Forbidden")
-            else
-                rawset(this,key,value)
-            end
-        end,
-        __gc = function(this)
-            if destructor then
-                destructor(rawget(this,"private"))
-            end
-        end,
-        --__metatable = "None of your business.",
-    }
-end
-
-local handler_metatable = generic_metatable({},vlc.httpd.handler_delete)
-local file_metatable = generic_metatable({},vlc.httpd.file_delete)
-local redirect_metatable = generic_metatable({},vlc.httpd.redirect_delete)
-
-local host_methods = {
-    handler_new = function(this,...)
-        return setmetatable({private=vlc.httpd.handler_new(rawget(this,"private"),...),parent=this},handler_metatable)
-    end,
-    file_new = function(this,...)
-        return setmetatable({private=vlc.httpd.file_new(rawget(this,"private"),...),parent=this},file_metatable)
-    end,
-    redirect_new = function(this,...)
-        return setmetatable({private=vlc.httpd.redirect_new(rawget(this,"private"),...),parent=this},redirect_metatable)
-    end,
-}
-local host_metatable = generic_metatable(host_methods,vlc.httpd.host_delete)
-
-function new( ... )
-    return setmetatable({private=vlc.httpd.host_new(...)},host_metatable)
-end