]> git.sesse.net Git - vlc/commitdiff
Lua Extensions: implement fake "require"
authorJean-Philippe André <jpeg@videolan.org>
Sun, 30 May 2010 14:57:21 +0000 (22:57 +0800)
committerJean-Philippe André <jpeg@videolan.org>
Sun, 30 May 2010 16:36:03 +0000 (00:36 +0800)
As the "descriptor" function is called with absolutely no libraries
loaded, even the built-in "require" function is not present at scan
time.
This closes #3453.

Note: this is a bit of a hack, but I prefer not to load any libs when
scanning the available extensions

Remove some useless debug, too

modules/misc/lua/extension.c

index 4483b4441206c691d56e663915f4b80fcf6fbdff..1634d06f5de4446e8b8a5ca3502f54fb7cbb7019 100644 (file)
@@ -194,6 +194,18 @@ static int ScanExtensions( extensions_manager_t *p_mgr )
     return VLC_SUCCESS;
 }
 
+/**
+ * Dummy Lua function: does nothing
+ * @note This function can be used to replace "require" while scanning for
+ * extensions
+ * Even the built-in libraries are not loaded when calling descriptor()
+ **/
+static int vlclua_dummy_require( lua_State *L )
+{
+    (void) L;
+    return 0;
+}
+
 /**
  * Batch scan all Lua files in folder "extensions": callback
  * @param p_this This extensions_manager_t object
@@ -236,8 +248,11 @@ int ScanLuaCallback( vlc_object_t *p_this, const char *psz_script,
     vlc_mutex_init( &p_ext->p_sys->running_lock );
     vlc_cond_init( &p_ext->p_sys->wait );
 
-    /* Load and run the script(s) */
+    /* Prepare Lua state */
     lua_State *L = luaL_newstate();
+    lua_register( L, "require", &vlclua_dummy_require );
+
+    /* Let's run it */
     if( luaL_dofile( L, psz_script ) )
     {
         msg_Warn( p_mgr, "Error loading script %s: %s", psz_script,
@@ -776,13 +791,6 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
             p_ext->p_sys->L = L;
         }
     }
-#ifndef NDEBUG
-    else
-    {
-        msg_Dbg( p_mgr, "Reusing old Lua state for extension '%s'",
-                 p_ext->psz_name );
-    }
-#endif
 
     return L;
 }