[vlc-commits] Implement lazy loading in icelast.lua, fix doc
Julien 'Lta' BALLET
git at videolan.org
Tue Jan 21 16:11:53 CET 2014
vlc | branch: master | Julien 'Lta' BALLET <contact at lta.io> | Tue Jan 21 11:38:40 2014 +0100| [929e33a02ea8ec37c84c5c25a7488bcde9ff2f65] | committer: Jean-Baptiste Kempf
Implement lazy loading in icelast.lua, fix doc
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=929e33a02ea8ec37c84c5c25a7488bcde9ff2f65
---
share/lua/sd/README.txt | 7 ++++---
share/lua/sd/icecast.lua | 10 +++++++++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/share/lua/sd/README.txt b/share/lua/sd/README.txt
index 9a0ed88..41cdf44 100644
--- a/share/lua/sd/README.txt
+++ b/share/lua/sd/README.txt
@@ -27,12 +27,12 @@ VLC Lua SD modules should define two functions:
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,
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
them is the one that will call your main() and search() functions. The other one
@@ -51,8 +51,9 @@ lazily_loaded = false
dkjson = nil
function lazy_load()
- if lazily_loaded ~= false then return nil end
+ if lazily_loaded then return nil end
dkjson = require("dkjson")
+ lazily_loaded = true
end
function descriptor()
diff --git a/share/lua/sd/icecast.lua b/share/lua/sd/icecast.lua
index d6ecefe..5ad183b 100644
--- a/share/lua/sd/icecast.lua
+++ b/share/lua/sd/icecast.lua
@@ -19,7 +19,14 @@
along with this program; if not, write to the Free Software
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()
return { title="Icecast Radio Directory" }
@@ -30,6 +37,7 @@ function dropnil(s)
end
function main()
+ lazy_load()
local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml")
for _, station in ipairs( tree.children ) do
simplexml.add_name_maps( station )
More information about the vlc-commits
mailing list