From: Jean-Philippe André Date: Sun, 30 May 2010 14:57:21 +0000 (+0800) Subject: Lua Extensions: implement fake "require" X-Git-Tag: 1.2.0-pre1~6396 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=860b78b3d6132b6ab5014a768cbdfbd96c0461fc;p=vlc 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 --- diff --git a/modules/misc/lua/extension.c b/modules/misc/lua/extension.c index 4483b44412..1634d06f5d 100644 --- a/modules/misc/lua/extension.c +++ b/modules/misc/lua/extension.c @@ -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; }