[vlc-commits] commit: Lua Extensions: implement fake "require" ( Jean-Philippe André )

git at videolan.org git at videolan.org
Sun May 30 19:05:58 CEST 2010


vlc/vlc-1.1 | branch: master | Jean-Philippe André <jpeg at videolan.org> | Sun May 30 22:57:21 2010 +0800| [e7c3a142c933d756794a78844b5c63f457bce666] | committer: Rémi Duraffort 

Lua Extensions: implement fake "require"

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
(cherry picked from commit 860b78b3d6132b6ab5014a768cbdfbd96c0461fc)

Signed-off-by: Rémi Duraffort <ivoire at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=e7c3a142c933d756794a78844b5c63f457bce666
---

 modules/misc/lua/extension.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/modules/misc/lua/extension.c b/modules/misc/lua/extension.c
index 4483b44..1634d06 100644
--- a/modules/misc/lua/extension.c
+++ b/modules/misc/lua/extension.c
@@ -195,6 +195,18 @@ static int ScanExtensions( extensions_manager_t *p_mgr )
 }
 
 /**
+ * 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
  * @param psz_script Name of the script to run
@@ -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;
 }



More information about the vlc-commits mailing list