Commit 2c244563 authored by Antoine Cellerier's avatar Antoine Cellerier

Do not store p_this in a table value visible from lua code.

parent 5a60c559
...@@ -135,14 +135,13 @@ static int probe_luascript( vlc_object_t *p_this, const char * psz_filename, ...@@ -135,14 +135,13 @@ static int probe_luascript( vlc_object_t *p_this, const char * psz_filename,
/* Load Lua libraries */ /* Load Lua libraries */
luaL_openlibs( L ); /* FIXME: Don't open all the libs? */ luaL_openlibs( L ); /* FIXME: Don't open all the libs? */
vlclua_set_this( L, p_demux );
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", p_reg );
luaopen_msg( L ); luaopen_msg( L );
luaopen_strings( L ); luaopen_strings( L );
luaopen_stream( L ); luaopen_stream( L );
luaopen_xml( L ); luaopen_xml( L );
luaopen_md5( L ); luaopen_md5( L );
lua_pushlightuserdata( L, p_demux );
lua_setfield( L, -2, "private" );
lua_pushstring( L, p_demux->psz_path ); lua_pushstring( L, p_demux->psz_path );
lua_setfield( L, -2, "path" ); lua_setfield( L, -2, "path" );
lua_pushstring( L, p_demux->psz_access ); lua_pushstring( L, p_demux->psz_access );
......
...@@ -719,13 +719,12 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr, ...@@ -719,13 +719,12 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
msg_Err( p_mgr, "Could not create new Lua State" ); msg_Err( p_mgr, "Could not create new Lua State" );
return NULL; return NULL;
} }
vlclua_set_this( L, p_mgr );
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_mgr );
lua_setfield( L, -2, "private" );
lua_pushlightuserdata( L, p_ext ); lua_pushlightuserdata( L, p_ext );
lua_setfield( L, -2, "extension" ); lua_setfield( L, -2, "extension" );
......
...@@ -168,15 +168,13 @@ int Open_LuaIntf( vlc_object_t *p_this ) ...@@ -168,15 +168,13 @@ int Open_LuaIntf( vlc_object_t *p_this )
goto error; goto error;
} }
vlclua_set_this( L, p_intf );
luaL_openlibs( L ); luaL_openlibs( L );
/* register our functions */ /* register our functions */
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", p_reg );
/* store a pointer to p_intf (FIXME: user could overwrite this) */
lua_pushlightuserdata( L, p_intf );
lua_setfield( L, -2, "private" );
/* register submodules */ /* register submodules */
luaopen_acl( L ); luaopen_acl( L );
luaopen_config( L ); luaopen_config( L );
......
...@@ -50,13 +50,19 @@ ...@@ -50,13 +50,19 @@
/***************************************************************************** /*****************************************************************************
* Internal lua<->vlc utils * Internal lua<->vlc utils
*****************************************************************************/ *****************************************************************************/
void __vlclua_set_this( lua_State *L, vlc_object_t *p_this )
{
lua_pushlightuserdata( L, __vlclua_set_this );
lua_pushlightuserdata( L, p_this );
lua_rawset( L, LUA_REGISTRYINDEX );
}
vlc_object_t * vlclua_get_this( lua_State *L ) vlc_object_t * vlclua_get_this( lua_State *L )
{ {
vlc_object_t * p_this; lua_pushlightuserdata( L, __vlclua_set_this );
lua_getglobal( L, "vlc" ); lua_rawget( L, LUA_REGISTRYINDEX );
lua_getfield( L, -1, "private" ); vlc_object_t *p_this = (vlc_object_t*)lua_topointer( L, -1 );
p_this = (vlc_object_t*)lua_topointer( L, lua_gettop( L ) ); lua_pop( L, 1 );
lua_pop( L, 2 );
return p_this; return p_this;
} }
......
...@@ -60,6 +60,8 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char ...@@ -60,6 +60,8 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
return NULL; return NULL;
} }
vlclua_set_this( L, p_this );
/* Load Lua libraries */ /* Load Lua libraries */
luaL_openlibs( L ); /* XXX: Don't open all the libs? */ luaL_openlibs( L ); /* XXX: Don't open all the libs? */
...@@ -75,9 +77,6 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char ...@@ -75,9 +77,6 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
luaopen_md5( L ); luaopen_md5( L );
luaopen_input_item( L, p_item ); luaopen_input_item( L, p_item );
lua_pushlightuserdata( L, p_this );
lua_setfield( L, -2, "private" );
if( vlclua_add_modules_path( p_this, L, psz_filename ) ) if( vlclua_add_modules_path( p_this, L, psz_filename ) )
{ {
msg_Warn( p_this, "Error while setting the module search path for %s", msg_Warn( p_this, "Error while setting the module search path for %s",
......
...@@ -94,10 +94,9 @@ int Open_LuaSD( vlc_object_t *p_this ) ...@@ -94,10 +94,9 @@ int Open_LuaSD( vlc_object_t *p_this )
msg_Err( p_sd, "Could not create new Lua State" ); msg_Err( p_sd, "Could not create new Lua State" );
goto error; goto error;
} }
vlclua_set_this( L, p_sd );
luaL_openlibs( L ); luaL_openlibs( L );
luaL_register( L, "vlc", p_reg ); luaL_register( L, "vlc", p_reg );
lua_pushlightuserdata( L, p_sd );
lua_setfield( L, -2, "private" );
luaopen_input( L ); luaopen_input( L );
luaopen_msg( L ); luaopen_msg( L );
luaopen_misc( L ); luaopen_misc( L );
......
...@@ -91,6 +91,8 @@ static inline const char *luaL_nilorcheckstring( lua_State *L, int narg ) ...@@ -91,6 +91,8 @@ static inline const char *luaL_nilorcheckstring( lua_State *L, int narg )
return luaL_checkstring( L, narg ); return luaL_checkstring( L, narg );
} }
#define vlclua_set_this(a, b) __vlclua_set_this(a, VLC_OBJECT(b))
void __vlclua_set_this( lua_State *, vlc_object_t * );
vlc_object_t * vlclua_get_this( lua_State * ); vlc_object_t * vlclua_get_this( lua_State * );
/***************************************************************************** /*****************************************************************************
......
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