if( !p_ext->p_sys->L )
return VLC_SUCCESS;
- return lua_ExecuteFunction( p_mgr, p_ext, (const char*) p_widget->p_sys, LUA_END );
+ lua_State *L = GetLuaState( p_mgr, p_ext );
+ lua_pushlightuserdata( L, p_widget );
+ lua_gettable( L, LUA_REGISTRYINDEX );
+ return lua_ExecuteFunction( p_mgr, p_ext, NULL, LUA_END );
}
msg_Err( p_mgr, "Could not create new Lua State" );
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_mgr );
- lua_setfield( L, -2, "private" );
-
- lua_pushlightuserdata( L, p_ext );
- lua_setfield( L, -2, "extension" );
-
if( p_ext )
{
/* Load more libraries */
/**
* Execute a function in a Lua script
+ * @param psz_function Name of global function to execute. If NULL, assume
+ * that the function object is already on top of the
+ * stack.
* @return < 0 in case of failure, >= 0 in case of success
* @note It's better to call this function from a dedicated thread
* (see extension_thread.c)
assert( p_ext != NULL );
lua_State *L = GetLuaState( p_mgr, p_ext );
- lua_getglobal( L, psz_function );
+ if( psz_function )
+ lua_getglobal( L, psz_function );
if( !lua_isfunction( L, -1 ) )
{
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;
}