From 80ba9b7a2031d3159932eb9e306b3c110c01cea6 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Thu, 1 Mar 2012 19:19:51 +0000 Subject: Modified to handle errors a bit better. Help patch changed to add some modules that will definitely load. svn path=/trunk/externals/loaders/pdlua/; revision=16046 --- examples/requirer.pd_lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'examples/requirer.pd_lua') diff --git a/examples/requirer.pd_lua b/examples/requirer.pd_lua index 4b6c4e9..b9fadce 100644 --- a/examples/requirer.pd_lua +++ b/examples/requirer.pd_lua @@ -1,15 +1,21 @@ -complex = require("complex") -sqlite3 = require("luasql.sqlite3") -- evil hack, below is lame - local R = pd.Class:new():register("requirer") function R:initialize(sel, atoms) - if type(atoms[1]) ~= "string" then return false end - -- require(atoms[1]) -- will this ever work? - for k,v in pairs(_G[atoms[1]]) do - pd.post(atoms[1].. "." .. tostring(k) .. " = " .. tostring(v)) + if type(atoms[1]) ~= "string" then + pd.post(self._name .. ": Missing module name") + return false + end + pd.post (self._name .. ": Looking for " .. atoms[1]) + require(atoms[1]) -- load the module + if _G[atoms[1]] == nil then + pd.post (self._name .. ": No such module (" .. atoms[1] .. ")") + else -- print out module contents + for k,v in pairs(_G[atoms[1]]) do + pd.post(atoms[1].. "." .. tostring(k) .. " = " .. tostring(v)) + end end self.inlets = 0 self.outlets = 0 return true end + -- cgit v1.2.1