[vlc-devel] commit: Do not store extension pointer in a variable visible from the lua code. ( Antoine Cellerier )
git version control
git at videolan.org
Sat Feb 27 22:05:40 CET 2010
vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Fri Feb 26 12:01:33 2010 +0100| [7478dfe4edc66d74679620be38d686d08e48ac7a] | committer: Antoine Cellerier
Do not store extension pointer in a variable visible from the lua code.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7478dfe4edc66d74679620be38d686d08e48ac7a
---
modules/misc/lua/extension.c | 26 +++++++++++++++++---------
modules/misc/lua/extension.h | 1 +
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/modules/misc/lua/extension.c b/modules/misc/lua/extension.c
index 174d18d..309b778 100644
--- a/modules/misc/lua/extension.c
+++ b/modules/misc/lua/extension.c
@@ -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;
}
diff --git a/modules/misc/lua/extension.h b/modules/misc/lua/extension.h
index 0f56853..eb54b38 100644
--- a/modules/misc/lua/extension.h
+++ b/modules/misc/lua/extension.h
@@ -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 * );
More information about the vlc-devel
mailing list