Commit 2ff13467 authored by Julien 'Lta' BALLET's avatar Julien 'Lta' BALLET Committed by Jean-Baptiste Kempf

Implement lazy loading in icelast.lua, fix doc

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 648b2bc7
...@@ -27,12 +27,12 @@ VLC Lua SD modules should define two functions: ...@@ -27,12 +27,12 @@ VLC Lua SD modules should define two functions:
User defined modules stored in the share/lua/modules/ directory are User defined modules stored in the share/lua/modules/ directory are
available. Read the 'Two pass Initialization section' available. Read the 'Lazy initialization' section
Available VLC specific Lua modules: input, msg, net, object, sd, Available VLC specific Lua modules: input, msg, net, object, sd,
strings, variables, stream, gettext, xml. See lua/README.txt. strings, variables, stream, gettext, xml. See lua/README.txt.
## Two pass Initialization ## Lazy Initialization
SD Lua scripts are actually ran in two different contexts/interpreters. One of SD Lua scripts are actually ran in two different contexts/interpreters. One of
them is the one that will call your main() and search() functions. The other one them is the one that will call your main() and search() functions. The other one
...@@ -51,8 +51,9 @@ lazily_loaded = false ...@@ -51,8 +51,9 @@ lazily_loaded = false
dkjson = nil dkjson = nil
function lazy_load() function lazy_load()
if lazily_loaded ~= false then return nil end if lazily_loaded then return nil end
dkjson = require("dkjson") dkjson = require("dkjson")
lazily_loaded = true
end end
function descriptor() function descriptor()
......
...@@ -19,7 +19,14 @@ ...@@ -19,7 +19,14 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]] --]]
require "simplexml"
lazily_loaded = false
function lazy_load()
if lazily_loaded then return nil end
require "simplexml"
lazily_loaded = true
end
function descriptor() function descriptor()
return { title="Icecast Radio Directory" } return { title="Icecast Radio Directory" }
...@@ -30,6 +37,7 @@ function dropnil(s) ...@@ -30,6 +37,7 @@ function dropnil(s)
end end
function main() function main()
lazy_load()
local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml") local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml")
for _, station in ipairs( tree.children ) do for _, station in ipairs( tree.children ) do
simplexml.add_name_maps( station ) simplexml.add_name_maps( station )
......
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