]> git.sesse.net Git - vlc/blob - modules/misc/lua/vlc.c
* modules/misc/lua:
[vlc] / modules / misc / lua / vlc.c
1 /*****************************************************************************
2  * vlc.c: Generic lua inteface functions
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *          Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifndef  _GNU_SOURCE
29 #   define  _GNU_SOURCE
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc_meta.h>
34 #include <vlc_charset.h>
35 #include <vlc_aout.h>
36
37 #include <lua.h>        /* Low level lua C API */
38 #include <lauxlib.h>    /* Higher level C API */
39 #include <lualib.h>     /* Lua libs */
40
41 #include "vlc.h"
42
43 /*****************************************************************************
44  * Module descriptor
45  *****************************************************************************/
46
47 #define INTF_TEXT N_("Lua interface")
48 #define INTF_LONGTEXT N_("Lua interface module to load")
49
50 #define CONFIG_TEXT N_("Lua inteface configuration")
51 #define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")
52
53 vlc_module_begin();
54     add_shortcut( "luameta" );
55     set_shortname( N_( "Lua Meta" ) );
56     set_description( _("Fetch metadata using lua scripts") );
57     set_capability( "meta fetcher", 10 );
58     set_callbacks( E_(FindMeta), NULL );
59     add_submodule();
60         set_shortname( N_( "Lua Art" ) );
61         set_description( _("Fetch artwork using lua scripts") );
62         set_capability( "art finder", 10 );
63         set_callbacks( E_(FindArt), NULL );
64     add_submodule();
65         add_shortcut( "luaplaylist" );
66         set_category( CAT_INPUT );
67         set_subcategory( SUBCAT_INPUT_DEMUX );
68         set_shortname( _("Lua Playlist") );
69         set_description( _("Lua Playlist Parser Interface") );
70         set_capability( "demux2", 9 );
71         set_callbacks( E_(Import_LuaPlaylist), E_(Close_LuaPlaylist) );
72     add_submodule();
73         add_shortcut( "luaintf" );
74         add_shortcut( "luarc" );
75         /* add_shortcut( "rc" ); */
76         add_shortcut( "luahotkeys" );
77         /* add_shortcut( "hotkeys" ); */
78         add_shortcut( "luatelnet" );
79         /* add_shortcut( "telnet" ); */
80         set_description( _("Lua Interface Module") );
81         set_capability( "interface", 0 );
82         add_string( "lua-intf", "dummy", NULL,
83                     INTF_TEXT, INTF_LONGTEXT, VLC_FALSE );
84         add_string( "lua-config", "", NULL,
85                     CONFIG_TEXT, CONFIG_LONGTEXT, VLC_FALSE );
86         set_callbacks( E_(Open_LuaIntf), E_(Close_LuaIntf) );
87 vlc_module_end();
88
89 /*****************************************************************************
90  * Internal lua<->vlc utils
91  *****************************************************************************/
92 vlc_object_t * vlclua_get_this( lua_State *L )
93 {
94     vlc_object_t * p_this;
95     lua_getglobal( L, "vlc" );
96     lua_getfield( L, -1, "private" );
97     p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) );
98     lua_pop( L, 2 );
99     return p_this;
100 }
101
102 /*****************************************************************************
103  * VLC error code translation
104  *****************************************************************************/
105 int vlclua_push_ret( lua_State *L, int i_error )
106 {
107     lua_pushnumber( L, i_error );
108     lua_pushstring( L, vlc_error( i_error ) );
109     return 2;
110 }
111
112 /*****************************************************************************
113  * Get the VLC version string
114  *****************************************************************************/
115 int vlclua_version( lua_State *L )
116 {
117     lua_pushstring( L, VLC_Version() );
118     return 1;
119 }
120
121 /*****************************************************************************
122  * Get the VLC license msg/disclaimer
123  *****************************************************************************/
124 int vlclua_license( lua_State *L )
125 {
126     lua_pushstring( L, LICENSE_MSG );
127     return 1;
128 }
129
130 /*****************************************************************************
131  * Quit VLC
132  *****************************************************************************/
133 int vlclua_quit( lua_State *L )
134 {
135     vlc_object_t *p_this = vlclua_get_this( L );
136     /* The rc.c code also stops the playlist ... not sure if this is needed
137      * though. */
138     vlc_object_kill( p_this->p_libvlc );
139     return 0;
140 }
141
142 /*****************************************************************************
143  * Volume related
144  *****************************************************************************/
145 int vlclua_volume_set( lua_State *L )
146 {
147     vlc_object_t *p_this = vlclua_get_this( L );
148     int i_volume = luaL_checkint( L, 1 );
149     /* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
150     return vlclua_push_ret( L, aout_VolumeSet( p_this, i_volume ) );
151 }
152
153 int vlclua_volume_get( lua_State *L )
154 {
155     vlc_object_t *p_this = vlclua_get_this( L );
156     audio_volume_t i_volume;
157     if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
158         lua_pushnumber( L, i_volume );
159     else
160         lua_pushnil( L );
161     return 1;
162 }
163
164 int vlclua_volume_up( lua_State *L )
165 {
166     audio_volume_t i_volume;
167     aout_VolumeUp( vlclua_get_this( L ),
168                    luaL_optint( L, 1, 1 ),
169                    &i_volume );
170     lua_pushnumber( L, i_volume );
171     return 1;
172 }
173
174 int vlclua_volume_down( lua_State *L )
175 {
176     audio_volume_t i_volume;
177     aout_VolumeDown( vlclua_get_this( L ),
178                      luaL_optint( L, 1, 1 ),
179                      &i_volume );
180     lua_pushnumber( L, i_volume );
181     return 1;
182 }
183
184 /*****************************************************************************
185  * Stream handling
186  *****************************************************************************/
187 int vlclua_stream_new( lua_State *L )
188 {
189     vlc_object_t * p_this = vlclua_get_this( L );
190     stream_t * p_stream;
191     const char * psz_url;
192     psz_url = luaL_checkstring( L, -1 );
193     p_stream = stream_UrlNew( p_this, psz_url );
194     if( !p_stream )
195         return luaL_error( L, "Error when opening url: `%s'", psz_url );
196     lua_pushlightuserdata( L, p_stream );
197     return 1;
198 }
199
200 int vlclua_stream_read( lua_State *L )
201 {
202     stream_t * p_stream;
203     int n;
204     byte_t *p_read;
205     int i_read;
206     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
207     n = luaL_checkint( L, 2 );
208     p_read = malloc( n );
209     if( !p_read ) return vlclua_error( L );
210     i_read = stream_Read( p_stream, p_read, n );
211     lua_pushlstring( L, (const char *)p_read, i_read );
212     free( p_read );
213     return 1;
214 }
215
216 int vlclua_stream_readline( lua_State *L )
217 {
218     stream_t * p_stream;
219     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
220     char *psz_line = stream_ReadLine( p_stream );
221     if( psz_line )
222     {
223         lua_pushstring( L, psz_line );
224         free( psz_line );
225     }
226     else
227         lua_pushnil( L );
228     return 1;
229 }
230
231 int vlclua_stream_delete( lua_State *L )
232 {
233     stream_t * p_stream;
234     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
235     stream_Delete( p_stream );
236     return 0;
237 }
238
239 /*****************************************************************************
240  * String transformations
241  *****************************************************************************/
242 int vlclua_decode_uri( lua_State *L )
243 {
244     int i_top = lua_gettop( L );
245     int i;
246     for( i = 1; i <= i_top; i++ )
247     {
248         const char *psz_cstring = luaL_checkstring( L, 1 );
249         char *psz_string = strdup( psz_cstring );
250         lua_remove( L, 1 ); /* remove elements to prevent being limited by
251                              * the stack's size (this function will work with
252                              * up to (stack size - 1) arguments */
253         decode_URI( psz_string );
254         lua_pushstring( L, psz_string );
255         free( psz_string );
256     }
257     return i_top;
258 }
259
260 int vlclua_resolve_xml_special_chars( lua_State *L )
261 {
262     int i_top = lua_gettop( L );
263     int i;
264     for( i = 1; i <= i_top; i++ )
265     {
266         const char *psz_cstring = luaL_checkstring( L, 1 );
267         char *psz_string = strdup( psz_cstring );
268         lua_remove( L, 1 ); /* remove elements to prevent being limited by
269                              * the stack's size (this function will work with
270                              * up to (stack size - 1) arguments */
271         resolve_xml_special_chars( psz_string );
272         lua_pushstring( L, psz_string );
273         free( psz_string );
274     }
275     return i_top;
276 }
277
278 /*****************************************************************************
279  * Messaging facilities
280  *****************************************************************************/
281 int vlclua_msg_dbg( lua_State *L )
282 {
283     int i_top = lua_gettop( L );
284     vlc_object_t *p_this = vlclua_get_this( L );
285     int i;
286     for( i = 1; i <= i_top; i++ )
287         msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
288     return 0;
289 }
290 int vlclua_msg_warn( lua_State *L )
291 {
292     int i_top = lua_gettop( L );
293     vlc_object_t *p_this = vlclua_get_this( L );
294     int i;
295     for( i = 1; i <= i_top; i++ )
296         msg_Warn( p_this, "%s", luaL_checkstring( L, i ) );
297     return 0;
298 }
299 int vlclua_msg_err( lua_State *L )
300 {
301     int i_top = lua_gettop( L );
302     vlc_object_t *p_this = vlclua_get_this( L );
303     int i;
304     for( i = 1; i <= i_top; i++ )
305         msg_Err( p_this, "%s", luaL_checkstring( L, i ) );
306     return 0;
307 }
308 int vlclua_msg_info( lua_State *L )
309 {
310     int i_top = lua_gettop( L );
311     vlc_object_t *p_this = vlclua_get_this( L );
312     int i;
313     for( i = 1; i <= i_top; i++ )
314         msg_Info( p_this, "%s", luaL_checkstring( L, i ) );
315     return 0;
316 }
317
318 /*****************************************************************************
319  *
320  *****************************************************************************/
321 static int file_select( const char *file )
322 {
323     int i = strlen( file );
324     return i > 4 && !strcmp( file+i-4, ".lua" );
325 }
326
327 static int file_compare( const char **a, const char **b )
328 {
329     return strcmp( *a, *b );
330 }
331
332 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname,
333                      char **ppsz_dir_list )
334 {
335     if( asprintf( &ppsz_dir_list[0], "%s" DIR_SEP "%s",
336                    p_this->p_libvlc->psz_datadir, luadirname ) < 0 )
337         return VLC_ENOMEM;
338
339 #   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
340     {
341         const char *psz_vlcpath = config_GetDataDir();
342         if( asprintf( &ppsz_dir_list[1], "%s" DIR_SEP "%s",
343                       psz_vlcpath, luadirname )  < 0 )
344             return VLC_ENOMEM;
345
346         if( asprintf( &ppsz_dir_list[2], "%s" DIR_SEP "share" DIR_SEP "%s",
347                       psz_vlcpath, luadirname )  < 0 )
348             return VLC_ENOMEM;
349     }
350 #   else
351     if( asprintf( &ppsz_dir_list[1],
352                   "share" DIR_SEP "%s", luadirname ) < 0 )
353         return VLC_ENOMEM;
354
355 #   ifdef HAVE_SYS_STAT_H
356     {
357         struct stat stat_info;
358         if( ( utf8_stat( ppsz_dir_list[1], &stat_info ) == -1 )
359             || !S_ISDIR( stat_info.st_mode ) )
360         {
361             free(ppsz_dir_list[1]);
362             if( asprintf( &ppsz_dir_list[1],
363                           DATA_PATH DIR_SEP "%s", luadirname ) < 0 )
364                 return VLC_ENOMEM;
365         }
366     }
367 #   endif
368 #   endif
369     return VLC_SUCCESS;
370 }
371
372 /*****************************************************************************
373  * Will execute func on all scripts in luadirname, and stop if func returns
374  * success.
375  *****************************************************************************/
376 int vlclua_scripts_batch_execute( vlc_object_t *p_this,
377                                   const char * luadirname,
378                                   int (*func)(vlc_object_t *, const char *, lua_State *, void *),
379                                   lua_State * L,
380                                   void * user_data)
381 {
382     int i_ret = VLC_EGENERIC;
383
384     DIR   *dir           = NULL;
385     char **ppsz_filelist = NULL;
386     char **ppsz_fileend  = NULL;
387     char **ppsz_file;
388
389     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
390     char **ppsz_dir;
391
392     i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
393     if( i_ret != VLC_SUCCESS )
394         return i_ret;
395     i_ret = VLC_EGENERIC;
396
397
398     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
399     {
400         int i_files;
401
402         if( ppsz_filelist )
403         {
404             for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
405                  ppsz_file++ )
406                 free( *ppsz_file );
407             free( ppsz_filelist );
408             ppsz_filelist = NULL;
409         }
410
411         if( dir )
412         {
413             closedir( dir );
414         }
415
416         msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );
417         dir = utf8_opendir( *ppsz_dir );
418
419         if( !dir ) continue;
420         i_files = utf8_loaddir( dir, &ppsz_filelist, file_select,
421                                 file_compare );
422         if( i_files < 1 ) continue;
423         ppsz_fileend = ppsz_filelist + i_files;
424
425         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )
426         {
427             char  *psz_filename;
428             if( asprintf( &psz_filename,
429                           "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) < 0)
430                 return VLC_ENOMEM;
431             msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );
432
433             i_ret = func( p_this, psz_filename, L, user_data );
434
435             free( psz_filename );
436
437             if( i_ret == VLC_SUCCESS ) break;
438         }
439         if( i_ret == VLC_SUCCESS ) break;
440     }
441
442     if( ppsz_filelist )
443     {
444         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
445              ppsz_file++ )
446             free( *ppsz_file );
447         free( ppsz_filelist );
448     }
449     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
450         free( *ppsz_dir );
451
452     if( dir ) closedir( dir );
453
454     return i_ret;
455 }
456
457
458 /*****************************************************************************
459  * Meta data setters utility.
460  * Playlist item table should be on top of the stack when these are called
461  *****************************************************************************/
462 void __vlclua_read_meta_data( vlc_object_t *p_this, lua_State *L,
463                               input_item_t *p_input )
464 {
465 #define TRY_META( a, b )                                        \
466     lua_getfield( L, -1, a );                                   \
467     if( lua_isstring( L, -1 ) )                                 \
468     {                                                           \
469         char *psz_value = strdup( lua_tostring( L, -1 ) );      \
470         EnsureUTF8( psz_value );                                \
471         msg_Dbg( p_this, #b ": %s", psz_value );                \
472         input_item_Set ## b ( p_input, psz_value );             \
473         free( psz_value );                                      \
474     }                                                           \
475     lua_pop( L, 1 ); /* pop a */
476     TRY_META( "title", Title );
477     TRY_META( "artist", Artist );
478     TRY_META( "genre", Genre );
479     TRY_META( "copyright", Copyright );
480     TRY_META( "album", Album );
481     TRY_META( "tracknum", TrackNum );
482     TRY_META( "description", Description );
483     TRY_META( "rating", Rating );
484     TRY_META( "date", Date );
485     TRY_META( "setting", Setting );
486     TRY_META( "url", URL );
487     TRY_META( "language", Language );
488     TRY_META( "nowplaying", NowPlaying );
489     TRY_META( "publisher", Publisher );
490     TRY_META( "encodedby", EncodedBy );
491     TRY_META( "arturl", ArtURL );
492     TRY_META( "trackid", TrackID );
493 }
494
495 void __vlclua_read_custom_meta_data( vlc_object_t *p_this, lua_State *L,
496                                      input_item_t *p_input )
497 {
498     /* ... item */
499     lua_getfield( L, -1, "meta" );
500     /* ... item meta */
501     if( lua_istable( L, -1 ) )
502     {
503         lua_pushnil( L );
504         /* ... item meta nil */
505         while( lua_next( L, -2 ) )
506         {
507             /* ... item meta key value */
508             if( !lua_isstring( L, -2 ) )
509             {
510                 msg_Warn( p_this, "Custom meta data category name must be "
511                                    "a string" );
512             }
513             else if( !lua_istable( L, -1 ) )
514             {
515                 msg_Warn( p_this, "Custom meta data category contents "
516                                    "must be a table" );
517             }
518             else
519             {
520                 const char *psz_meta_category = lua_tostring( L, -2 );
521                 msg_Dbg( p_this, "Found custom meta data category: %s",
522                          psz_meta_category );
523                 lua_pushnil( L );
524                 /* ... item meta key value nil */
525                 while( lua_next( L, -2 ) )
526                 {
527                     /* ... item meta key value key2 value2 */
528                     if( !lua_isstring( L, -2 ) )
529                     {
530                         msg_Warn( p_this, "Custom meta category item name "
531                                            "must be a string." );
532                     }
533                     else if( !lua_isstring( L, -1 ) )
534                     {
535                         msg_Warn( p_this, "Custom meta category item value "
536                                            "must be a string." );
537                     }
538                     else
539                     {
540                         const char *psz_meta_name =
541                             lua_tostring( L, -2 );
542                         const char *psz_meta_value =
543                             lua_tostring( L, -1 );
544                         msg_Dbg( p_this, "Custom meta %s, %s: %s",
545                                  psz_meta_category, psz_meta_name,
546                                  psz_meta_value );
547                         input_ItemAddInfo( p_input, psz_meta_category,
548                                            psz_meta_name, psz_meta_value );
549                     }
550                     lua_pop( L, 1 ); /* pop item */
551                     /* ... item meta key value key2 */
552                 }
553                 /* ... item meta key value */
554             }
555             lua_pop( L, 1 ); /* pop category */
556             /* ... item meta key */
557         }
558         /* ... item meta */
559     }
560     lua_pop( L, 1 ); /* pop "meta" */
561     /* ... item -> back to original stack */
562 }
563
564 /*****************************************************************************
565  * Playlist utilities
566  ****************************************************************************/
567 /**
568  * Playlist item table should be on top of the stack when this is called
569  */
570 void __vlclua_read_options( vlc_object_t *p_this, lua_State *L,
571                             int *pi_options, char ***pppsz_options )
572 {
573     lua_getfield( L, -1, "options" );
574     if( lua_istable( L, -1 ) )
575     {
576         lua_pushnil( L );
577         while( lua_next( L, -2 ) )
578         {
579             if( lua_isstring( L, -1 ) )
580             {
581                 char *psz_option = strdup( lua_tostring( L, -1 ) );
582                 msg_Dbg( p_this, "Option: %s", psz_option );
583                 INSERT_ELEM( *pppsz_options, *pi_options, *pi_options,
584                              psz_option );
585             }
586             else
587             {
588                 msg_Warn( p_this, "Option should be a string" );
589             }
590             lua_pop( L, 1 ); /* pop option */
591         }
592     }
593     lua_pop( L, 1 ); /* pop "options" */
594 }
595
596 int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
597                                     playlist_t *p_playlist,
598                                     input_item_t *p_parent, vlc_bool_t b_play )
599 {
600     int i_count = 0;
601
602     /* playlist */
603     if( lua_istable( L, -1 ) )
604     {
605         lua_pushnil( L );
606         /* playlist nil */
607         while( lua_next( L, -2 ) )
608         {
609             /* playlist key item */
610             /* <Parse playlist item> */
611             if( lua_istable( L, -1 ) )
612             {
613                 lua_getfield( L, -1, "path" );
614                 /* playlist key item path */
615                 if( lua_isstring( L, -1 ) )
616                 {
617                     const char   *psz_path     = NULL;
618                     const char   *psz_name     = NULL;
619                     char        **ppsz_options = NULL;
620                     int           i_options    = 0;
621                     mtime_t       i_duration   = -1;
622                     input_item_t *p_input;
623
624                     /* Read path and name */
625                     psz_path = lua_tostring( L, -1 );
626                     msg_Dbg( p_this, "Path: %s", psz_path );
627                     lua_getfield( L, -2, "name" );
628                     /* playlist key item path name */
629                     if( lua_isstring( L, -1 ) )
630                     {
631                         psz_name = lua_tostring( L, -1 );
632                         msg_Dbg( p_this, "Name: %s", psz_name );
633                     }
634                     else
635                     {
636                         if( !lua_isnil( L, -1 ) )
637                             msg_Warn( p_this, "Playlist item name should be a string." );
638                         psz_name = psz_path;
639                     }
640
641                     /* Read duration */
642                     lua_getfield( L, -3, "duration" );
643                     /* playlist key item path name duration */
644                     if( lua_isnumber( L, -1 ) )
645                     {
646                         i_duration = (mtime_t)(lua_tonumber( L, -1 )*1e6);
647                     }
648                     else if( !lua_isnil( L, -1 ) )
649                     {
650                         msg_Warn( p_this, "Playlist item duration should be a number (in seconds)." );
651                     }
652                     lua_pop( L, 1 ); /* pop "duration" */
653
654                     /* playlist key item path name */
655
656                     /* Read options: item must be on top of stack */
657                     lua_pushvalue( L, -3 );
658                     /* playlist key item path name item */
659                     vlclua_read_options( p_this, L, &i_options, &ppsz_options );
660
661                     /* Create input item */
662                     p_input = input_ItemNewExt( p_playlist, psz_path,
663                                                 psz_name, i_options,
664                                                 (const char **)ppsz_options,
665                                                 i_duration );
666                     lua_pop( L, 3 ); /* pop "path name item" */
667                     /* playlist key item */
668
669                     /* Read meta data: item must be on top of stack */
670                     vlclua_read_meta_data( p_this, L, p_input );
671
672                     /* Read custom meta data: item must be on top of stack*/
673                     vlclua_read_custom_meta_data( p_this, L, p_input );
674
675                     /* Append item to playlist */
676                     if( p_parent ) /* Add to node */
677                         input_ItemAddSubItem( p_parent, p_input );
678                     else if( b_play ) /* Play */
679                         playlist_AddInput( p_playlist, p_input,
680                                            PLAYLIST_APPEND | PLAYLIST_GO,
681                                            PLAYLIST_END, VLC_TRUE, VLC_FALSE );
682                     else /* Enqueue */
683                         playlist_AddInput( p_playlist, p_input,
684                                            PLAYLIST_APPEND | PLAYLIST_PREPARSE,
685                                            PLAYLIST_END, VLC_TRUE, VLC_FALSE );
686                     i_count ++; /* increment counter */
687
688                     while( i_options > 0 )
689                         free( ppsz_options[--i_options] );
690                     free( ppsz_options );
691                 }
692                 else
693                 {
694                     lua_pop( L, 1 ); /* pop "path" */
695                     msg_Warn( p_this,
696                              "Playlist item's path should be a string" );
697                 }
698                 /* playlist key item */
699             }
700             else
701             {
702                 msg_Warn( p_this, "Playlist item should be a table" );
703             }
704             /* <Parse playlist item> */
705             lua_pop( L, 1 ); /* pop the value, keep the key for
706                               * the next lua_next() call */
707             /* playlist key */
708         }
709         /* playlist */
710     }
711     else
712     {
713         msg_Warn( p_this, "Playlist should be a table." );
714     }
715     return i_count;
716 }