[vlc-commits] lua: expose var_Inherit()

Pierre Ynard git at videolan.org
Thu Sep 15 20:37:44 CEST 2011


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Thu Sep 15 20:35:34 2011 +0200| [ad964b11c168978351eced5c64aa6284bf20bb31] | committer: Pierre Ynard

lua: expose var_Inherit()

Similar functionality wasn't quite available by combining
vlc.var.create() and vlc.var.get()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ad964b11c168978351eced5c64aa6284bf20bb31
---

 modules/lua/libs/variables.c |   22 ++++++++++++++++++++++
 share/lua/README.txt         |    2 ++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/modules/lua/libs/variables.c b/modules/lua/libs/variables.c
index 40f4238..f3becae 100644
--- a/modules/lua/libs/variables.c
+++ b/modules/lua/libs/variables.c
@@ -130,6 +130,27 @@ static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
     return 1;
 }
 
+static int vlclua_var_inherit( lua_State *L )
+{
+    vlc_value_t val;
+    vlc_object_t *p_obj;
+    if( lua_type( L, 1 ) == LUA_TNIL )
+        p_obj = vlclua_get_this( L );
+    else
+    {
+        vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
+        p_obj = *pp_obj;
+    }
+    const char *psz_var = luaL_checkstring( L, 2 );
+
+    int i_type = config_GetType( p_obj, psz_var );
+    if( var_Inherit( p_obj, psz_var, i_type, &val ) != VLC_SUCCESS )
+        return 0;
+
+    lua_pop( L, 2 );
+    return vlclua_pushvalue( L, i_type, val, true );
+}
+
 static int vlclua_var_get( lua_State *L )
 {
     vlc_value_t val;
@@ -611,6 +632,7 @@ static int vlclua_togglebool( lua_State *L )
  *
  *****************************************************************************/
 static const luaL_Reg vlclua_var_reg[] = {
+    { "inherit", vlclua_var_inherit },
     { "get", vlclua_var_get },
     { "get_list", vlclua_var_get_list },
     { "set", vlclua_var_set },
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 23e1394..76a1469 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -375,6 +375,8 @@ strings.from_charset( charset, str ): convert a string from a specified
 
 Variables
 ---------
+var.inherit( object, name ): Find the variable "name"'s value inherited by
+  the object. If object is unset, the current module's object will be used.
 var.get( object, name ): Get the object's variable "name"'s value.
 var.get_list( object, name ): Get the object's variable "name"'s value list.
   1st return value is the value list, 2nd return value is the text list.



More information about the vlc-commits mailing list