[vlc-devel] [PATCH] lua: renderers: Allow module name to be omitted

Hugo Beauzée-Luyssen hugo at beauzee.fr
Mon Jun 29 11:54:12 CEST 2020


---
 modules/lua/libs/renderers.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/modules/lua/libs/renderers.c b/modules/lua/libs/renderers.c
index 822b7ad237..3e132a95a8 100644
--- a/modules/lua/libs/renderers.c
+++ b/modules/lua/libs/renderers.c
@@ -179,11 +179,39 @@ static int vlclua_rd_create( lua_State* L )
     vlc_vector_init( &sys->items );
     vlc_mutex_init( &sys->mutex );
     sys->last_renderer_id = 0;
+    sys->rd = NULL;
 
     vlc_object_t *this = vlclua_get_this( L );
-    const char* name = luaL_checkstring( L, 1 );
+    const char* name = lua_tostring( L, 1 );
+
+    if ( name )
+    {
+        sys->rd = vlc_rd_new( this, name, &sys->owner );
+    }
+    else
+    {
+        char** names;
+        char** longnames;
+        if ( vlc_rd_get_names( this, &names, &longnames ) != VLC_SUCCESS )
+        {
+            vlc_vector_destroy( &sys->items );
+            return 0;
+        }
+        int i = 0;
+        while ( sys->rd == NULL && names[i] != NULL )
+        {
+            sys->rd = vlc_rd_new( this, names[i], &sys->owner );
+            ++i;
+        }
+        for ( i = 0; names[i] != NULL; ++i )
+        {
+            free( names[i] );
+            free( longnames[i] );
+        }
+        free( longnames );
+        free( names );
+    }
 
-    sys->rd = vlc_rd_new( this, name, &sys->owner );
     if ( !sys->rd )
     {
         vlc_vector_destroy( &sys->items );
-- 
2.20.1



More information about the vlc-devel mailing list