diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/requirer-help.pd | 13 | ||||
-rw-r--r-- | examples/requirer.pd_lua | 20 |
2 files changed, 22 insertions, 11 deletions
diff --git a/examples/requirer-help.pd b/examples/requirer-help.pd index 85b3989..55fe144 100644 --- a/examples/requirer-help.pd +++ b/examples/requirer-help.pd @@ -1,8 +1,13 @@ -#N canvas 0 0 450 300 10; -#X obj 144 88 requirer complex; +#N canvas 592 156 450 300 10; +#X obj 144 118 requirer complex; #X obj 146 173 requirer sqlite3; #X text 57 27 This should find the package next to the .pd_lua?; -#X text 55 54 Or should it look next to the containing .pd patch?; +#X text 57 54 Or should it look next to the containing .pd patch?; #X text 56 142 This only "works" because of a dirty dirty hack...; -#X text 52 222 TODO: some kind of "my location" necessary for .pd_lua +#X text 52 242 TODO: some kind of "my location" necessary for .pd_lua scripts to access?; +#X text 45 90 If it fails a list of paths searched will appear in the +Pd console.; +#X obj 56 220 requirer string; +#X text 155 220 built-in modules are found OK; +#X obj 57 200 requirer math; 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 + |