aboutsummaryrefslogtreecommitdiff
path: root/examples/lsymbol2bytes.pd_lua
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2012-04-20 19:03:21 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 14:28:31 +0200
commit4bab8348d2842245d93833a80f0d4713f973069c (patch)
treeda59b8a15a89f14d97572797024010a7aa6ccc81 /examples/lsymbol2bytes.pd_lua
parent869a2ec9dc40ec39d6833e1bd8eaeaf630216e5a (diff)
Two objects to serialize symbols and floats.
svn path=/trunk/externals/loaders/pdlua/; revision=16129
Diffstat (limited to 'examples/lsymbol2bytes.pd_lua')
-rw-r--r--examples/lsymbol2bytes.pd_lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/lsymbol2bytes.pd_lua b/examples/lsymbol2bytes.pd_lua
new file mode 100644
index 0000000..d024072
--- /dev/null
+++ b/examples/lsymbol2bytes.pd_lua
@@ -0,0 +1,46 @@
+--[[
+ lsymbol2bytes
+ Output a symbol as a sequence of bytes
+ author Martin Peach 20120420
+--]]
+
+-- Pd class
+
+local Lsymbol2Bytes = pd.Class:new():register("lsymbol2bytes")
+
+function Lsymbol2Bytes:initialize(name, atoms)
+ self.inlets = 1
+ self.outlets = 1
+ return true
+end
+
+-- Lsymbol2Bytes:drip: output possibly multibyte characters from buf and output them as floats on [0..255]
+function Lsymbol2Bytes:drip(buf)
+ --pd.post(buf.. " size " .. #buf)
+ local i = 1, b
+ local len = #buf
+
+ for i = 1, len do
+ self:outlet(1, "float", {string.byte(buf, i)})
+ end
+end
+
+function Lsymbol2Bytes:in_1(sel, atoms) -- anything
+ --pd.post("sel is " .. sel);
+ --pd.post("number of atoms is ".. #atoms)
+ --for i,v in ipairs(atoms) do
+ -- pd.post(i .. " = " .. v)
+ --end
+ local buf
+ if sel == "symbol" then -- the usual case
+ buf = tostring(atoms[1])
+ self:drip(buf)
+ elseif #atoms == 0 then -- a selector
+ buf = tostring(sel)
+ self:drip(buf)
+ else -- reject non-symbols
+ self:error("lsymbol2bytes: input not a symbol")
+ end
+end
+-- end of lsymbol2bytes
+