Commit 7478dfe4 authored by Antoine Cellerier's avatar Antoine Cellerier

Do not store extension pointer in a variable visible from the lua code.

parent 2c244563
...@@ -720,14 +720,12 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr, ...@@ -720,14 +720,12 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
return NULL; return NULL;
} }
vlclua_set_this( L, p_mgr ); vlclua_set_this( L, p_mgr );
vlclua_extension_set( L, p_ext );
luaL_openlibs( L ); luaL_openlibs( L );
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", p_reg );
luaopen_msg( L ); luaopen_msg( L );
lua_pushlightuserdata( L, p_ext );
lua_setfield( L, -2, "extension" );
if( p_ext ) if( p_ext )
{ {
/* Load more libraries */ /* Load more libraries */
...@@ -916,17 +914,27 @@ static int TriggerExtension( extensions_manager_t *p_mgr, ...@@ -916,17 +914,27 @@ static int TriggerExtension( extensions_manager_t *p_mgr,
return i_ret; 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 /** Retrieve extension associated to the current script
* @param L current lua_State * @param L current lua_State
* @return Lua userdata "vlc.extension" * @return Extension pointer
**/ **/
extension_t *vlclua_extension_get( lua_State *L ) extension_t *vlclua_extension_get( lua_State *L )
{ {
extension_t *p_ext = NULL; lua_pushlightuserdata( L, vlclua_extension_set );
lua_getglobal( L, "vlc" ); lua_rawget( L, LUA_REGISTRYINDEX );
lua_getfield( L, -1, "extension" ); extension_t *p_ext = (extension_t*) lua_topointer( L, -1 );
p_ext = (extension_t*) lua_topointer( L, lua_gettop( L ) ); lua_pop( L, 1 );
lua_pop( L, 2 );
return p_ext; return p_ext;
} }
......
...@@ -117,6 +117,7 @@ bool LockExtension( extension_t *p_ext ); ...@@ -117,6 +117,7 @@ bool LockExtension( extension_t *p_ext );
void UnlockExtension( extension_t *p_ext ); void UnlockExtension( extension_t *p_ext );
/* Lua specific functions */ /* Lua specific functions */
void vlclua_extension_set( lua_State *L, extension_t * );
extension_t *vlclua_extension_get( lua_State *L ); extension_t *vlclua_extension_get( lua_State *L );
int lua_ExtensionActivate( extensions_manager_t *, extension_t * ); int lua_ExtensionActivate( extensions_manager_t *, extension_t * );
int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * ); int lua_ExtensionDeactivate( extensions_manager_t *, extension_t * );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment