]> git.sesse.net Git - vlc/commitdiff
* modules/misc/lua:
authorAntoine Cellerier <dionoea@videolan.org>
Mon, 5 Nov 2007 21:52:26 +0000 (21:52 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Mon, 5 Nov 2007 21:52:26 +0000 (21:52 +0000)
   * Add vlc.license()
   * vlc.vlm.execute_command() now returns the VLC error code and the corresponding error message as 2nd and 3rd return values.
 * share/luaintf: add help and module description related stuff to the telnet and rc modules.

modules/misc/lua/intf.c
modules/misc/lua/vlc.c
modules/misc/lua/vlc.h
modules/misc/lua/vlm.c
share/luaintf/rc.lua
share/luaintf/telnet.lua

index 01d36a9e95624a7704f11138f4c3fd267c3703af..95d81119f7a97bd6aa44bdb75421f1a38409e0c3 100644 (file)
@@ -557,6 +557,7 @@ static luaL_Reg p_reg[] =
     { "signal", vlclua_signal },
 
     { "version", vlclua_version },
+    { "license", vlclua_license },
     { "should_die", vlclua_intf_should_die },
     { "quit", vlclua_quit },
 
index 7da1237de42fd294fe206bedfd1bf66403816ee2..0fd8db7b9d06edac11bd205a112c3b92680c7511 100644 (file)
@@ -118,6 +118,15 @@ int vlclua_version( lua_State *L )
     return 1;
 }
 
+/*****************************************************************************
+ * Get the VLC license msg/disclaimer
+ *****************************************************************************/
+int vlclua_license( lua_State *L )
+{
+    lua_pushstring( L, LICENSE_MSG );
+    return 1;
+}
+
 /*****************************************************************************
  * Quit VLC
  *****************************************************************************/
index 0c52cc85cf04cc3a1b1296cb4460230cf05698f1..2eba1b600686ee078afb71eeac5aff8d2fd1efce 100644 (file)
@@ -144,6 +144,7 @@ vlc_object_t * vlclua_get_this( lua_State * );
 int vlclua_push_ret( lua_State *, int i_error );
 
 int vlclua_version( lua_State * );
+int vlclua_license( lua_State * );
 int vlclua_quit( lua_State * );
 
 int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
index cbdf5ba87eb6357bcdadd78d78908614bb5fcde5..314bc2c1952ee2784ff9db8f342f4e2b6f6bd6ed 100644 (file)
@@ -87,9 +87,10 @@ int vlclua_vlm_execute_command( lua_State *L )
     vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_VLM );
     const char *psz_command = luaL_checkstring( L, 2 );
     vlm_message_t *message;
-    vlm_ExecuteCommand( p_vlm, psz_command, &message );
+    int i_ret;
+    i_ret = vlm_ExecuteCommand( p_vlm, psz_command, &message );
     lua_settop( L, 0 );
     push_message( L, message );
     vlm_MessageDelete( message );
-    return 1;
+    return 1 + vlclua_push_ret( L, i_ret );
 }
index c95f1a0dcb6ccfe9820c92efb1ca521349109893..b325489438d219028a1e1570d42ae6b70310fd30 100644 (file)
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 --]==========================================================================]
 
