Changeset d5107810595354bd93f6bf65713c039d1bc7cb8b
- Timestamp:
- 11/05/07 22:52:26
(8 months ago)
- Author:
- Antoine Cellerier <dionoea@videolan.org>
- git-committer:
- Antoine Cellerier <dionoea@videolan.org> 1194299546 +0000
- git-parent:
[94742be8ad29e8941d9eec6835f78633cf0f6142]
- git-author:
- Antoine Cellerier <dionoea@videolan.org> 1194299546 +0000
- Message:
- 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.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rde31813 |
rd510781 |
|
| 558 | 558 | |
|---|
| 559 | 559 | { "version", vlclua_version }, |
|---|
| | 560 | { "license", vlclua_license }, |
|---|
| 560 | 561 | { "should_die", vlclua_intf_should_die }, |
|---|
| 561 | 562 | { "quit", vlclua_quit }, |
|---|
| rbddd76b |
rd510781 |
|
| 116 | 116 | { |
|---|
| 117 | 117 | lua_pushstring( L, VLC_Version() ); |
|---|
| | 118 | return 1; |
|---|
| | 119 | } |
|---|
| | 120 | |
|---|
| | 121 | /***************************************************************************** |
|---|
| | 122 | * Get the VLC license msg/disclaimer |
|---|
| | 123 | *****************************************************************************/ |
|---|
| | 124 | int vlclua_license( lua_State *L ) |
|---|
| | 125 | { |
|---|
| | 126 | lua_pushstring( L, LICENSE_MSG ); |
|---|
| 118 | 127 | return 1; |
|---|
| 119 | 128 | } |
|---|
| rde31813 |
rd510781 |
|
| 145 | 145 | |
|---|
| 146 | 146 | int vlclua_version( lua_State * ); |
|---|
| | 147 | int vlclua_license( lua_State * ); |
|---|
| 147 | 148 | int vlclua_quit( lua_State * ); |
|---|
| 148 | 149 | |
|---|
| rde31813 |
rd510781 |
|
| 88 | 88 | const char *psz_command = luaL_checkstring( L, 2 ); |
|---|
| 89 | 89 | vlm_message_t *message; |
|---|
| 90 | | vlm_ExecuteCommand( p_vlm, psz_command, &message ); |
|---|
| | 90 | int i_ret; |
|---|
| | 91 | i_ret = vlm_ExecuteCommand( p_vlm, psz_command, &message ); |
|---|
| 91 | 92 | lua_settop( L, 0 ); |
|---|
| 92 | 93 | push_message( L, message ); |
|---|
| 93 | 94 | vlm_MessageDelete( message ); |
|---|
| 94 | | return 1; |
|---|
| | 95 | return 1 + vlclua_push_ret( L, i_ret ); |
|---|
| 95 | 96 | } |
|---|
| r94742be |
rd510781 |
|
| 22 | 22 | --]==========================================================================] |
|---|
| 23 | 23 | |
|---|
| 24 | | --[==========================================================================[ |
|---|
| | 24 | description= |
|---|
| | 25 | [============================================================================[ |
|---|
| | 26 | Remote control interface for VLC |
|---|
| | 27 | |
|---|
| 25 | 28 | This is a modules/control/rc.c look alike (with a bunch of new features) |
|---|
| 26 | 29 | |
|---|
| … | … | |
| 34 | 37 | Note: |
|---|
| 35 | 38 | -I luarc is an alias for -I lua --lua-intf rc |
|---|
| 36 | | --]==========================================================================] |
|---|
| | 39 | |
|---|
| | 40 | Configuration options setable throught the --lua-config option are: |
|---|
| | 41 | * hosts: A list of hosts to listen on. |
|---|
| | 42 | * host: A host to listen on. (won't be used if `hosts' is set) |
|---|
| | 43 | The following can be set using the --lua-config option or in the interface |
|---|
| | 44 | itself using the `set' command: |
|---|
| | 45 | * prompt: The prompt. |
|---|
| | 46 | * welcome: The welcome message. |
|---|
| | 47 | * width: The default terminal width (used to format text). |
|---|
| | 48 | * autocompletion: When issuing an unknown command, print a list of |
|---|
| | 49 | possible commands to autocomplete with. (0 to disable, |
|---|
| | 50 | 1 to enable). |
|---|
| | 51 | * autoalias: If autocompletion returns only one possibility, use it |
|---|
| | 52 | (0 to disable, 1 to enable). |
|---|
| | 53 | ]============================================================================] |
|---|
| 37 | 54 | |
|---|
| 38 | 55 | require("common") |
|---|
| … | … | |
| 49 | 66 | welcome = "Remote control interface initialized. Type `help' for help." |
|---|
| 50 | 67 | } |
|---|
| | 68 | |
|---|
| | 69 | --[[ Import custom environement variables from the command line config (if possible) ]] |
|---|
| | 70 | for k,v in pairs(env) do |
|---|
| | 71 | if config[k] then |
|---|
| | 72 | if type(env[k]) == type(config[k]) then |
|---|
| | 73 | env[k] = config[k] |
|---|
| | 74 | vlc.msg.dbg("set environement variable `"..k.."' to "..tonumber(env[k])) |
|---|
| | 75 | else |
|---|
| | 76 | vlc.msg.err("environement variable `"..k.."' should be of type "..type(env[k])..". config value will be discarded.") |
|---|
| | 77 | end |
|---|
| | 78 | end |
|---|
| | 79 | end |
|---|
| 51 | 80 | |
|---|
| 52 | 81 | --[[ Command functions ]] |
|---|
| … | … | |
| 159 | 188 | end |
|---|
| 160 | 189 | client:append("+----[ End of playlist ]") |
|---|
| | 190 | end |
|---|
| | 191 | |
|---|
| | 192 | function print_text(label,text) |
|---|
| | 193 | return function(name,client) |
|---|
| | 194 | client:append("+----[ "..label.." ]") |
|---|
| | 195 | client:append "|" |
|---|
| | 196 | for line in string.gmatch(text,".-\r?\n") do |
|---|
| | 197 | client:append("| "..string.gsub(line,"\r?\n","")) |
|---|
| | 198 | end |
|---|
| | 199 | client:append "|" |
|---|
| | 200 | client:append("+----[ End of "..string.lower(label).." ]") |
|---|
| | 201 | end |
|---|
| 161 | 202 | end |
|---|
| 162 | 203 | |
|---|
| … | … | |
| 353 | 394 | { "alias"; { func = skip(alias); args = "[cmd]"; help = "set/get command aliases"; adv = true } }; |
|---|
| 354 | 395 | { "eval"; { func = skip(eval); help = "eval some lua (*debug*)"; adv =true } }; -- FIXME: comment out if you're not debugging |
|---|
| | 396 | { "description"; { func = print_text("Description",description); help = "describe this module" } }; |
|---|
| | 397 | { "license"; { func = print_text("License message",vlc.license()); help = "print VLC's license message"; adv = true } }; |
|---|
| 355 | 398 | { "help"; { func = help; args = "[pattern]"; help = "a help message"; aliases = { "?" } } }; |
|---|
| 356 | 399 | { "longhelp"; { func = help; args = "[pattern]"; help = "a longer help message" } }; |
|---|
| … | … | |
| 448 | 491 | end |
|---|
| 449 | 492 | -- Print prompt when switching a client's status to `read' |
|---|
| 450 | | h.status_callbacks[host.status.read] = function(client) client:send( client.env.prompt ) end |
|---|
| | 493 | h.status_callbacks[host.status.read] = function(client) |
|---|
| | 494 | client:send( client.env.prompt ) |
|---|
| | 495 | end |
|---|
| 451 | 496 | |
|---|
| 452 | 497 | h:listen( config.hosts or config.host or "*console" ) |
|---|
| r786b6c4 |
rd510781 |
|
| 22 | 22 | --]==========================================================================] |
|---|
| 23 | 23 | |
|---|
| 24 | | --[==========================================================================[ |
|---|
| | 24 | description= |
|---|
| | 25 | [============================================================================[ |
|---|
| | 26 | VLM Interface plugin |
|---|
| | 27 | |
|---|
| 25 | 28 | Copy (features wise) of the original VLC modules/control/telnet.c module. |
|---|
| 26 | 29 | |
|---|
| … | … | |
| 32 | 35 | listen on stdin: vlc -I lua --lua-intf telnet --lua-config "telnet={host='*console'}" |
|---|
| 33 | 36 | listen on stdin + 2 ports on localhost: vlc -I lua --lua-intf telnet --lua-config "telnet={hosts={'localhost:4212','localhost:5678','*console'}}" |
|---|
| 34 | | --]==========================================================================] |
|---|
| | 37 | |
|---|
| | 38 | Configuration options setable throught the --lua-config option are: |
|---|
| | 39 | * hosts: A list of hosts to listen on (see examples above). |
|---|
| | 40 | * host: A host to listen on. (won't be used if `hosts' is set) |
|---|
| | 41 | * password: The password used for remote clients. |
|---|
| | 42 | * prompt: The prompt. |
|---|
| | 43 | ]============================================================================] |
|---|
| 35 | 44 | |
|---|
| 36 | 45 | require "host" |
|---|
| … | … | |
| 55 | 64 | end |
|---|
| 56 | 65 | function on_read( client ) |
|---|
| 57 | | client:send( "> " ) |
|---|
| | 66 | client:send( config.prompt and tostring(config.prompt) or "> " ) |
|---|
| 58 | 67 | end |
|---|
| 59 | 68 | function on_write( client ) |
|---|
| … | … | |
| 119 | 128 | return false |
|---|
| 120 | 129 | end |
|---|
| | 130 | function print_text(text) |
|---|
| | 131 | return function(client) |
|---|
| | 132 | client:append(string.gsub(text,"\r?\n","\r\n")) |
|---|
| | 133 | return true |
|---|
| | 134 | end |
|---|
| | 135 | end |
|---|
| 121 | 136 | function help(client) |
|---|
| 122 | 137 | client:append(" Telnet Specific Commands:") |
|---|
| … | … | |
| 127 | 142 | end |
|---|
| 128 | 143 | commands = { |
|---|
| 129 | | ["shutdown"] = { func = shutdown, help = "shutdown VLC" }, |
|---|
| 130 | | ["quit"] = { func = quit, help = "logout from telnet/shutdown VLC from local shell" }, |
|---|
| 131 | | ["logout"] = { func = logout, help = "logout" }, |
|---|
| 132 | | ["lock"] = { func = lock, help = "lock the telnet prompt" }, |
|---|
| 133 | | ["help"] = { func = help, help = "show this help", dovlm = true }, |
|---|
| | 144 | ["shutdown"] = { func = shutdown, help = "shutdown VLC" }, |
|---|
| | 145 | ["quit"] = { func = quit, help = "logout from telnet/shutdown VLC from local shell" }, |
|---|
| | 146 | ["logout"] = { func = logout, help = "logout" }, |
|---|
| | 147 | ["lock"] = { func = lock, help = "lock the telnet prompt" }, |
|---|
| | 148 | ["description"] = { func = print_text(description), help = "describe this module" }, |
|---|
| | 149 | ["license"] = { func = print_text(vlc.license()), help = "print VLC's license message" }, |
|---|
| | 150 | ["help"] = { func = help, help = "show this help", dovlm = true }, |
|---|
| 134 | 151 | } |
|---|
| 135 | 152 | |
|---|
| … | … | |
| 139 | 156 | if not commands[cmd] or not commands[cmd].func or commands[cmd].dovlm then |
|---|
| 140 | 157 | -- if it's not an interface specific command, it has to be a VLM command |
|---|
| 141 | | message = vlc.vlm.execute_command( vlm, cmd ) |
|---|
| | 158 | local message, vlc_err = vlc.vlm.execute_command( vlm, cmd ) |
|---|
| 142 | 159 | vlm_message_to_string( client, message ) |
|---|
| 143 | 160 | if not commands[cmd] or not commands[cmd].func and not commands[cmd].dovlm then |
|---|
| | 161 | if vlc_err ~= 0 then client:append( "Type `help' for help." ) end |
|---|
| 144 | 162 | return true |
|---|
| 145 | 163 | end |
|---|