]> git.sesse.net Git - vlc/commitdiff
Do not store extension pointer in a variable visible from the lua code.
authorAntoine Cellerier <dionoea@videolan.org>
Fri, 26 Feb 2010 11:01:33 +0000 (12:01 +0100)
committerAntoine Cellerier <dionoea@videolan.org>
Sat, 27 Feb 2010 21:04:23 +0000 (22:04 +0100)
modules/misc/lua/extension.c
modules/misc/lua/extension.h

index 174d18dda1b59331ede71f243bf1457998760e38..309b778a0a78e392bd9ab2d664f49f70a14e9c22 100644 (file)
@@ -720,14 +720,12 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
             return NULL;
         }
         vlclua_set_this( L, p_mgr );
+        vlclua_extension_set( L, p_ext );
 
         luaL_openlibs( L );
         luaL_register( L, "vlc", p_reg );
         luaopen_msg( L );
 
-        lua_pushlightuserdata( L, p_ext );
-        lua_setfield( L, -2, "extension" );
-
         if( p_ext )
         {
             /* Load more libraries */
@@ -916,17 +914,27 @@ static int TriggerExtension( extensions_manager_t *p_mgr,
     return i_ret;
 }
 
+/** Set extension associated to the current script
+ * @param L current lua_State
+ * @param p_ext the extension
+ */
+void vlclua_extension_set( lua_State *L, extension_t *p_ext )
+{
+    lua_pushlightuserdata( L, vlclua_extension_set );
+    lua_pushlightuserdata( L, p_ext );
+    lua_rawset( L, LUA_REGISTRYINDEX );
+}
+
 /** Retrieve extension associated to the current script
  * @param L current lua_State
- * @return Lua userdata "vlc.extension"
+ * @return Extension pointer
  **/
 extension_t *vlclua_extension_get( lua_State *L )
 {
-    extension_t *p_ext = NULL;
-    lua_getglobal( L, "vlc" );
-    lua_getfield( L, -1, "extension" );
-    p_ext = (extension_t*) lua_topointer( L, lua_gettop( L ) );
-    lua_pop( L, 2 );
+    lua_pushlightuserdata( L, vlclua_extension_set );
+    lua_rawget( L, LUA_REGISTRYINDEX );
+    extension_t *p_ext = (extension_t*) lua_topointer( L, -1 );
+    lua_pop( L, 1 );
     return p_ext;
 }
 
index 0f568532402f105a158e79792b3d8f21154ca18a..eb54b385b8e0b34f1a196136ba4a0a0136a5c3ae 100644 (file)
@@ -117,6 +117,7 @@ bool LockExtension( extension_t *p_ext );
 void UnlockExtension( extension_t *p_ext );
 
 /* Lua specific functions */
+void vlclua_extension_set( lua_State *L, extension_t * );
 extension_t *vlclua_extension_get( lua_State *L );
 int lua_ExtensionActivate( extensions_manager_t *, extension_t * );
 int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * );