From 66bffcc5a3b8544635d4bfbe261ef381d577502a Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Fri, 13 Jun 2008 12:14:16 +0200 Subject: [PATCH] Update lua intf scripts to new API (untested). --- modules/misc/lua/libs/net.c | 4 +-- share/lua/http/custom.lua | 2 +- share/lua/http/dialogs/footer | 2 +- share/lua/http/requests/browse.xml | 8 +++--- share/lua/http/requests/playlist.xml | 6 ++-- share/lua/http/requests/status.xml | 2 +- share/lua/http/requests/vlm.xml | 2 +- share/lua/http/requests/vlm_cmd.xml | 2 +- share/lua/intf/hotkeys.lua | 10 +++---- share/lua/intf/http.lua | 36 ++++++++++++------------ share/lua/intf/modules/host.lua | 41 +++++++--------------------- share/lua/intf/rc.lua | 14 +++++----- share/lua/intf/telnet.lua | 12 ++++---- 13 files changed, 59 insertions(+), 82 deletions(-) diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c index f9210b5444..dcf2166463 100644 --- a/modules/misc/lua/libs/net.c +++ b/modules/misc/lua/libs/net.c @@ -376,8 +376,8 @@ static const luaL_Reg vlclua_net_reg[] = { { "recv", vlclua_net_recv }, { "select", vlclua_net_select }, { "fd_set_new", vlclua_fd_set_new }, - { "fd_read", vlclua_fd_read }, - { "fd_write", vlclua_fd_write }, + { "read", vlclua_fd_read }, + { "write", vlclua_fd_write }, { "stat", vlclua_stat }, /* Not really "net" */ { "opendir", vlclua_opendir }, /* Not really "net" */ { NULL, NULL } diff --git a/share/lua/http/custom.lua b/share/lua/http/custom.lua index 962a04d61c..f0483d7e4f 100644 --- a/share/lua/http/custom.lua +++ b/share/lua/http/custom.lua @@ -22,4 +22,4 @@ function dialogs(...) end _G.dialogs = dialogs -_G.vlm = vlc.vlm.new() +_G.vlm = vlc.vlm() diff --git a/share/lua/http/dialogs/footer b/share/lua/http/dialogs/footer index dd48313ff6..7a2159148d 100644 --- a/share/lua/http/dialogs/footer +++ b/share/lua/http/dialogs/footer @@ -33,5 +33,5 @@ This dialog needs the following dialogs to be fully functional: Flash based remote playback - VideoLAN website
- + diff --git a/share/lua/http/requests/browse.xml b/share/lua/http/requests/browse.xml index c252085299..f1425e4106 100644 --- a/share/lua/http/requests/browse.xml +++ b/share/lua/http/requests/browse.xml @@ -29,15 +29,15 @@ vim:syntax=lua \n") end end diff --git a/share/lua/http/requests/playlist.xml b/share/lua/http/requests/playlist.xml index 13541993bc..1576216dac 100644 --- a/share/lua/http/requests/playlist.xml +++ b/share/lua/http/requests/playlist.xml @@ -30,14 +30,14 @@ vim:syntax=lua function print_playlist(item) if item.flags.disabled then return end if item.children then - local name = vlc.convert_xml_special_chars(item.name) + local name = vlc.strings.convert_xml_special_chars(item.name) print("") for _, c in ipairs(item.children) do print_playlist(c) end print("") else - local name, path = vlc.convert_xml_special_chars(item.name,item.path or "") + local name, path = vlc.strings.convert_xml_special_chars(item.name,item.path or "") print("") end end @@ -64,7 +64,7 @@ if _GET["search"] then else _G.search_key = nil end - local key = vlc.decode_uri(_GET["search"]) + local key = vlc.strings.decode_uri(_GET["search"]) p = vlc.playlist.search(key) else p = vlc.playlist.get() diff --git a/share/lua/http/requests/status.xml b/share/lua/http/requests/status.xml index 0b41fa0689..24aedf8463 100644 --- a/share/lua/http/requests/status.xml +++ b/share/lua/http/requests/status.xml @@ -132,7 +132,7 @@ local vout = input and vlc.object.find(input,'vout','child') "..tostring(v).."\n") diff --git a/share/lua/http/requests/vlm.xml b/share/lua/http/requests/vlm.xml index d26edeade7..19d3fb4503 100644 --- a/share/lua/http/requests/vlm.xml +++ b/share/lua/http/requests/vlm.xml @@ -149,7 +149,7 @@ local function print_msg(m) print("\n") end -local msg = vlc.vlm.execute_command(vlm,"show") +local msg = vlm:execute_command("show") print_xml(msg) --print_msg(msg) diff --git a/share/lua/http/requests/vlm_cmd.xml b/share/lua/http/requests/vlm_cmd.xml index 35b8516218..2e49db3bc4 100644 --- a/share/lua/http/requests/vlm_cmd.xml +++ b/share/lua/http/requests/vlm_cmd.xml @@ -25,7 +25,7 @@ ]]?> a.last + a.delta then a.times = 0 else @@ -82,9 +82,9 @@ function action_trigger( action ) end a.last = date table.insert(queue,action) - vlc.signal() + vlc.misc.signal() else - vlc.msg_err("Key `"..key.."' points to unknown action `"..bindings[key].."'.") + vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.") end end @@ -94,7 +94,7 @@ function key_press( var, old, new, data ) if bindings[key] then action_trigger(bindings[key]) else - vlc.msg_err("Key `"..key.."' isn't bound to any action.") + vlc.msg.err("Key `"..key.."' isn't bound to any action.") end end @@ -110,7 +110,7 @@ while not die do end table.remove(queue,1) else - die = vlc.lock_and_wait() + die = vlc.misc.lock_and_wait() end end diff --git a/share/lua/intf/http.lua b/share/lua/intf/http.lua index dde018e887..1ff7fe7a31 100644 --- a/share/lua/intf/http.lua +++ b/share/lua/intf/http.lua @@ -31,8 +31,6 @@ Configuration options: --]==========================================================================] -require "httpd" -require "acl" require "common" vlc.msg.info("Lua HTTP interface") @@ -69,10 +67,10 @@ function process_raw(filename) return assert(loadstring(code,filename)) end function process(filename) - local mtime = 0 -- vlc.fd.stat(filename).modification_time + local mtime = 0 -- vlc.net.stat(filename).modification_time local func = false -- process_raw(filename) return function(...) - local new_mtime = vlc.fd.stat(filename).modification_time + local new_mtime = vlc.net.stat(filename).modification_time if new_mtime ~= mtime then -- Re-read the file if it changed if mtime == 0 then @@ -122,7 +120,7 @@ function dirlisting(url,listing,acl_) ]] end - return h:file_new(url,"text/html",nil,nil,acl_,callback,nil) + return h:file(url,"text/html",nil,nil,acl_,callback,nil) end function file(h,path,url,acl_,mime) @@ -151,15 +149,15 @@ function file(h,path,url,acl_,mime) end return table.concat(page) end - return h:file_new(url or path,mime,nil,nil,acl_,callback,nil) + return h:file(url or path,mime,nil,nil,acl_,callback,nil) end function rawfile(h,path,url,acl_) local filename = path - local mtime = 0 -- vlc.fd.stat(filename).modification_time + local mtime = 0 -- vlc.net.stat(filename).modification_time local page = false -- io.open(filename):read("*a") local callback = function(data,request) - local new_mtime = vlc.fd.stat(filename).modification_time + local new_mtime = vlc.net.stat(filename).modification_time if mtime ~= new_mtime then -- Re-read the file if it changed if mtime == 0 then @@ -172,15 +170,15 @@ function rawfile(h,path,url,acl_) end return page end - return h:file_new(url or path,nil,nil,nil,acl_,callback,nil) + return h:file(url or path,nil,nil,nil,acl_,callback,nil) end function parse_url_request(request) if not request then return {} end t = {} for k,v in string.gmatch(request,"([^=&]+)=?([^=&]*)") do - local k_ = vlc.decode_uri(k) - local v_ = vlc.decode_uri(v) + local k_ = vlc.strings.decode_uri(k) + local v_ = vlc.strings.decode_uri(v) if t[k_] ~= nil then local t2 if type(t[k_]) ~= "table" then @@ -199,9 +197,9 @@ function parse_url_request(request) end local function find_datadir(name) - local list = vlc.datadir_list(name) + local list = vlc.misc.datadir_list(name) for _, l in ipairs(list) do - local s = vlc.fd.stat(l) + local s = vlc.net.stat(l) if s then return l end @@ -237,17 +235,17 @@ local function load_dir(dir,root,parent_acl) local my_acl = parent_acl do local af = dir.."/.hosts" - local s = vlc.fd.stat(af) + local s = vlc.net.stat(af) if s and s.type == "file" then -- We found an acl - my_acl = acl.new(false) + my_acl = vlc.acl(false) my_acl:load_file(af) end end - local d = vlc.fd.opendir(dir) + local d = vlc.net.opendir(dir) for _,f in ipairs(d) do if not string.match(f,"^%.") then - local s = vlc.fd.stat(dir.."/"..f) + local s = vlc.net.stat(dir.."/"..f) if s.type == "file" then local url if f == "index.html" then @@ -276,10 +274,10 @@ local function load_dir(dir,root,parent_acl) end local u = vlc.net.url_parse( config.host or "localhost:8080" ) -h = httpd.new(u.host,u.port) +h = vlc.httpd(u.host,u.port) load_dir( http_dir ) -while not die do die = vlc.lock_and_wait() end -- everything happens in callbacks +while not die do die = vlc.misc.lock_and_wait() end -- everything happens in callbacks -- FIXME: We shouldn't need to do this ourselves. for i=1,#files do diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua index 4d60ea6a5d..82867f6385 100644 --- a/share/lua/intf/modules/host.lua +++ b/share/lua/intf/modules/host.lua @@ -38,7 +38,7 @@ Example use: --or h:listen( { "localhost:4212", "*console" } ) -- The main loop - while not vlc.should_die() do + while not vlc.misc.should_die() do -- accept new connections h:accept() @@ -75,24 +75,9 @@ function host() local listeners = {} local status_callbacks = {} - -- private methods - local function new_fd_set() - function foo_fds(foo) - return function(fd,...) return foo(fd.fds,...) end - end - return { -- data - fds = vlc.fd.new_fd_set(), - -- methods - zero = foo_fds( vlc.fd.fd_zero ), - set = foo_fds( vlc.fd.fd_set ), - isset = foo_fds( vlc.fd.fd_isset ), - clr = foo_fds( vlc.fd.fd_clr ), - } - end - -- private data - local fds_read = new_fd_set() - local fds_write = new_fd_set() + local fds_read = vlc.net.fd_set_new() + local fds_write = vlc.net.fd_set_new() -- private methods local function client_accept( clients, listen ) @@ -102,7 +87,7 @@ function host() else wait = 0 end - return vlc.net.accept( listen, wait ) + return listen:accept( wait ) end local function fd_client( client ) @@ -130,14 +115,14 @@ function host() end local function write( client, data ) - return vlc.fd.write( client.wfd, data or client.buffer ) + return vlc.net.write( client.wfd, data or client.buffer ) end local function read( client, len ) if len then - return vlc.fd.read( client.rfd, len ) + return vlc.net.read( client.rfd, len ) else - return vlc.fd.read( client.rfd ) + return vlc.net.read( client.rfd ) end end @@ -200,7 +185,7 @@ function host() switch_status = switch_status, append = append, } - client:send( "VLC media player "..vlc.version().."\n" ) + client:send( "VLC media player "..vlc.misc.version().."\n" ) table.insert(clients, client) client:switch_status(status.password) end @@ -274,7 +259,7 @@ function host() wait = 0 end for _, listener in pairs(listeners.tcp.list) do - local fd = vlc.net.accept( listener, wait ) + local fd = listener:accept( wait ) new_client( h, fd, fd, client_type.net ) end end @@ -283,7 +268,7 @@ function host() local function _select( h, timeout ) local nfds = math.max( filter_client( fds_read, status.read, status.password ), filter_client( fds_write, status.write ) ) + 1 - local ret = vlc.net.select( nfds, fds_read.fds, fds_write.fds, + local ret = vlc.net.select( nfds, fds_read, fds_write, timeout or 0.5 ) local wclients = {} local rclients = {} @@ -311,12 +296,6 @@ function host() vlc.net.close(client.wfd) end end - - if listeners.tcp then - for _, listener in pairs(listeners.tcp.list) do - vlc.net.listen_close( listener ) - end - end end local function _broadcast( h, msg ) diff --git a/share/lua/intf/rc.lua b/share/lua/intf/rc.lua index 17a62789ec..191f919e8c 100644 --- a/share/lua/intf/rc.lua +++ b/share/lua/intf/rc.lua @@ -143,7 +143,7 @@ function shutdown(name,client) client:append("Bye-bye!") h:broadcast("Shutting down.") vlc.msg.info("Requested shutdown.") - vlc.quit() + vlc.misc.quit() end function quit(name,client) @@ -323,7 +323,7 @@ function playlist_status(name,client) end function is_playing(name,client) - if vlc.is_playing() then client:append "1" else client:append "0" end + if vlc.input.is_playing() then client:append "1" else client:append "0" end end function ret_print(foo,start,stop) @@ -438,11 +438,11 @@ commands_ordered = { { "faster"; { func = rate; help = "faster playing of stream" } }; { "slower"; { func = rate; help = "slower playing of stream" } }; { "normal"; { func = rate; help = "normal playing of stream" } }; - { "fullscreen"; { func = skip2(vlc.fullscreen); args = "[on|off]"; help = "toggle fullscreen"; aliases = { "f", "F" } } }; + { "fullscreen"; { func = skip2(vlc.video.fullscreen); args = "[on|off]"; help = "toggle fullscreen"; aliases = { "f", "F" } } }; { "info"; { func = input_info; help = "information about the current stream" } }; { "get_time"; { func = get_time("time"); help = "seconds elapsed since stream's beginning" } }; { "is_playing"; { func = is_playing; help = "1 if a stream plays, 0 otherwise" } }; - { "get_title"; { func = ret_print(vlc.get_title); help = "the title of the current stream" } }; + { "get_title"; { func = ret_print(vlc.input.get_title); help = "the title of the current stream" } }; { "get_length"; { func = get_time("length"); help = "the length of the current stream" } }; { "" }; { "volume"; { func = volume; args = "[X]"; help = "set/get audio volume" } }; @@ -465,7 +465,7 @@ commands_ordered = { { "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 } }; + { "license"; { func = print_text("License message",vlc.misc.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)" } }; @@ -542,7 +542,7 @@ function call_command(cmd,client,arg) end function call_libvlc_command(cmd,client,arg) - local ok, vlcerr, vlcmsg = pcall( vlc.libvlc_command, cmd, arg ) + local ok, vlcerr, vlcmsg = pcall( vlc.var.libvlc_command, cmd, arg ) if not ok then local a = arg or "" if a ~= "" then a = " " .. a end @@ -568,7 +568,7 @@ end h:listen( config.hosts or config.host or "*console" ) --[[ The main loop ]] -while not vlc.should_die() do +while not vlc.misc.should_die() do h:accept() local write, read = h:select(0.1) diff --git a/share/lua/intf/telnet.lua b/share/lua/intf/telnet.lua index 1f40af01e7..2f7bd3f125 100644 --- a/share/lua/intf/telnet.lua +++ b/share/lua/intf/telnet.lua @@ -101,13 +101,13 @@ h:listen( config.hosts or config.host or "localhost:4212" ) password = config.password or "admin" --[[ Launch vlm ]] -vlm = vlc.vlm.new() +vlm = vlc.vlm() --[[ Commands ]] function shutdown(client) h:broadcast("Shutting down.\r\n") vlc.msg.err("shutdown requested") - vlc.quit() + vlc.misc.quit() return true end function logout(client) @@ -146,7 +146,7 @@ commands = { ["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" }, + ["license"] = { func = print_text(vlc.misc.license()), help = "print VLC's license message" }, ["help"] = { func = help, help = "show this help", dovlm = true }, } @@ -155,7 +155,7 @@ 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 - local message, vlc_err = vlc.vlm.execute_command( vlm, cmd ) + local message, vlc_err = vlm:execute_command( 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 @@ -171,7 +171,7 @@ function client_command( client ) end --[[ The main loop ]] -while not vlc.should_die() do +while not vlc.misc.should_die() do h:accept() local w, r = h:select( 0.1 ) @@ -219,4 +219,4 @@ while not vlc.should_die() do end --[[ Clean up ]] -vlc.vlm.delete( vlm ) +vlm = nil -- 2.39.2