Commit d5107810 authored by Antoine Cellerier's avatar Antoine Cellerier

* modules/misc/lua:

   * 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.
parent 94742be8
...@@ -557,6 +557,7 @@ static luaL_Reg p_reg[] = ...@@ -557,6 +557,7 @@ static luaL_Reg p_reg[] =
{ "signal", vlclua_signal }, { "signal", vlclua_signal },
{ "version", vlclua_version }, { "version", vlclua_version },
{ "license", vlclua_license },
{ "should_die", vlclua_intf_should_die }, { "should_die", vlclua_intf_should_die },
{ "quit", vlclua_quit }, { "quit", vlclua_quit },
......
...@@ -118,6 +118,15 @@ int vlclua_version( lua_State *L ) ...@@ -118,6 +118,15 @@ int vlclua_version( lua_State *L )
return 1; return 1;
} }
/*****************************************************************************
* Get the VLC license msg/disclaimer
*****************************************************************************/
int vlclua_license( lua_State *L )
{
lua_pushstring( L, LICENSE_MSG );
return 1;
}
/***************************************************************************** /*****************************************************************************
* Quit VLC * Quit VLC
*****************************************************************************/ *****************************************************************************/
......
...@@ -144,6 +144,7 @@ vlc_object_t * vlclua_get_this( lua_State * ); ...@@ -144,6 +144,7 @@ vlc_object_t * vlclua_get_this( lua_State * );
int vlclua_push_ret( lua_State *, int i_error ); int vlclua_push_ret( lua_State *, int i_error );
int vlclua_version( lua_State * ); int vlclua_version( lua_State * );
int vlclua_license( lua_State * );
int vlclua_quit( lua_State * ); int vlclua_quit( lua_State * );
int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */ int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val ); /* internal use only */
......
...@@ -87,9 +87,10 @@ int vlclua_vlm_execute_command( lua_State *L ) ...@@ -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 ); vlm_t *p_vlm = (vlm_t*)vlclua_checkobject( L, 1, VLC_OBJECT_VLM );
const char *psz_command = luaL_checkstring( L, 2 ); const char *psz_command = luaL_checkstring( L, 2 );
vlm_message_t *message; 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 ); lua_settop( L, 0 );
push_message( L, message ); push_message( L, message );
vlm_MessageDelete( message ); vlm_MessageDelete( message );
return 1; return 1 + vlclua_push_ret( L, i_ret );
} }
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 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) This is a modules/control/rc.c look alike (with a bunch of new features)
Use on local term: Use on local term:
...@@ -33,7 +36,21 @@ ...@@ -33,7 +36,21 @@
Note: Note:
-I luarc is an alias for -I lua --lua-intf rc -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") require("common")
skip = common.skip skip = common.skip
...@@ -49,6 +66,18 @@ env = { prompt = "> "; ...@@ -49,6 +66,18 @@ env = { prompt = "> ";
welcome = "Remote control interface initialized. Type `help' for help." 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 ]] --[[ Command functions ]]
function set_env(name,client,value) function set_env(name,client,value)
if value then if value then
...@@ -160,6 +189,18 @@ function playlist(name,client,arg) ...@@ -160,6 +189,18 @@ function playlist(name,client,arg)
client:append("+----[ End of playlist ]") client:append("+----[ End of playlist ]")
end 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) function help(name,client,arg)
local width = client.env.width local width = client.env.width
local long = (name == "longhelp") local long = (name == "longhelp")
...@@ -352,6 +393,8 @@ commands_ordered = { ...@@ -352,6 +393,8 @@ commands_ordered = {
{ "save_env"; { func = save_env; help = "save env vars (for future clients)"; adv = true } }; { "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 } }; { "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 { "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 = { "?" } } }; { "help"; { func = help; args = "[pattern]"; help = "a help message"; aliases = { "?" } } };
{ "longhelp"; { func = help; args = "[pattern]"; help = "a longer help message" } }; { "longhelp"; { func = help; args = "[pattern]"; help = "a longer help message" } };
{ "logout"; { func = logout; help = "exit (if in a socket connection)" } }; { "logout"; { func = logout; help = "exit (if in a socket connection)" } };
...@@ -447,7 +490,9 @@ h.status_callbacks[host.status.password] = function(client) ...@@ -447,7 +490,9 @@ h.status_callbacks[host.status.password] = function(client)
client:switch_status(host.status.read) client:switch_status(host.status.read)
end end
-- Print prompt when switching a client's status to `read' -- 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" ) h:listen( config.hosts or config.host or "*console" )
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 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. Copy (features wise) of the original VLC modules/control/telnet.c module.
Differences are: Differences are:
...@@ -31,7 +34,13 @@ ...@@ -31,7 +34,13 @@
for example: for example:
listen on stdin: vlc -I lua --lua-intf telnet --lua-config "telnet={host='*console'}" 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'}}" 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" require "host"
...@@ -54,7 +63,7 @@ function on_password( client ) ...@@ -54,7 +63,7 @@ function on_password( client )
end end
end end
function on_read( client ) function on_read( client )
client:send( "> " ) client:send( config.prompt and tostring(config.prompt) or "> " )
end end
function on_write( client ) function on_write( client )
end end
...@@ -118,6 +127,12 @@ function lock(client) ...@@ -118,6 +127,12 @@ function lock(client)
client.buffer = "" client.buffer = ""
return false return false
end end
function print_text(text)
return function(client)
client:append(string.gsub(text,"\r?\n","\r\n"))
return true
end
end
function help(client) function help(client)
client:append(" Telnet Specific Commands:") client:append(" Telnet Specific Commands:")
for c,t in pairs(commands) do for c,t in pairs(commands) do
...@@ -130,6 +145,8 @@ commands = { ...@@ -130,6 +145,8 @@ commands = {
["quit"] = { func = quit, help = "logout from telnet/shutdown VLC from local shell" }, ["quit"] = { func = quit, help = "logout from telnet/shutdown VLC from local shell" },
["logout"] = { func = logout, help = "logout" }, ["logout"] = { func = logout, help = "logout" },
["lock"] = { func = lock, help = "lock the telnet prompt" }, ["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 }, ["help"] = { func = help, help = "show this help", dovlm = true },
} }
...@@ -138,9 +155,10 @@ function client_command( client ) ...@@ -138,9 +155,10 @@ function client_command( client )
client.buffer = "" client.buffer = ""
if not commands[cmd] or not commands[cmd].func or commands[cmd].dovlm then 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 -- 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 ) vlm_message_to_string( client, message )
if not commands[cmd] or not commands[cmd].func and not commands[cmd].dovlm then 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 return true
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment