From: Antoine Cellerier Date: Mon, 5 Nov 2007 21:52:26 +0000 (+0000) Subject: * modules/misc/lua: X-Git-Tag: 0.9.0-test0~4687 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d5107810595354bd93f6bf65713c039d1bc7cb8b;p=vlc * 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. --- diff --git a/modules/misc/lua/intf.c b/modules/misc/lua/intf.c index 01d36a9e95..95d81119f7 100644 --- a/modules/misc/lua/intf.c +++ b/modules/misc/lua/intf.c @@ -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 }, diff --git a/modules/misc/lua/vlc.c b/modules/misc/lua/vlc.c index 7da1237de4..0fd8db7b9d 100644 --- a/modules/misc/lua/vlc.c +++ b/modules/misc/lua/vlc.c @@ -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 *****************************************************************************/ diff --git a/modules/misc/lua/vlc.h b/modules/misc/lua/vlc.h index 0c52cc85cf..2eba1b6006 100644 --- a/modules/misc/lua/vlc.h +++ b/modules/misc/lua/vlc.h @@ -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 */ diff --git a/modules/misc/lua/vlm.c b/modules/misc/lua/vlm.c index cbdf5ba87e..314bc2c195 100644 --- a/modules/misc/lua/vlm.c +++ b/modules/misc/lua/vlm.c @@ -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 ); } diff --git a/share/luaintf/rc.lua b/share/luaintf/rc.lua index c95f1a0dcb..b325489438 100644 --- a/share/luaintf/rc.lua +++ b/share/luaintf/rc.lua @@ -21,7 +21,10 @@ 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: @@ -33,7 +36,21 @@ 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" ) diff --git a/share/luaintf/telnet.lua b/share/luaintf/telnet.lua index 837ac8b513..1f40af01e7 100644 --- a/share/luaintf/telnet.lua +++ b/share/luaintf/telnet.lua @@ -21,7 +21,10 @@ 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: @@ -31,7 +34,13 @@ 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