]> git.sesse.net Git - vlc/commitdiff
Implement lazy loading in icelast.lua, fix doc
authorJulien 'Lta' BALLET <contact@lta.io>
Tue, 21 Jan 2014 10:38:40 +0000 (11:38 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 21 Jan 2014 15:13:31 +0000 (16:13 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
share/lua/sd/README.txt
share/lua/sd/icecast.lua

index 9a0ed88d3a474ea61d0a0a0114de2ed5057fe1b2..41cdf44b3b89fc61b5426e036e7e84d23f70f92a 100644 (file)
@@ -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()
index d6ecefe29ffb35a6ca5fc8f1aea6734f94cbea32..5ad183b7040435ea345f9326cb04049c7287a72e 100644 (file)
  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 )