---[==========================================================================[
+description=
+[============================================================================[
+ Remote control interface for VLC
+
  This is a modules/control/rc.c look alike (with a bunch of new features)
  
  Use on local term:
  
  Note:
     -I luarc is an alias for -I lua --lua-intf rc
---]==========================================================================]
+
+ Configuration options setable throught the --lua-config option are:
+    * hosts: A list of hosts to listen on.
+    * host: A host to listen on. (won't be used if `hosts' is set)
+ The following can be set using the --lua-config option or in the interface
+ itself using the `set' command:
+    * prompt: The prompt.
+    * welcome: The welcome message.
+    * width: The default terminal width (used to format text).
+    * autocompletion: When issuing an unknown command, print a list of
+                      possible commands to autocomplete with. (0 to disable,
+                      1 to enable).
+    * autoalias: If autocompletion returns only one possibility, use it
+                 (0 to disable, 1 to enable).
+]============================================================================]
 
 require("common")
 skip = common.skip
@@ -49,6 +66,18 @@ env = { prompt = "> ";
         welcome = "Remote control interface initialized. Type `help' for help."
       }
 
+--[[ Import custom environement variables from the command line config (if possible) ]]
+for k,v in pairs(env) do
+    if config[k] then
+        if type(env[k]) == type(config[k]) then
+            env[k] = config[k]
+            vlc.msg.dbg("set environement variable `"..k.."' to "..tonumber(env[k]))
+        else
+            vlc.msg.err("environement variable `"..k.."' should be of type "..type(env[k])..". config value will be discarded.")
+        end
+    end
+end
+
 --[[ Command functions ]]
 function set_env(name,client,value)
     if value then
@@ -160,6 +189,18 @@ function playlist(name,client,arg)
     client:append("+----[ End of playlist ]")
 end
 
+function print_text(label,text)
+    return function(name,client)
+        client:append("+----[ "..label.." ]")
+        client:append "|"
+        for line in string.gmatch(text,".-\r?\n") do
+            client:append("| "..string.gsub(line,"\r?\n",""))
+        end
+        client:append "|"
+        client:append("+----[ End of "..string.lower(label).." ]")
+    end
+end
+
 function help(name,client,arg)
     local width = client.env.width
     local long = (name == "longhelp")
@@ -352,6 +393,8 @@ commands_ordered = {
     { "save_env"; { func = save_env; help = "save env vars (for future clients)"; adv = true } };
     { "alias"; { func = skip(alias); args = "[cmd]"; help = "set/get command aliases"; adv = true } };
     { "eval"; { func = skip(eval); help = "eval some lua (*debug*)"; adv =true } }; -- FIXME: comment out if you're not debugging
+    { "description"; { func = print_text("Description",description); help = "describe this module" } };
+    { "license"; { func = print_text("License message",vlc.license()); help = "print VLC's license message"; adv = true } };
     { "help"; { func = help; args = "[pattern]"; help = "a help message"; aliases = { "?" } } };
     { "longhelp"; { func = help; args = "[pattern]"; help = "a longer help message" } };
     { "logout"; { func = logout; help = "exit (if in a socket connection)" } };
@@ -447,7 +490,9 @@ h.status_callbacks[host.status.password] = function(client)
     client:switch_status(host.status.read)
 end
 -- Print prompt when switching a client's status to `read'
-h.status_callbacks[host.status.read] = function(client) client:send( client.env.prompt ) end
+h.status_callbacks[host.status.read] = function(client)
+    client:send( client.env.prompt )
+end
 
 h:listen( config.hosts or config.host or "*console" )
 
index 837ac8b513ea7628f64bd0629859f05159c7ad9c..1f40af01e7154bdf97839002b437844dfe0274ee 100644 (file)
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 --]==========================================================================]
 
---[==========================================================================[
+description=
+[============================================================================[
+ VLM Interface plugin
+
  Copy (features wise) of the original VLC modules/control/telnet.c module.
 
  Differences are:
       for example:
         listen on stdin: vlc -I lua --lua-intf telnet --lua-config "telnet={host='*console'}"
         listen on stdin + 2 ports on localhost: vlc -I lua --lua-intf telnet --lua-config "telnet={hosts={'localhost:4212','localhost:5678','*console'}}"
---]==========================================================================]
+ Configuration options setable throught the --lua-config option are:
+    * hosts: A list of hosts to listen on (see examples above).
+    * host: A host to listen on. (won't be used if `hosts' is set)
+    * password: The password used for remote clients.
+    * prompt: The prompt.
+]============================================================================]
 
 require "host"
 
@@ -54,7 +63,7 @@ function on_password( client )
     end
 end
 function on_read( client )
-    client:send( "> " )
+    client:send( config.prompt and tostring(config.prompt) or "> " )
 end
 function on_write( client )
 end
@@ -118,6 +127,12 @@ function lock(client)
     client.buffer = ""
     return false
 end
+function print_text(text)
+    return function(client)
+        client:append(string.gsub(text,"\r?\n","\r\n"))
+        return true
+    end
+end
 function help(client)
     client:append("    Telnet Specific Commands:")
     for c,t in pairs(commands) do
@@ -126,11 +141,13 @@ function help(client)
     return true
 end
 commands = {
-    ["shutdown"] = { func = shutdown, help = "shutdown VLC" },
-    ["quit"]     = { func = quit, help = "logout from telnet/shutdown VLC from local shell" },
-    ["logout"]   = { func = logout, help = "logout" },
-    ["lock"]     = { func = lock, help = "lock the telnet prompt" },
-    ["help"]     = { func = help, help = "show this help", dovlm = true },
+    ["shutdown"]    = { func = shutdown, help = "shutdown VLC" },
+    ["quit"]        = { func = quit, help = "logout from telnet/shutdown VLC from local shell" },
+    ["logout"]      = { func = logout, help = "logout" },
+    ["lock"]        = { func = lock, help = "lock the telnet prompt" },
+    ["description"] = { func = print_text(description), help = "describe this module" },
+    ["license"]     = { func = print_text(vlc.license()), help = "print VLC's license message" },
+    ["help"]        = { func = help, help = "show this help", dovlm = true },
     }
 
 function client_command( client )
@@ -138,9 +155,10 @@ function client_command( client )
     client.buffer = ""
     if not commands[cmd] or not commands[cmd].func or commands[cmd].dovlm then
         -- if it's not an interface specific command, it has to be a VLM command
-        message = vlc.vlm.execute_command( vlm, cmd )
+        local message, vlc_err = vlc.vlm.execute_command( vlm, cmd )
         vlm_message_to_string( client, message )
         if not commands[cmd] or not commands[cmd].func and not commands[cmd].dovlm then
+            if vlc_err ~= 0 then client:append( "Type `help' for help." ) end
             return true
         end
     end