[vlc-devel] commit: Implement "@name var val" style commands in rc.lua ( and other misc changes) (Antoine Cellerier )

git version control git at videolan.org
Mon Jan 19 22:29:00 CET 2009


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Mon Jan 19 22:02:44 2009 +0100| [8bf00f1bebf8abd4c4d33797594d6f18f3f6cba9] | committer: Antoine Cellerier 

Implement "@name var val" style commands in rc.lua (and other misc changes)

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

 modules/misc/lua/libs/variables.c |    5 ++-
 share/lua/README.txt              |    8 +++-
 share/lua/intf/dummy.lua          |    2 +-
 share/lua/intf/rc.lua             |   72 ++++++++++++++++++++++---------------
 4 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/modules/misc/lua/libs/variables.c b/modules/misc/lua/libs/variables.c
index 8b8d045..16833bc 100644
--- a/modules/misc/lua/libs/variables.c
+++ b/modules/misc/lua/libs/variables.c
@@ -211,11 +211,12 @@ static int vlclua_command( lua_State *L )
     const char *psz_cmd;
     const char *psz_arg;
     char *psz_msg;
+    int ret;
     psz_name = luaL_checkstring( L, 1 );
     psz_cmd = luaL_checkstring( L, 2 );
     psz_arg = luaL_checkstring( L, 3 );
     lua_pop( L, 3 );
-    var_Command( p_this, psz_name, psz_cmd, psz_arg, &psz_msg );
+    ret = var_Command( p_this, psz_name, psz_cmd, psz_arg, &psz_msg );
     if( psz_msg )
     {
         lua_pushstring( L, psz_msg );
@@ -225,7 +226,7 @@ static int vlclua_command( lua_State *L )
     {
         lua_pushstring( L, "" );
     }
-    return 1;
+    return vlclua_push_ret( L, ret ) + 1;
 }
 
 static int vlclua_libvlc_command( lua_State *L )
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 3dd3fc8..1048176 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -95,7 +95,8 @@ misc.homedir(): Get the user's home directory.
 misc.configdir(): Get the user's VLC config directory.
 misc.cachedir(): Get the user's VLC cache directory.
 
-misc.datadir_list( name ): FIXME: write description ... or ditch function if it isn't usefull anymore, we have datadir and userdatadir :)
+misc.datadir_list( name ): FIXME: write description ... or ditch function
+  if it isn't usefull anymore, we have datadir and userdatadir :)
 
 misc.mdate(): Get the current date (in milliseconds).
 misc.mwait(): Wait for the given date (in milliseconds).
@@ -124,7 +125,9 @@ end
 net.close( fd ): Close file descriptor.
 net.send( fd, string, [length] ): Send data on fd.
 net.recv( fd, [max length] ): Receive data from fd.
-net.select( nfds, fds_read, fds_write, timeout ): Monitor a bunch of file descriptors. Returns number of fds to handle and the amount of time not slept. See "man select".
+net.select( nfds, fds_read, fds_write, timeout ): Monitor a bunch of file
+  descriptors. Returns number of fds to handle and the amount of time not
+  slept. See "man select".
 net.fd_set_new(): Create a new fd_set.
 local fds = vlc.net.fd_set_new()
 fds:clr( fd ) -- remove fd from set
@@ -315,6 +318,7 @@ a reference to it, all VLM items will be deleted.
 Volume
 ------
 volume.set( level ): Set volume to an absolute level between 0 and 1024.
+  256 is 100%.
 volume.get(): Get volume.
 volume.up( [n] ): Increment volume by n steps of 32. n defaults to 1.
 volume.down( [n] ): Decrement volume by n steps of 32. n defaults to 1.
