/*****************************************************************************
* variables.c: Generic lua<->vlc variables interface
*****************************************************************************
- * Copyright (C) 2007-2008 the VideoLAN team
+ * Copyright (C) 2007-2010 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea at videolan tod org>
*****************************************************************************/
int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val )
{
- switch( i_type &= 0xf0 )
+ switch( i_type &= VLC_VAR_CLASS )
{
case VLC_VAR_VOID:
vlclua_error( L );
case VLC_VAR_MUTEX:
vlclua_error( L );
break;
- case VLC_VAR_LIST:
- {
- int i_count = val.p_list->i_count;
- int i;
- lua_createtable( L, i_count, 0 );
- for( i = 0; i < i_count; i++ )
- {
- lua_pushinteger( L, i+1 );
- if( !vlclua_pushvalue( L, val.p_list->pi_types[i],
- val.p_list->p_values[i] ) )
- lua_pushnil( L );
- lua_settable( L, -3 );
- }
- }
- break;
default:
vlclua_error( L );
}
return 1;
}
+static int vlclua_pushlist( lua_State *L, vlc_list_t *p_list )
+{
+ int i_count = p_list->i_count;
+
+ lua_createtable( L, i_count, 0 );
+ for( int i = 0; i < i_count; i++ )
+ {
+ lua_pushinteger( L, i+1 );
+ if( !vlclua_pushvalue( L, p_list->pi_types[i],
+ p_list->p_values[i] ) )
+ lua_pushnil( L );
+ lua_settable( L, -3 );
+ }
+ return 1;
+}
+
static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
{
- switch( i_type & 0xf0 )
+ switch( i_type & VLC_VAR_CLASS )
{
case VLC_VAR_VOID:
break;
case VLC_VAR_MUTEX:
vlclua_error( L );
break;
- case VLC_VAR_LIST:
- vlclua_error( L );
- break;
default:
vlclua_error( L );
}
const char *psz_var = luaL_checkstring( L, 2 );
int i_ret = var_Change( *pp_obj, psz_var, VLC_VAR_GETLIST, &val, &text );
if( i_ret < 0 ) return vlclua_push_ret( L, i_ret );
- vlclua_pushvalue( L, VLC_VAR_LIST, val );
- vlclua_pushvalue( L, VLC_VAR_LIST, text );
+ vlclua_pushlist( L, val.p_list );
+ vlclua_pushlist( L, text.p_list );
var_FreeList( &val, &text );
return 2;
}
}
else
{
- lua_pushstring( L, "" );
+ lua_pushliteral( L, "" );
}
return vlclua_push_ret( L, ret ) + 1;
}
val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
lua_pop( L, 2 );
int i_type = var_Type( p_this->p_libvlc, psz_cmd );
- if( ! i_type & VLC_VAR_ISCOMMAND )
+ if( ! (i_type & VLC_VAR_ISCOMMAND) )
{
free( val_arg.psz_string );
return luaL_error( L, "libvlc's \"%s\" is not a command",
b_bool = !var_GetBool( p_obj, psz_name );
else /* lua_gettop( L ) == 1 */
{
- b_bool = luaL_checkboolean( L, -1 )?true:false;
+ b_bool = luaL_checkboolean( L, -1 );
lua_pop( L, 1 );
}
{
/* errormessage */
const char *psz_err = lua_tostring( L, -1 );
- msg_Err( p_this, "Error while runing lua interface callback: %s",
+ msg_Err( p_this, "Error while running lua interface callback: %s",
psz_err );
/* empty the stack (should only contain the error message) */
lua_settop( L, 0 );
lua_settop( L, 4 ); /* makes sure that optional data arg is set */
if( !lua_isfunction( L, 3 ) )
return vlclua_error( L );
+
+ if( !pp_obj || !*pp_obj )
+ return vlclua_error( L );
+
+ /* Check variable type, in order to avoid PANIC */
+ switch( var_Type( *pp_obj, psz_var ) )
+ {
+ case VLC_VAR_BOOL:
+ case VLC_VAR_INTEGER:
+ case VLC_VAR_STRING:
+ case VLC_VAR_FLOAT:
+ case VLC_VAR_TIME:
+ break;
+ case VLC_VAR_ADDRESS:
+ case VLC_VAR_VOID:
+ case VLC_VAR_MUTEX:
+ default:
+ return vlclua_error( L );
+ }
+
i_index++;
p_callback = (vlclua_callback_t*)malloc( sizeof( vlclua_callback_t ) );
return 0;
}
+static int vlclua_trigger_callback( lua_State *L )
+{
+ vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
+ const char *psz_var = luaL_checkstring( L, 2 );
+
+ return vlclua_push_ret( L, var_TriggerCallback( *pp_obj, psz_var ) );
+}
+
/*****************************************************************************
*
*****************************************************************************/
{ "create", vlclua_var_create },
{ "add_callback", vlclua_add_callback },
{ "del_callback", vlclua_del_callback },
+ { "trigger_callback", vlclua_trigger_callback },
{ "command", vlclua_command },
{ "libvlc_command", vlclua_libvlc_command },
{ NULL, NULL }