]> git.sesse.net Git - vlc/blob - modules/misc/lua/vlc.c
7da1237de42fd294fe206bedfd1bf66403816ee2
[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  * Quit VLC
123  *****************************************************************************/
124 int vlclua_quit( lua_State *L )
125 {
126     vlc_object_t *p_this = vlclua_get_this( L );
127     /* The rc.c code also stops the playlist ... not sure if this is needed
128      * though. */
129     vlc_object_kill( p_this->p_libvlc );
130     return 0;
131 }
132
133 /*****************************************************************************
134  * Volume related
135  *****************************************************************************/
136 int vlclua_volume_set( lua_State *L )
137 {
138     vlc_object_t *p_this = vlclua_get_this( L );
139     int i_volume = luaL_checkint( L, 1 );
140     /* Do we need to check that i_volume is in the AOUT_VOLUME_MIN->MAX range?*/
141     return vlclua_push_ret( L, aout_VolumeSet( p_this, i_volume ) );
142 }
143
144 int vlclua_volume_get( lua_State *L )
145 {
146     vlc_object_t *p_this = vlclua_get_this( L );
147     audio_volume_t i_volume;
148     if( aout_VolumeGet( p_this, &i_volume ) == VLC_SUCCESS )
149         lua_pushnumber( L, i_volume );
150     else
151         lua_pushnil( L );
152     return 1;
153 }
154
155 int vlclua_volume_up( lua_State *L )
156 {
157     audio_volume_t i_volume;
158     aout_VolumeUp( vlclua_get_this( L ),
159                    luaL_optint( L, 1, 1 ),
160                    &i_volume );
161     lua_pushnumber( L, i_volume );
162     return 1;
163 }
164
165 int vlclua_volume_down( lua_State *L )
166 {
167     audio_volume_t i_volume;
168     aout_VolumeDown( vlclua_get_this( L ),
169                      luaL_optint( L, 1, 1 ),
170                      &i_volume );
171     lua_pushnumber( L, i_volume );
172     return 1;
173 }
174
175 /*****************************************************************************
176  * Stream handling
177  *****************************************************************************/
178 int vlclua_stream_new( lua_State *L )
179 {
180     vlc_object_t * p_this = vlclua_get_this( L );
181     stream_t * p_stream;
182     const char * psz_url;
183     psz_url = luaL_checkstring( L, -1 );
184     p_stream = stream_UrlNew( p_this, psz_url );
185     if( !p_stream )
186         return luaL_error( L, "Error when opening url: `%s'", psz_url );
187     lua_pushlightuserdata( L, p_stream );
188     return 1;
189 }
190
191 int vlclua_stream_read( lua_State *L )
192 {
193     stream_t * p_stream;
194     int n;
195     byte_t *p_read;
196     int i_read;
197     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
198     n = luaL_checkint( L, 2 );
199     p_read = malloc( n );
200     if( !p_read ) return vlclua_error( L );
201     i_read = stream_Read( p_stream, p_read, n );
202     lua_pushlstring( L, (const char *)p_read, i_read );
203     free( p_read );
204     return 1;
205 }
206
207 int vlclua_stream_readline( lua_State *L )
208 {
209     stream_t * p_stream;
210     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
211     char *psz_line = stream_ReadLine( p_stream );
212     if( psz_line )
213     {
214         lua_pushstring( L, psz_line );
215         free( psz_line );
216     }
217     else
218         lua_pushnil( L );
219     return 1;
220 }
221
222 int vlclua_stream_delete( lua_State *L )
223 {
224     stream_t * p_stream;
225     p_stream = (stream_t *)luaL_checklightuserdata( L, 1 );
226     stream_Delete( p_stream );
227     return 0;
228 }
229
230 /*****************************************************************************
231  * String transformations
232  *****************************************************************************/
233 int vlclua_decode_uri( lua_State *L )
234 {
235     int i_top = lua_gettop( L );
236     int i;
237     for( i = 1; i <= i_top; i++ )
238     {
239         const char *psz_cstring = luaL_checkstring( L, 1 );
240         char *psz_string = strdup( psz_cstring );
241         lua_remove( L, 1 ); /* remove elements to prevent being limited by
242                              * the stack's size (this function will work with
243                              * up to (stack size - 1) arguments */
244         decode_URI( psz_string );
245         lua_pushstring( L, psz_string );
246         free( psz_string );
247     }
248     return i_top;
249 }
250
251 int vlclua_resolve_xml_special_chars( lua_State *L )
252 {
253     int i_top = lua_gettop( L );
254     int i;
255     for( i = 1; i <= i_top; i++ )
256     {
257         const char *psz_cstring = luaL_checkstring( L, 1 );
258         char *psz_string = strdup( psz_cstring );
259         lua_remove( L, 1 ); /* remove elements to prevent being limited by
260                              * the stack's size (this function will work with
261                              * up to (stack size - 1) arguments */
262         resolve_xml_special_chars( psz_string );
263         lua_pushstring( L, psz_string );
264         free( psz_string );
265     }
266     return i_top;
267 }
268
269 /*****************************************************************************
270  * Messaging facilities
271  *****************************************************************************/
272 int vlclua_msg_dbg( lua_State *L )
273 {
274     int i_top = lua_gettop( L );
275     vlc_object_t *p_this = vlclua_get_this( L );
276     int i;
277     for( i = 1; i <= i_top; i++ )
278         msg_Dbg( p_this, "%s", luaL_checkstring( L, 1 ) );
279     return 0;
280 }
281 int vlclua_msg_warn( 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_Warn( p_this, "%s", luaL_checkstring( L, i ) );
288     return 0;
289 }
290 int vlclua_msg_err( 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_Err( p_this, "%s", luaL_checkstring( L, i ) );
297     return 0;
298 }
299 int vlclua_msg_info( 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_Info( p_this, "%s", luaL_checkstring( L, i ) );
306     return 0;
307 }
308
309 /*****************************************************************************
310  *
311  *****************************************************************************/
312 static int file_select( const char *file )
313 {
314     int i = strlen( file );
315     return i > 4 && !strcmp( file+i-4, ".lua" );
316 }
317
318 static int file_compare( const char **a, const char **b )
319 {
320     return strcmp( *a, *b );
321 }
322
323 int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname,
324                      char **ppsz_dir_list )
325 {
326     if( asprintf( &ppsz_dir_list[0], "%s" DIR_SEP "%s",
327                    p_this->p_libvlc->psz_datadir, luadirname ) < 0 )
328         return VLC_ENOMEM;
329
330 #   if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
331     {
332         const char *psz_vlcpath = config_GetDataDir();
333         if( asprintf( &ppsz_dir_list[1], "%s" DIR_SEP "%s",
334                       psz_vlcpath, luadirname )  < 0 )
335             return VLC_ENOMEM;
336
337         if( asprintf( &ppsz_dir_list[2], "%s" DIR_SEP "share" DIR_SEP "%s",
338                       psz_vlcpath, luadirname )  < 0 )
339             return VLC_ENOMEM;
340     }
341 #   else
342     if( asprintf( &ppsz_dir_list[1],
343                   "share" DIR_SEP "%s", luadirname ) < 0 )
344         return VLC_ENOMEM;
345
346 #   ifdef HAVE_SYS_STAT_H
347     {
348         struct stat stat_info;
349         if( ( utf8_stat( ppsz_dir_list[1], &stat_info ) == -1 )
350             || !S_ISDIR( stat_info.st_mode ) )
351         {
352             free(ppsz_dir_list[1]);
353             if( asprintf( &ppsz_dir_list[1],
354                           DATA_PATH DIR_SEP "%s", luadirname ) < 0 )
355                 return VLC_ENOMEM;
356         }
357     }
358 #   endif
359 #   endif
360     return VLC_SUCCESS;
361 }
362
363 /*****************************************************************************
364  * Will execute func on all scripts in luadirname, and stop if func returns
365  * success.
366  *****************************************************************************/
367 int vlclua_scripts_batch_execute( vlc_object_t *p_this,
368                                   const char * luadirname,
369                                   int (*func)(vlc_object_t *, const char *, lua_State *, void *),
370                                   lua_State * L,
371                                   void * user_data)
372 {
373     int i_ret = VLC_EGENERIC;
374
375     DIR   *dir           = NULL;
376     char **ppsz_filelist = NULL;
377     char **ppsz_fileend  = NULL;
378     char **ppsz_file;
379
380     char  *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
381     char **ppsz_dir;
382
383     i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
384     if( i_ret != VLC_SUCCESS )
385         return i_ret;
386     i_ret = VLC_EGENERIC;
387
388
389     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
390     {
391         int i_files;
392
393         if( ppsz_filelist )
394         {
395             for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
396                  ppsz_file++ )
397                 free( *ppsz_file );
398             free( ppsz_filelist );
399             ppsz_filelist = NULL;
400         }
401
402         if( dir )
403         {
404             closedir( dir );
405         }
406
407         msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );
408         dir = utf8_opendir( *ppsz_dir );
409
410         if( !dir ) continue;
411         i_files = utf8_loaddir( dir, &ppsz_filelist, file_select,
412                                 file_compare );
413         if( i_files < 1 ) continue;
414         ppsz_fileend = ppsz_filelist + i_files;
415
416         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )
417         {
418             char  *psz_filename;
419             if( asprintf( &psz_filename,
420                           "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) < 0)
421                 return VLC_ENOMEM;
422             msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );
423
424             i_ret = func( p_this, psz_filename, L, user_data );
425
426             free( psz_filename );
427
428             if( i_ret == VLC_SUCCESS ) break;
429         }
430         if( i_ret == VLC_SUCCESS ) break;
431     }
432
433     if( ppsz_filelist )
434     {
435         for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
436              ppsz_file++ )
437             free( *ppsz_file );
438         free( ppsz_filelist );
439     }
440     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
441         free( *ppsz_dir );
442
443     if( dir ) closedir( dir );
444
445     return i_ret;
446 }
447
448
449 /*****************************************************************************
450  * Meta data setters utility.
451  * Playlist item table should be on top of the stack when these are called
452  *****************************************************************************/
453 void __vlclua_read_meta_data( vlc_object_t *p_this, lua_State *L,
454                               input_item_t *p_input )
455 {
456 #define TRY_META( a, b )                                        \
457     lua_getfield( L, -1, a );                                   \
458     if( lua_isstring( L, -1 ) )                                 \
459     {                                                           \
460         char *psz_value = strdup( lua_tostring( L, -1 ) );      \
461         EnsureUTF8( psz_value );                                \
462         msg_Dbg( p_this, #b ": %s", psz_value );                \
463         input_item_Set ## b ( p_input, psz_value );             \
464         free( psz_value );                                      \
465     }                                                           \
466     lua_pop( L, 1 ); /* pop a */
467     TRY_META( "title", Title );
468     TRY_META( "artist", Artist );
469     TRY_META( "genre", Genre );
470     TRY_META( "copyright", Copyright );
471     TRY_META( "album", Album );
472     TRY_META( "tracknum", TrackNum );
473     TRY_META( "description", Description );
474     TRY_META( "rating", Rating );
475     TRY_META( "date", Date );
476     TRY_META( "setting", Setting );
477     TRY_META( "url", URL );
478     TRY_META( "language", Language );
479     TRY_META( "nowplaying", NowPlaying );
480     TRY_META( "publisher", Publisher );
481     TRY_META( "encodedby", EncodedBy );
482     TRY_META( "arturl", ArtURL );
483     TRY_META( "trackid", TrackID );
484 }
485
486 void __vlclua_read_custom_meta_data( vlc_object_t *p_this, lua_State *L,
487                                      input_item_t *p_input )
488 {
489     /* ... item */
490     lua_getfield( L, -1, "meta" );
491     /* ... item meta */
492     if( lua_istable( L, -1 ) )
493     {
494         lua_pushnil( L );
495         /* ... item meta nil */
496         while( lua_next( L, -2 ) )
497         {
498             /* ... item meta key value */
499             if( !lua_isstring( L, -2 ) )
500             {
501                 msg_Warn( p_this, "Custom meta data category name must be "
502                                    "a string" );
503             }
504             else if( !lua_istable( L, -1 ) )
505             {
506                 msg_Warn( p_this, "Custom meta data category contents "
507                                    "must be a table" );
508             }
509             else
510             {
511                 const char *psz_meta_category = lua_tostring( L, -2 );
512                 msg_Dbg( p_this, "Found custom meta data category: %s",
513                          psz_meta_category );
514                 lua_pushnil( L );
515                 /* ... item meta key value nil */
516                 while( lua_next( L, -2 ) )
517                 {
518                     /* ... item meta key value key2 value2 */
519                     if( !lua_isstring( L, -2 ) )
520                     {
521                         msg_Warn( p_this, "Custom meta category item name "
522                                            "must be a string." );
523                     }
524                     else if( !lua_isstring( L, -1 ) )
525                     {
526                         msg_Warn( p_this, "Custom meta category item value "
527                                            "must be a string." );
528                     }
529                     else
530                     {
531                         const char *psz_meta_name =
532                             lua_tostring( L, -2 );
533                         const char *psz_meta_value =
534                             lua_tostring( L, -1 );
535                         msg_Dbg( p_this, "Custom meta %s, %s: %s",
536                                  psz_meta_category, psz_meta_name,
537                                  psz_meta_value );
538                         input_ItemAddInfo( p_input, psz_meta_category,
539                                            psz_meta_name, psz_meta_value );
540                     }
541                     lua_pop( L, 1 ); /* pop item */
542                     /* ... item meta key value key2 */
543                 }
544                 /* ... item meta key value */
545             }
546             lua_pop( L, 1 ); /* pop category */
547             /* ... item meta key */
548         }
549         /* ... item meta */
550     }
551     lua_pop( L, 1 ); /* pop "meta" */
552     /* ... item -> back to original stack */
553 }
554
555 /*****************************************************************************
556  * Playlist utilities
557  ****************************************************************************/
558 /**
559  * Playlist item table should be on top of the stack when this is called
560  */
561 void __vlclua_read_options( vlc_object_t *p_this, lua_State *L,
562                             int *pi_options, char ***pppsz_options )
563 {
564     lua_getfield( L, -1, "options" );
565     if( lua_istable( L, -1 ) )
566     {
567         lua_pushnil( L );
568         while( lua_next( L, -2 ) )
569         {
570             if( lua_isstring( L, -1 ) )
571             {
572                 char *psz_option = strdup( lua_tostring( L, -1 ) );
573                 msg_Dbg( p_this, "Option: %s", psz_option );
574                 INSERT_ELEM( *pppsz_options, *pi_options, *pi_options,
575                              psz_option );
576             }
577             else
578             {
579                 msg_Warn( p_this, "Option should be a string" );
580             }
581             lua_pop( L, 1 ); /* pop option */
582         }
583     }
584     lua_pop( L, 1 ); /* pop "options" */
585 }
586
587 int __vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
588                                     playlist_t *p_playlist,
589                                     input_item_t *p_parent, vlc_bool_t b_play )
590 {
591     int i_count = 0;
592
593     /* playlist */
594     if( lua_istable( L, -1 ) )
595     {
596         lua_pushnil( L );
597         /* playlist nil */
598         while( lua_next( L, -2 ) )
599         {
600             /* playlist key item */
601             /* <Parse playlist item> */
602             if( lua_istable( L, -1 ) )
603             {
604                 lua_getfield( L, -1, "path" );
605                 /* playlist key item path */
606                 if( lua_isstring( L, -1 ) )
607                 {
608                     const char   *psz_path     = NULL;
609                     const char   *psz_name     = NULL;
610                     char        **ppsz_options = NULL;
611                     int           i_options    = 0;
612                     mtime_t       i_duration   = -1;
613                     input_item_t *p_input;
614
615                     /* Read path and name */
616                     psz_path = lua_tostring( L, -1 );
617                     msg_Dbg( p_this, "Path: %s", psz_path );
618                     lua_getfield( L, -2, "name" );
619                     /* playlist key item path name */
620                     if( lua_isstring( L, -1 ) )
621                     {
622                         psz_name = lua_tostring( L, -1 );
623                         msg_Dbg( p_this, "Name: %s", psz_name );
624                     }
625                     else
626                     {
627                         if( !lua_isnil( L, -1 ) )
628                             msg_Warn( p_this, "Playlist item name should be a string." );
629                         psz_name = psz_path;
630                     }
631
632                     /* Read duration */
633                     lua_getfield( L, -3, "duration" );
634                     /* playlist key item path name duration */
635                     if( lua_isnumber( L, -1 ) )
636                     {
637                         i_duration = (mtime_t)(lua_tonumber( L, -1 )*1e6);
638                     }
639                     else if( !lua_isnil( L, -1 ) )
640                     {
641                         msg_Warn( p_this, "Playlist item duration should be a number (in seconds)." );
642                     }
643                     lua_pop( L, 1 ); /* pop "duration" */
644
645                     /* playlist key item path name */
646
647                     /* Read options: item must be on top of stack */
648                     lua_pushvalue( L, -3 );
649                     /* playlist key item path name item */
650                     vlclua_read_options( p_this, L, &i_options, &ppsz_options );
651
652                     /* Create input item */
653                     p_input = input_ItemNewExt( p_playlist, psz_path,
654                                                 psz_name, i_options,
655                                                 (const char **)ppsz_options,
656                                                 i_duration );
657                     lua_pop( L, 3 ); /* pop "path name item" */
658                     /* playlist key item */
659
660                     /* Read meta data: item must be on top of stack */
661                     vlclua_read_meta_data( p_this, L, p_input );
662
663                     /* Read custom meta data: item must be on top of stack*/
664                     vlclua_read_custom_meta_data( p_this, L, p_input );
665
666                     /* Append item to playlist */
667                     if( p_parent ) /* Add to node */
668                         input_ItemAddSubItem( p_parent, p_input );
669                     else if( b_play ) /* Play */
670                         playlist_AddInput( p_playlist, p_input,
671                                            PLAYLIST_APPEND | PLAYLIST_GO,
672                                            PLAYLIST_END, VLC_TRUE, VLC_FALSE );
673                     else /* Enqueue */
674                         playlist_AddInput( p_playlist, p_input,
675                                            PLAYLIST_APPEND | PLAYLIST_PREPARSE,
676                                            PLAYLIST_END, VLC_TRUE, VLC_FALSE );
677                     i_count ++; /* increment counter */
678
679                     while( i_options > 0 )
680                         free( ppsz_options[--i_options] );
681                     free( ppsz_options );
682                 }
683                 else
684                 {
685                     lua_pop( L, 1 ); /* pop "path" */
686                     msg_Warn( p_this,
687                              "Playlist item's path should be a string" );
688                 }
689                 /* playlist key item */
690             }
691             else
692             {
693                 msg_Warn( p_this, "Playlist item should be a table" );
694             }
695             /* <Parse playlist item> */
696             lua_pop( L, 1 ); /* pop the value, keep the key for
697                               * the next lua_next() call */
698             /* playlist key */
699         }
700         /* playlist */
701     }
702     else
703     {
704         msg_Warn( p_this, "Playlist should be a table." );
705     }
706     return i_count;
707 }