diff --git a/share/lua/intf/dummy.lua b/share/lua/intf/dummy.lua
index 7193043..3a5fea4 100644
--- a/share/lua/intf/dummy.lua
+++ b/share/lua/intf/dummy.lua
@@ -3,7 +3,7 @@
 msg = [[
 This is the `dummy' VLC Lua interface module.
 Please specify a VLC Lua interface to load with the --lua-intf option.
-VLC Lua interface modules include: `rc', `telnet' and `hotkeys'.
+VLC Lua interface modules include: `rc', `telnet' and `http'.
 For example: vlc -I lua --lua-intf rc]]
 --You can also use the alternate syntax: vlc -I "lua{intf=rc}"]]
 
diff --git a/share/lua/intf/rc.lua b/share/lua/intf/rc.lua
index 5492625..91b1155 100644
--- a/share/lua/intf/rc.lua
+++ b/share/lua/intf/rc.lua
@@ -1,7 +1,7 @@
 --[==========================================================================[
  rc.lua: remote control module for VLC
 --[==========================================================================[
- Copyright (C) 2007 the VideoLAN team
+ Copyright (C) 2007-2009 the VideoLAN team
  $Id$
 
  Authors: Antoine Cellerier <dionoea at videolan dot org>
@@ -513,7 +513,7 @@ do
         end
     end
     list = list..")"
-    if count ~= 0 then
+    if count ~= 0 and env.welcome then
         env.welcome = env.welcome .. "\r\nWarning: "..count.." functions are still unimplemented "..list.."."
     end
 end
@@ -556,6 +556,18 @@ function call_libvlc_command(cmd,client,arg)
     return vlcerr
 end
 
+function call_object_command(cmd,client,arg)
+    local var, val = split_input(arg)
+    local ok, vlcmsg, vlcerr, vlcerrmsg = pcall( vlc.var.command, cmd, var, val )
+    if not ok then
+        client:append("Error in `"..cmd.." "..var.." "..val.."' ".. vlcmsg) -- when pcall fails the 2nd arg is the error message
+    end
+    if vlcmsg ~= "" then
+        client:append(vlcmsg)
+    end
+    return vlcerr
+end
+
 --[[ Setup host ]]
 require("host")
 h = host.host()
@@ -604,36 +616,38 @@ while not vlc.misc.should_die() do
             client:switch_status(host.status.write)
             if commands[cmd] then
                 call_command(cmd,client,arg)
+            elseif string.sub(cmd,0,1)=='@'
+            and call_object_command(string.sub(cmd,2,#cmd),client,arg) == 0 then
+                --
+            elseif client.type == host.client_type.stdio
+            and call_libvlc_command(cmd,client,arg) == 0 then
+                --
             else
-                if client.type == host.client_type.stdio 
-                and call_libvlc_command(cmd,client,arg) == 0 then
-                else
-                    local choices = {}
-                    if client.env.autocompletion ~= 0 then
-                        for v,_ in common.pairs_sorted(commands) do
-                            if string.sub(v,0,#cmd)==cmd then
-                                table.insert(choices, v)
-                            end
+                local choices = {}
+                if client.env.autocompletion ~= 0 then
+                    for v,_ in common.pairs_sorted(commands) do
+                        if string.sub(v,0,#cmd)==cmd then
+                            table.insert(choices, v)
                         end
                     end
-                    if #choices == 1 and client.env.autoalias ~= 0 then
-                        -- client:append("Aliasing to \""..choices[1].."\".")
-                        cmd = choices[1]
-                        call_command(cmd,client,arg)
-                    else
-                        client:append("Unknown command `"..cmd.."'. Type `help' for help.")
-                        if #choices ~= 0 then
-                            client:append("Possible choices are:")
-                            local cols = math.floor(client.env.width/(client.env.colwidth+1))
-                            local fmt = "%-"..client.env.colwidth.."s"
-                            for i = 1, #choices do
-                                choices[i] = string.format(fmt,choices[i])
-                            end
-                            for i = 1, #choices, cols do
-                                local j = i + cols - 1
-                                if j > #choices then j = #choices end
-                                client:append("  "..table.concat(choices," ",i,j))
-                            end
+                end
+                if #choices == 1 and client.env.autoalias ~= 0 then
+                    -- client:append("Aliasing to \""..choices[1].."\".")
+                    cmd = choices[1]
+                    call_command(cmd,client,arg)
+                else
+                    client:append("Unknown command `"..cmd.."'. Type `help' for help.")
+                    if #choices ~= 0 then
+                        client:append("Possible choices are:")
+                        local cols = math.floor(client.env.width/(client.env.colwidth+1))
+                        local fmt = "%-"..client.env.colwidth.."s"
+                        for i = 1, #choices do
+                            choices[i] = string.format(fmt,choices[i])
+                        end
+                        for i = 1, #choices, cols do
+                            local j = i + cols - 1
+                            if j > #choices then j = #choices end
+                            client:append("  "..table.concat(choices," ",i,j))
                         end
                     end
                 end




More information about the vlc-devel mailing list