X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Flua%2Flibs%2Fvariables.c;h=f0b1cbf30370f21ce9faf2f4de6575b8f99a736d;hb=498262cef5133af555f2ce8a8efd775aa163c41b;hp=c7820220c273864da74a28a5f8810245f0530ebc;hpb=1e724a9b7f89314a4b668414e125e3490fda234c;p=vlc diff --git a/modules/misc/lua/libs/variables.c b/modules/misc/lua/libs/variables.c index c7820220c2..f0b1cbf303 100644 --- a/modules/misc/lua/libs/variables.c +++ b/modules/misc/lua/libs/variables.c @@ -1,7 +1,7 @@ /***************************************************************************** * 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 @@ -75,27 +75,28 @@ int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ) 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 & VLC_VAR_CLASS ) @@ -126,9 +127,6 @@ static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val ) case VLC_VAR_MUTEX: vlclua_error( L ); break; - case VLC_VAR_LIST: - vlclua_error( L ); - break; default: vlclua_error( L ); } @@ -198,8 +196,8 @@ static int vlclua_var_get_list( lua_State *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; } @@ -224,7 +222,7 @@ static int vlclua_command( lua_State *L ) } else { - lua_pushstring( L, "" ); + lua_pushliteral( L, "" ); } return vlclua_push_ret( L, ret ) + 1; } @@ -259,7 +257,7 @@ int __vlclua_var_toggle_or_set( lua_State *L, vlc_object_t *p_obj, 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 ); } @@ -320,7 +318,7 @@ static int vlclua_callback( vlc_object_t *p_this, char const *psz_var, { /* 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 ); @@ -358,7 +356,6 @@ static int vlclua_add_callback( lua_State *L ) case VLC_VAR_ADDRESS: case VLC_VAR_VOID: case VLC_VAR_MUTEX: - case VLC_VAR_LIST: default: return vlclua_error( L ); }