summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-23 00:11:30 +0100
committerPixel <pixel@nobis-crew.org>2009-12-23 00:11:30 +0100
commitf6ac50837aabd69c6ea5892a858359f51f40ee03 (patch)
treefd6f7007d543de2cca7a813e8efbf156089aa0eb
parent95b71cfc474f247e7e1081ea67c7a2166ddd3805 (diff)
Mbmbmlmlm \r is evil.
-rw-r--r--dalos-binaryops.lua228
-rw-r--r--dalos-buffer.lua60
-rw-r--r--dalos-hexview.lua320
-rw-r--r--dalos-input.lua88
-rw-r--r--dalos-limiter.lua118
-rw-r--r--dalos-luafilter.lua276
-rw-r--r--dalos-luahandle.lua102
-rw-r--r--dalos-tee.lua100
-rw-r--r--dalos-textbuffer.lua70
9 files changed, 681 insertions, 681 deletions
diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua
index 1ced26f..59e8361 100644
--- a/dalos-binaryops.lua
+++ b/dalos-binaryops.lua
@@ -1,114 +1,114 @@
-dalosp.binaryops = {
- operations = {
- XOR = 0,
- AND = 1,
- OR = 2,
- ADD = 3,
- SUB = 4,
- },
-
- opnames = {
- [0] = "XOR",
- [1] = "AND",
- [2] = "OR",
- [3] = "ADD",
- [4] = "SUB",
- },
-
- configure = function (self)
- local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[
-Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur}
-Maximize: %b[No,Yes]{Check if you want to maximize the output}
-]], self.op or 0, self.maximize and 1 or 0)
- if accept then
- self.extra.op = operation
- self.extra.maximize = maximize == 1
- self:input_change()
- end
- end,
-
- get_settings = function (self)
- return { op = self.extra.op, maximize = self.extra.maximize }
- end,
-
- input_change = function (self, ind)
- local h1 = self:get_linked_input(1)
- local h2 = self:get_linked_input(2)
- local op = self.extra.op or dalosp.binaryops.operations.XOR
- if h1 and h2 then
- self.color = cd.GREEN
- local obj = {
- h1 = h1,
- h2 = h2,
- op = op,
- maximize = self.extra.maximize,
- offset = 0,
- size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()),
- getname = function () return self.name end,
- do_read = function (self, count)
- self.h1:seek(self.offset)
- self.h2:seek(self.offset)
-
- local t1, r1 = self.h1:read(count)
- local t2, r2 = self.h2:read(count)
- local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2)
- self.offset = self.offset + r
- if r == 0 then self.got_eof = true return 0 end
- local t = {}
- local op
- if self.op == dalosp.binaryops.operations.XOR then
- op = bit.bxor
- elseif self.op == dalosp.binaryops.operations.AND then
- op = bit.band
- elseif self.op == dalosp.binaryops.operations.OR then
- op = bit.bor
- elseif self.op == dalosp.binaryops.operations.ADD then
- op = function(a, b) return a + b end
- elseif self.op == dalosp.binaryops.operations.SUB then
- op = function(a, b) return a - b end
- end
- for i = 0, r - 1 do
- t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255)
- end
- return r, t
- end,
- }
- self:set_houtput(dalos.luahandle(obj))
- self.dcanvas:draw()
- else
- self.color = cd.YELLOW
- self:set_houtput(nil)
- self.dcanvas:draw()
- end
- end,
-
- draw = function (self, cv, x, y, w, h)
- dalosp.object.default_draw(self, cv, x, y, w, h)
- local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2)
- local op = self.extra.op or dalosp.binaryops.operations.XOR
- cv:TextAlignment(cd.CENTER)
- cv:Foreground(cd.BLACK)
- cv:Text(cx, cy, dalosp.binaryops.opnames[op])
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 2
- tab.noutputs = 1
- tab.otype = dalos.objtype.LUA_FILTER
- tab.configure = dalosp.binaryops.configure
- tab.input_change = dalosp.binaryops.input_change
- tab.default_name = "Binary Ops"
- tab.draw = dalosp.binaryops.draw
- tab.get_settings = dalosp.binaryops.get_settings
- tab.ntype = "Binary Ops"
- local extra = { }
- if settings then extra.op = settings.op extra.maximize = settings.maximize end
-
- local obj = dalos.object(d, tab, extra)
-
- return obj
- end,
-}
-
-dalos.binaryops = dalosp.binaryops.create
-dalos:register_obj("Binary Ops", dalos.binaryops)
+dalosp.binaryops = {
+ operations = {
+ XOR = 0,
+ AND = 1,
+ OR = 2,
+ ADD = 3,
+ SUB = 4,
+ },
+
+ opnames = {
+ [0] = "XOR",
+ [1] = "AND",
+ [2] = "OR",
+ [3] = "ADD",
+ [4] = "SUB",
+ },
+
+ configure = function (self)
+ local accept, operation, maximize = iup.GetParam(self.name .. " configuration", nil, [[
+Operation: %l|xor|and|or|add|sub|{Binary operation that's going to occur}
+Maximize: %b[No,Yes]{Check if you want to maximize the output}
+]], self.op or 0, self.maximize and 1 or 0)
+ if accept then
+ self.extra.op = operation
+ self.extra.maximize = maximize == 1
+ self:input_change()
+ end
+ end,
+
+ get_settings = function (self)
+ return { op = self.extra.op, maximize = self.extra.maximize }
+ end,
+
+ input_change = function (self, ind)
+ local h1 = self:get_linked_input(1)
+ local h2 = self:get_linked_input(2)
+ local op = self.extra.op or dalosp.binaryops.operations.XOR
+ if h1 and h2 then
+ self.color = cd.GREEN
+ local obj = {
+ h1 = h1,
+ h2 = h2,
+ op = op,
+ maximize = self.extra.maximize,
+ offset = 0,
+ size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()),
+ getname = function () return self.name end,
+ do_read = function (self, count)
+ self.h1:seek(self.offset)
+ self.h2:seek(self.offset)
+
+ local t1, r1 = self.h1:read(count)
+ local t2, r2 = self.h2:read(count)
+ local r = self.extra.maximize and math.max(r1, r2) or math.min(r1, r2)
+ self.offset = self.offset + r
+ if r == 0 then self.got_eof = true return 0 end
+ local t = {}
+ local op
+ if self.op == dalosp.binaryops.operations.XOR then
+ op = bit.bxor
+ elseif self.op == dalosp.binaryops.operations.AND then
+ op = bit.band
+ elseif self.op == dalosp.binaryops.operations.OR then
+ op = bit.bor
+ elseif self.op == dalosp.binaryops.operations.ADD then
+ op = function(a, b) return a + b end
+ elseif self.op == dalosp.binaryops.operations.SUB then
+ op = function(a, b) return a - b end
+ end
+ for i = 0, r - 1 do
+ t[i] = bit.band(op(t1[i % r1], t2[i % r2]), 255)
+ end
+ return r, t
+ end,
+ }
+ self:set_houtput(dalos.luahandle(obj))
+ self.dcanvas:draw()
+ else
+ self.color = cd.YELLOW
+ self:set_houtput(nil)
+ self.dcanvas:draw()
+ end
+ end,
+
+ draw = function (self, cv, x, y, w, h)
+ dalosp.object.default_draw(self, cv, x, y, w, h)
+ local cx, cy = x + w / 2, cv:InvertYAxis(y + h / 2)
+ local op = self.extra.op or dalosp.binaryops.operations.XOR
+ cv:TextAlignment(cd.CENTER)
+ cv:Foreground(cd.BLACK)
+ cv:Text(cx, cy, dalosp.binaryops.opnames[op])
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 2
+ tab.noutputs = 1
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.configure = dalosp.binaryops.configure
+ tab.input_change = dalosp.binaryops.input_change
+ tab.default_name = "Binary Ops"
+ tab.draw = dalosp.binaryops.draw
+ tab.get_settings = dalosp.binaryops.get_settings
+ tab.ntype = "Binary Ops"
+ local extra = { }
+ if settings then extra.op = settings.op extra.maximize = settings.maximize end
+
+ local obj = dalos.object(d, tab, extra)
+
+ return obj
+ end,
+}
+
+dalos.binaryops = dalosp.binaryops.create
+dalos:register_obj("Binary Ops", dalos.binaryops)
diff --git a/dalos-buffer.lua b/dalos-buffer.lua
index ecab2ed..8abcadc 100644
--- a/dalos-buffer.lua
+++ b/dalos-buffer.lua
@@ -1,30 +1,30 @@
-dalosp.buffer = {
- input_change = function (self, ind)
- local h = self:get_linked_input(1)
- if h then
- self.color = cd.GREEN
- local b = Buffer(true)
- b:copyfrom(self:get_linked_input(1))
- self:set_houtput(b)
- else
- self:set_houtput(nil)
- self.color = cd.YELLOW
- end
- self.dcanvas:draw()
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 1
- tab.noutputs = 1
- tab.otype = dalos.objtype.LUA_FILTER
- tab.default_name = "Buffer"
- tab.input_change = dalosp.buffer.input_change
- tab.ntype = "Buffer"
- local obj = dalos.object(d, tab, extra)
-
- return obj
- end,
-}
-
-dalos.buffer = dalosp.buffer.create
-dalos:register_obj("Buffer", dalos.buffer)
+dalosp.buffer = {
+ input_change = function (self, ind)
+ local h = self:get_linked_input(1)
+ if h then
+ self.color = cd.GREEN
+ local b = Buffer(true)
+ b:copyfrom(self:get_linked_input(1))
+ self:set_houtput(b)
+ else
+ self:set_houtput(nil)
+ self.color = cd.YELLOW
+ end
+ self.dcanvas:draw()
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 1
+ tab.noutputs = 1
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.default_name = "Buffer"
+ tab.input_change = dalosp.buffer.input_change
+ tab.ntype = "Buffer"
+ local obj = dalos.object(d, tab, extra)
+
+ return obj
+ end,
+}
+
+dalos.buffer = dalosp.buffer.create
+dalos:register_obj("Buffer", dalos.buffer)
diff --git a/dalos-hexview.lua b/dalos-hexview.lua
index a4915f4..cfd8652 100644
--- a/dalos-hexview.lua
+++ b/dalos-hexview.lua
@@ -1,160 +1,160 @@
-load "iupe-hexview.lua"
-load "iupe-hexview-toolbox.lua"
-
-dalosp.hexview = {
- activate = function (self)
- self.extra.hvdlg:show()
- end,
-
- input_change = function (self, ind)
- local extra = self.extra
- local hv = extra.hv
- local h = self:get_linked_input(ind)
- if not h then
- self.color = cd.YELLOW
- hv:updatehandle(nil)
- self.dcanvas:draw()
- return
- end
- if not h:canread() or not h:canseek() then
- self.color = cd.RED
- hv:updatehandle(nil)
- self.dcanvas:draw()
- return
- end
- self.color = cd.GREEN
- for i = 1, 12 do
- self:set_houtput(nil, i)
- self.oldcursors[i] = -1
- end
- hv:updatehandle(h)
- self.dcanvas:draw()
- end,
-
- configure = function (self)
- end,
-
- get_settings = function (self)
- local hv = extra.hv
- local r = {
- mcursor = hv.mcursor + 0,
- kcursor = hv.kcursor + 0,
- markers = {},
- filecursor = hv.filecursor + 0,
- nbbytes = hv.nbbytes + 0,
- nblines = hv.nblines + 0,
- }
- for i = 1, 10 do
- r.markers[i] = hv.markers[i] + 0
- end
- return r
- end,
-
- output_change = function (self, ind)
- self.watchees[ind] = self.outputs[ind] and true or false
- self:set_houtput(nil, ind)
- self.oldcursors[ind] = -1
- self:dalos_hv_cb(self.extra.hv)
- end,
-
- update_houtput = function (self, ind, cursor)
- local h = self:get_linked_input(1)
- local maxsize = h and h:getsize() or -1
- cursor = cursor + 0
- if cursor >= 0 and h and self.watchees[ind] then
- if cursor < maxsize then
- self:set_houtput(nil, ind)
- end
- local obj = {
- h = h,
- hvo = self,
- ind = ind,
- origin = cursor,
- size = maxsize - cursor,
- getname = function (self) return self.hvo.name .. ":" .. self.ind end,
- getmodif = function (self) return self.hvo:getmodif() end,
- do_seek = function (self)
- self.h:seek(self.offset + self.origin)
- end,
- do_read = function (self, count, userdata)
- return self.h:read(count, userdata)
- end,
- }
- self:set_houtput(dalos.luahandle(obj), ind)
- end
- end,
-
- dalos_hv_cb = function (self, hv, reset)
- local m
- for i = 1, 10 do
- m = hv.markers[i]
- if m and self.oldcursors[i] ~= m then
- self:update_houtput(i, m)
- self.oldcursors[i] = m
- end
- end
-
- m = hv.kcursor
- if m and self.oldcursors[11] ~= m then
- self:update_houtput(11, m)
- self.oldcursors[11] = m
- end
-
- m = hv.mcursor
- if m and self.oldcursors[12] ~= m then
- self:update_houtput(12, m)
- self.oldcursors[12] = m
- end
- end,
-
- create = function (d, tab, settings)
- tab.otype = dalos.objtype.LUA_FILTER
- tab.activate = dalosp.hexview.activate
- tab.input_change = dalosp.hexview.input_change
- tab.output_change = dalosp.hexview.output_change
- tab.configure = dalosp.hexview.configure
- tab.get_settings = dalosp.hexview.get_settings
- tab.ninputs = 1
- tab.noutputs = 12
- tab.default_name = "Hexview"
- tab.ntype = "Hexview"
-
- local extra = { }
-
- local obj = dalos.object(d, tab, extra)
-
- local hv = iupe.hexview { }
- local hvtb = iupe.hexview_toolbox { hexview = hv }
- local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" }
-
- extra.hv = hv
- extra.hvtb = hvtb
- extra.hvdlg = hvdlg
-
- obj.oldcursors = { }
- obj.watchees = { }
- obj.update_houtput = dalosp.hexview.update_houtput
- for i = 1, 12 do obj.oldcursors[i] = -1 end
-
- if settings then
- if settings.markers then
- for i = 1, 10 do
- if settings.markers[i] then hv.markers[i] = settings.markers[i] end
- end
- end
- if settings.mcursor then hv.mcursor = settings.mcursor end
- if settings.kcursor then hv.kcursor = settings.kcursor end
- if settings.filecursor then hv.filecursor = settings.filecursor end
- if settings.nbbytes then hv.nbbytes = settings.nbbytes end
- if settings.nblines then hv.nblines = settings.nblines end
- end
-
- hv:registercb(dalosp.hexview.dalos_hv_cb, obj)
- obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb
-
- return obj
- end,
-}
-
-dalos.hexview = dalosp.hexview.create
-dalos:register_obj("Hexview", dalos.hexview)
+load "iupe-hexview.lua"
+load "iupe-hexview-toolbox.lua"
+
+dalosp.hexview = {
+ activate = function (self)
+ self.extra.hvdlg:show()
+ end,
+
+ input_change = function (self, ind)
+ local extra = self.extra
+ local hv = extra.hv
+ local h = self:get_linked_input(ind)
+ if not h then
+ self.color = cd.YELLOW
+ hv:updatehandle(nil)
+ self.dcanvas:draw()
+ return
+ end
+ if not h:canread() or not h:canseek() then
+ self.color = cd.RED
+ hv:updatehandle(nil)
+ self.dcanvas:draw()
+ return
+ end
+ self.color = cd.GREEN
+ for i = 1, 12 do
+ self:set_houtput(nil, i)
+ self.oldcursors[i] = -1
+ end
+ hv:updatehandle(h)
+ self.dcanvas:draw()
+ end,
+
+ configure = function (self)
+ end,
+
+ get_settings = function (self)
+ local hv = extra.hv
+ local r = {
+ mcursor = hv.mcursor + 0,
+ kcursor = hv.kcursor + 0,
+ markers = {},
+ filecursor = hv.filecursor + 0,
+ nbbytes = hv.nbbytes + 0,
+ nblines = hv.nblines + 0,
+ }
+ for i = 1, 10 do
+ r.markers[i] = hv.markers[i] + 0
+ end
+ return r
+ end,
+
+ output_change = function (self, ind)
+ self.watchees[ind] = self.outputs[ind] and true or false
+ self:set_houtput(nil, ind)
+ self.oldcursors[ind] = -1
+ self:dalos_hv_cb(self.extra.hv)
+ end,
+
+ update_houtput = function (self, ind, cursor)
+ local h = self:get_linked_input(1)
+ local maxsize = h and h:getsize() or -1
+ cursor = cursor + 0
+ if cursor >= 0 and h and self.watchees[ind] then
+ if cursor < maxsize then
+ self:set_houtput(nil, ind)
+ end
+ local obj = {
+ h = h,
+ hvo = self,
+ ind = ind,
+ origin = cursor,
+ size = maxsize - cursor,
+ getname = function (self) return self.hvo.name .. ":" .. self.ind end,
+ getmodif = function (self) return self.hvo:getmodif() end,
+ do_seek = function (self)
+ self.h:seek(self.offset + self.origin)
+ end,
+ do_read = function (self, count, userdata)
+ return self.h:read(count, userdata)
+ end,
+ }
+ self:set_houtput(dalos.luahandle(obj), ind)
+ end
+ end,
+
+ dalos_hv_cb = function (self, hv, reset)
+ local m
+ for i = 1, 10 do
+ m = hv.markers[i]
+ if m and self.oldcursors[i] ~= m then
+ self:update_houtput(i, m)
+ self.oldcursors[i] = m
+ end
+ end
+
+ m = hv.kcursor
+ if m and self.oldcursors[11] ~= m then
+ self:update_houtput(11, m)
+ self.oldcursors[11] = m
+ end
+
+ m = hv.mcursor
+ if m and self.oldcursors[12] ~= m then
+ self:update_houtput(12, m)
+ self.oldcursors[12] = m
+ end
+ end,
+
+ create = function (d, tab, settings)
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.activate = dalosp.hexview.activate
+ tab.input_change = dalosp.hexview.input_change
+ tab.output_change = dalosp.hexview.output_change
+ tab.configure = dalosp.hexview.configure
+ tab.get_settings = dalosp.hexview.get_settings
+ tab.ninputs = 1
+ tab.noutputs = 12
+ tab.default_name = "Hexview"
+ tab.ntype = "Hexview"
+
+ local extra = { }
+
+ local obj = dalos.object(d, tab, extra)
+
+ local hv = iupe.hexview { }
+ local hvtb = iupe.hexview_toolbox { hexview = hv }
+ local hvdlg = iup.dialog { iup.hbox { iup.frame { hv }, iup.sbox { direction = "WEST", hvtb } }, title = obj.name, size = "500x" }
+
+ extra.hv = hv
+ extra.hvtb = hvtb
+ extra.hvdlg = hvdlg
+
+ obj.oldcursors = { }
+ obj.watchees = { }
+ obj.update_houtput = dalosp.hexview.update_houtput
+ for i = 1, 12 do obj.oldcursors[i] = -1 end
+
+ if settings then
+ if settings.markers then
+ for i = 1, 10 do
+ if settings.markers[i] then hv.markers[i] = settings.markers[i] end
+ end
+ end
+ if settings.mcursor then hv.mcursor = settings.mcursor end
+ if settings.kcursor then hv.kcursor = settings.kcursor end
+ if settings.filecursor then hv.filecursor = settings.filecursor end
+ if settings.nbbytes then hv.nbbytes = settings.nbbytes end
+ if settings.nblines then hv.nblines = settings.nblines end
+ end
+
+ hv:registercb(dalosp.hexview.dalos_hv_cb, obj)
+ obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb
+
+ return obj
+ end,
+}
+
+dalos.hexview = dalosp.hexview.create
+dalos:register_obj("Hexview", dalos.hexview)
diff --git a/dalos-input.lua b/dalos-input.lua
index be2cf75..625dcab 100644
--- a/dalos-input.lua
+++ b/dalos-input.lua
@@ -1,44 +1,44 @@
-dalosp.input = {
- get_settings = function (self)
- return { filename = self.extra.filename }
- end,
-
- configure = function (self)
- local dlg = iup.filedlg {
- dialogtype = "Open",
- file = self.extra.filename,
- }
- iup.Popup(dlg)
- if dlg.status ~= -1 then
- local s, v = pcall(Input, dlg.value)
- if s then
- self:set_houtput(v)
- return
- end
- end
- self:set_houtput(nil)
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 0
- tab.noutputs = 1
- tab.otype = dalos.objtype.HANDLE
- tab.configure = dalosp.input.configure
- tab.default_name = "Input"
- tab.ntype = "Input"
- tab.get_settings = dalosp.input.get_settings
- local extra = { }
- if settings then extra.filename = settings.filename end
- local obj = dalos.object(d, tab, extra)
-
- if extra.filename then
- local s, v = pcall(Input, extra.filename)
- if s then obj:set_houtput(v) end
- end
-
- return obj
- end,
-}
-
-dalos.input = dalosp.input.create
-dalos:register_obj("Input", dalos.input)
+dalosp.input = {
+ get_settings = function (self)
+ return { filename = self.extra.filename }
+ end,
+
+ configure = function (self)
+ local dlg = iup.filedlg {
+ dialogtype = "Open",
+ file = self.extra.filename,
+ }
+ iup.Popup(dlg)
+ if dlg.status ~= -1 then
+ local s, v = pcall(Input, dlg.value)
+ if s then
+ self:set_houtput(v)
+ return
+ end
+ end
+ self:set_houtput(nil)
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 0
+ tab.noutputs = 1
+ tab.otype = dalos.objtype.HANDLE
+ tab.configure = dalosp.input.configure
+ tab.default_name = "Input"
+ tab.ntype = "Input"
+ tab.get_settings = dalosp.input.get_settings
+ local extra = { }
+ if settings then extra.filename = settings.filename end
+ local obj = dalos.object(d, tab, extra)
+
+ if extra.filename then
+ local s, v = pcall(Input, extra.filename)
+ if s then obj:set_houtput(v) end
+ end
+
+ return obj
+ end,
+}
+
+dalos.input = dalosp.input.create
+dalos:register_obj("Input", dalos.input)
diff --git a/dalos-limiter.lua b/dalos-limiter.lua
index 99bd07f..b8387e3 100644
--- a/dalos-limiter.lua
+++ b/dalos-limiter.lua
@@ -1,59 +1,59 @@
-dalosp.limiter = {
- configure = function (self)
- local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[
-Limit: %i{The actual size this limiter is going to produce}
-]], self.op or 0, self.maximize and 1 or 0)
- if accept then
- self.extra.limit = limit
- self:input_change()
- end
- end,
-
- get_settings = function (self)
- return { limit = self.extra.limit }
- end,
-
- input_change = function (self, ind)
- local h = self:get_linked_input(1)
- if h then
- self.color = cd.GREEN
- local obj = {
- h = h,
- size = math.max(h:getsize(), self.limit),
- getname = function () return self.name end,
- do_read = function (self, count, userdata)
- return self.h:read(count, userdata)
- end,
- do_seek = function (self)
- self.h:seek(self.offset, SEEK_SET)
- end,
- }
- self:set_houtput(dalos.luahandle(obj))
- self.dcanvas:draw()
- else
- self.color = cd.YELLOW
- self:set_houtput(nil)
- self.dcanvas:draw()
- end
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 1
- tab.noutputs = 1
- tab.otype = dalos.objtype.LUA_FILTER
- tab.configure = dalosp.limiter.configure
- tab.input_change = dalosp.limiter.input_change
- tab.default_name = "Limiter"
- tab.ntype = "Limiter"
- tab.get_settings = dalosp.limiter.get_settings
- local extra = { }
- if settings then extra.limit = settings.limit end
-
- local obj = dalos.object(d, tab, extra)
-
- return obj
- end,
-}
-
-dalos.limiter = dalosp.limiter.create
-dalos:register_obj("Limiter", dalos.limiter)
+dalosp.limiter = {
+ configure = function (self)
+ local accept, limit = iup.GetParam(self.name .. " configuration", nil, [[
+Limit: %i{The actual size this limiter is going to produce}
+]], self.op or 0, self.maximize and 1 or 0)
+ if accept then
+ self.extra.limit = limit
+ self:input_change()
+ end
+ end,
+
+ get_settings = function (self)
+ return { limit = self.extra.limit }
+ end,
+
+ input_change = function (self, ind)
+ local h = self:get_linked_input(1)
+ if h then
+ self.color = cd.GREEN
+ local obj = {
+ h = h,
+ size = math.max(h:getsize(), self.limit),
+ getname = function () return self.name end,
+ do_read = function (self, count, userdata)
+ return self.h:read(count, userdata)
+ end,
+ do_seek = function (self)
+ self.h:seek(self.offset, SEEK_SET)
+ end,
+ }
+ self:set_houtput(dalos.luahandle(obj))
+ self.dcanvas:draw()
+ else
+ self.color = cd.YELLOW
+ self:set_houtput(nil)
+ self.dcanvas:draw()
+ end
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 1
+ tab.noutputs = 1
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.configure = dalosp.limiter.configure
+ tab.input_change = dalosp.limiter.input_change
+ tab.default_name = "Limiter"
+ tab.ntype = "Limiter"
+ tab.get_settings = dalosp.limiter.get_settings
+ local extra = { }
+ if settings then extra.limit = settings.limit end
+
+ local obj = dalos.object(d, tab, extra)
+
+ return obj
+ end,
+}
+
+dalos.limiter = dalosp.limiter.create
+dalos:register_obj("Limiter", dalos.limiter)
diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua
index b267142..20f4f99 100644
--- a/dalos-luafilter.lua
+++ b/dalos-luafilter.lua
@@ -1,138 +1,138 @@
-dalosp.luafilter = {
- default_code = [[
--- available globals:
-
--- ninputs, noutputs: numbers
-
--- get_input(ind): handle
--- del_output(ind): nil
--- new_output(ind): nil
--- set_color(c) : nil
-
-function activate()
-end
-
-function read(ind, count, userdata, offset)
-end
-
-function seek(ind, offset)
-end
-
-function input_change(ind)
-end
-]],
-
- get_settings = function (self)
- return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code }
- end,
-
- run_in_localenv = function (self, f, ...)
- local localenv = self.extra.localenv
- local metatable = getmetatable(_G)
- if not metatable then metatable = {} end
- local oldni, oldi = metatable.__newindex, metatable.__index
- metatable.__newindex = function (table, key, value)
--- print("Setting _G[" .. key .. "] = " .. tostring(value))
- localenv[key] = value
- end
- metatable.__index = function (table, key)
--- print("Getting _G[" .. key .. "]")
- local l = localenv[key]
- if l then return localenv[key] end
- return rawget(_G, key)
- end
- setmetatable(_G, metatable)
-
- if type(f) ~= "function" then f = localenv[f] end
- local rets = { true }
- if f then rets = { pcall(f, ...) } end
-
- metatable.__newindex, metatable.__index = oldni, oldi
- setmetatable(_G, metatable)
-
- if not rets[1] then error(rets[2]) end
- table.remove(rets, 1)
- return unpack(rets)
- end,
-
- load_code = function (self, code)
- self.extra.localenv = {
- ninputs = self.ninputs + 0,
- noutputs = self.noutputs + 0,
- get_input = function(ind) return self:get_linked_input(ind) end,
- del_output = function(ind) self:set_houtput(nil, ind) end,
- new_output = function(ind, size, name)
- self:set_houtput(dalos.luahandle{
- size = size,
- getname = function ()
- return name
- end,
- do_read = function (lh, count, userdata)
- return self:run_in_localenv("read", ind, count, userdata, lh.offset)
- end,
- do_seek = function (lh)
- return self:run_in_localenv("seek", ind, lh.offset)
- end,
- }, ind)
- end,
- set_color = function(c) self.color = c self:draw() end,
- }
- if code and code ~= "" then
- local f = loadstring(code)
- if f then self:run_in_localenv(f) end
- end
- end,
-
- input_change = function (self, ind)
- self:run_in_localenv("input_change", ind)
- end,
-
- configure = function (self)
- local okay = false
- local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code }
- local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end }
- local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end }
- local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" }
- local r = dlg:popup()
--- if r ~= iup.NOERROR then return end
- local newcode = text.value
- if newcode and okay then
- self.extra.code = newcode
- self:load_code(newcode)
- end
- end,
-
- activate = function (self)
- self:run_in_localenv "activate"
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = settings and settings.ninputs
- tab.noutputs = settings and settings.noutputs
- tab.otype = dalos.objtype.LUA_FILTER
- tab.configure = dalosp.luafilter.configure
- tab.activate = dalosp.luafilter.activate
- tab.input_change = dalosp.luafilter.input_change
- tab.default_name = "Lua Filter"
- tab.get_settings = dalosp.luafilter.get_settings
- tab.ntype = "Lua Filter"
- local extra = { localenv = {} }
- extra.code = settings and settings.code
- if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end
- local s = true
- while not s and not tab.ninputs or not tab.noutputs do
- s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1)
- end
-
- local obj = dalos.object(d, tab, extra)
-
- obj.load_code = dalosp.luafilter.load_code
- obj.run_in_localenv = dalosp.luafilter.run_in_localenv
- obj:load_code(extra.code)
-
- return obj
- end,
-}
-
-dalos.luafilter = dalosp.luafilter.create
-dalos:register_obj("Lua Filter", dalos.luafilter)
+dalosp.luafilter = {
+ default_code = [[
+-- available globals:
+
+-- ninputs, noutputs: numbers
+
+-- get_input(ind): handle
+-- del_output(ind): nil
+-- new_output(ind): nil
+-- set_color(c) : nil
+
+function activate()
+end
+
+function read(ind, count, userdata, offset)
+end
+
+function seek(ind, offset)
+end
+
+function input_change(ind)
+end
+]],
+
+ get_settings = function (self)
+ return { ninputs = self.ninputs, noutputs = self.noutputs, code = self.extra.code }
+ end,
+
+ run_in_localenv = function (self, f, ...)
+ local localenv = self.extra.localenv
+ local metatable = getmetatable(_G)
+ if not metatable then metatable = {} end
+ local oldni, oldi = metatable.__newindex, metatable.__index
+ metatable.__newindex = function (table, key, value)
+-- print("Setting _G[" .. key .. "] = " .. tostring(value))
+ localenv[key] = value
+ end
+ metatable.__index = function (table, key)
+-- print("Getting _G[" .. key .. "]")
+ local l = localenv[key]
+ if l then return localenv[key] end
+ return rawget(_G, key)
+ end
+ setmetatable(_G, metatable)
+
+ if type(f) ~= "function" then f = localenv[f] end
+ local rets = { true }
+ if f then rets = { pcall(f, ...) } end
+
+ metatable.__newindex, metatable.__index = oldni, oldi
+ setmetatable(_G, metatable)
+
+ if not rets[1] then error(rets[2]) end
+ table.remove(rets, 1)
+ return unpack(rets)
+ end,
+
+ load_code = function (self, code)
+ self.extra.localenv = {
+ ninputs = self.ninputs + 0,
+ noutputs = self.noutputs + 0,
+ get_input = function(ind) return self:get_linked_input(ind) end,
+ del_output = function(ind) self:set_houtput(nil, ind) end,
+ new_output = function(ind, size, name)
+ self:set_houtput(dalos.luahandle{
+ size = size,
+ getname = function ()
+ return name
+ end,
+ do_read = function (lh, count, userdata)
+ return self:run_in_localenv("read", ind, count, userdata, lh.offset)
+ end,
+ do_seek = function (lh)
+ return self:run_in_localenv("seek", ind, lh.offset)
+ end,
+ }, ind)
+ end,
+ set_color = function(c) self.color = c self:draw() end,
+ }
+ if code and code ~= "" then
+ local f = loadstring(code)
+ if f then self:run_in_localenv(f) end
+ end
+ end,
+
+ input_change = function (self, ind)
+ self:run_in_localenv("input_change", ind)
+ end,
+
+ configure = function (self)
+ local okay = false
+ local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code }
+ local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end }
+ local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end }
+ local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" }
+ local r = dlg:popup()
+-- if r ~= iup.NOERROR then return end
+ local newcode = text.value
+ if newcode and okay then
+ self.extra.code = newcode
+ self:load_code(newcode)
+ end
+ end,
+
+ activate = function (self)
+ self:run_in_localenv "activate"
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = settings and settings.ninputs
+ tab.noutputs = settings and settings.noutputs
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.configure = dalosp.luafilter.configure
+ tab.activate = dalosp.luafilter.activate
+ tab.input_change = dalosp.luafilter.input_change
+ tab.default_name = "Lua Filter"
+ tab.get_settings = dalosp.luafilter.get_settings
+ tab.ntype = "Lua Filter"
+ local extra = { localenv = {} }
+ extra.code = settings and settings.code
+ if not extra.code or extra.code == "" then extra.code = dalosp.luafilter.default_code end
+ local s = true
+ while not s and not tab.ninputs or not tab.noutputs do
+ s, tab.ninputs, tab.noutputs = iup.GetParam("Lua Filter", nil, "Inputs number: %i\nOutputs number: %i\n", 1, 1)
+ end
+
+ local obj = dalos.object(d, tab, extra)
+
+ obj.load_code = dalosp.luafilter.load_code
+ obj.run_in_localenv = dalosp.luafilter.run_in_localenv
+ obj:load_code(extra.code)
+
+ return obj
+ end,
+}
+
+dalos.luafilter = dalosp.luafilter.create
+dalos:register_obj("Lua Filter", dalos.luafilter)
diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua
index 332a90e..952f856 100644
--- a/dalos-luahandle.lua
+++ b/dalos-luahandle.lua
@@ -1,51 +1,51 @@
-dalosp.luahandle = {
- create = function (tab)
- local obj = {
- offset = 0,
- canread = function (self) return true end,
- canwrite = function (self) return false end,
- canseek = function (self) return true end,
- canwatch = function (self) return false end,
- tell = function (self) return self.offset end,
- getsize = function (self) return self.size end,
- getmodif = function (self) return 0 end,
- flush = function (self) return true end,
- seek = function (self, offset, wheel)
- if wheel == SEEK_SET then
- self.offset = offset
- elseif wheel == SEEK_CUR then
- self.offset = self.offset + offset
- elseif wheel == SEEK_END then
- self.offset = self.size + offset
- else
- error "Unknown wheel"
- end
- if self.offset < 0 then self.offset = 0 end
- if self.offset >= self.size then self.offset = self.size end
- if self.do_seek then self:do_seek() end
- return self.offset
- end,
- read = function (self, userdata, count)
- count = math.min(count, self.size - self.offset)
-
- if count == 0 then
- if self.got_eof then self.lh:close() end
- self.got_eof = true
- return 0
- end
-
- self.got_eof = false
-
- local r, t = self:do_read(count, userdata)
- self.offset = self.offset + r
- return r, t
- end,
- }
- for k, v in pairs(tab) do obj[k] = v end
- local newh = HandleLua(obj)
- obj.lh = newh
- return newh
- end,
-}
-
-dalos.luahandle = dalosp.luahandle.create
+dalosp.luahandle = {
+ create = function (tab)
+ local obj = {
+ offset = 0,
+ canread = function (self) return true end,
+ canwrite = function (self) return false end,
+ canseek = function (self) return true end,
+ canwatch = function (self) return false end,
+ tell = function (self) return self.offset end,
+ getsize = function (self) return self.size end,
+ getmodif = function (self) return 0 end,
+ flush = function (self) return true end,
+ seek = function (self, offset, wheel)
+ if wheel == SEEK_SET then
+ self.offset = offset
+ elseif wheel == SEEK_CUR then
+ self.offset = self.offset + offset
+ elseif wheel == SEEK_END then
+ self.offset = self.size + offset
+ else
+ error "Unknown wheel"
+ end
+ if self.offset < 0 then self.offset = 0 end
+ if self.offset >= self.size then self.offset = self.size end
+ if self.do_seek then self:do_seek() end
+ return self.offset
+ end,
+ read = function (self, userdata, count)
+ count = math.min(count, self.size - self.offset)
+
+ if count == 0 then
+ if self.got_eof then self.lh:close() end
+ self.got_eof = true
+ return 0
+ end
+
+ self.got_eof = false
+
+ local r, t = self:do_read(count, userdata)
+ self.offset = self.offset + r
+ return r, t
+ end,
+ }
+ for k, v in pairs(tab) do obj[k] = v end
+ local newh = HandleLua(obj)
+ obj.lh = newh
+ return newh
+ end,
+}
+
+dalos.luahandle = dalosp.luahandle.create
diff --git a/dalos-tee.lua b/dalos-tee.lua
index 5c9b26a..1d75fb2 100644
--- a/dalos-tee.lua
+++ b/dalos-tee.lua
@@ -1,50 +1,50 @@
-dalosp.tee = {
- NTEE = 16,
-
- set_out = function (self, h, ind)
- local name = h:getname()
- local obj = {
- h = h,
- size = h:getsize(),
- getname = function () return name end,
- do_read = function (self, count, userdata)
- self.h:seek(self.offset, SEEK_SET)
- return self.h:read(count, userdata)
- end,
- }
- self:set_houtput(dalos.luahandle(obj), ind)
- end,
-
- input_change = function (self, ind)
- local h = self:get_linked_input(1)
- if h then
- self.color = cd.GREEN
- for ind = 1, 16 do self:set_out(h, ind) end
- self.dcanvas:draw()
- else
- self.color = cd.YELLOW
- for i = 1, dalosp.tee.NTEE do
- self:set_houtput(nil, i)
- end
- self.dcanvas:draw()
- end
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 1
- tab.noutputs = dalosp.tee.NTEE
- tab.otype = dalos.objtype.LUA_FILTER
- tab.input_change = dalosp.tee.input_change
- tab.default_name = "Tee"
- tab.ntype = "Tee"
-
- local obj = dalos.object(d, tab)
-
- obj.set_out = dalosp.tee.set_out
-
- return obj
- end,
-}
-
-dalos.tee = dalosp.tee.create
-dalos:register_obj("Tee", dalos.tee)
+dalosp.tee = {
+ NTEE = 16,
+
+ set_out = function (self, h, ind)
+ local name = h:getname()
+ local obj = {
+ h = h,
+ size = h:getsize(),
+ getname = function () return name end,
+ do_read = function (self, count, userdata)
+ self.h:seek(self.offset, SEEK_SET)
+ return self.h:read(count, userdata)
+ end,
+ }
+ self:set_houtput(dalos.luahandle(obj), ind)
+ end,
+
+ input_change = function (self, ind)
+ local h = self:get_linked_input(1)
+ if h then
+ self.color = cd.GREEN
+ for ind = 1, 16 do self:set_out(h, ind) end
+ self.dcanvas:draw()
+ else
+ self.color = cd.YELLOW
+ for i = 1, dalosp.tee.NTEE do
+ self:set_houtput(nil, i)
+ end
+ self.dcanvas:draw()
+ end
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 1
+ tab.noutputs = dalosp.tee.NTEE
+ tab.otype = dalos.objtype.LUA_FILTER
+ tab.input_change = dalosp.tee.input_change
+ tab.default_name = "Tee"
+ tab.ntype = "Tee"
+
+ local obj = dalos.object(d, tab)
+
+ obj.set_out = dalosp.tee.set_out
+
+ return obj
+ end,
+}
+
+dalos.tee = dalosp.tee.create
+dalos:register_obj("Tee", dalos.tee)
diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua
index cd91689..a5a4f40 100644
--- a/dalos-textbuffer.lua
+++ b/dalos-textbuffer.lua
@@ -1,35 +1,35 @@
-dalosp.textbuffer = {
- get_settings = function (self)
- return { text = self.extra.text }
- end,
-
- activate = function (self)
- local text = self.extra.text or ""
- text = iup.GetText(self.name, text)
- if text then
- self.extra.text = text
- local b = Buffer(true)
- b:write(text)
- self:set_houtput(b)
- end
- end,
-
- create = function (d, tab, settings)
- tab.ninputs = 0
- tab.noutputs = 1
- tab.otype = dalos.objtype.HANDLE
- tab.activate = dalosp.textbuffer.activate
- tab.default_name = "Text Buffer"
- tab.ntype = "Text Buffer"
- tab.get_settings = dalosp.textbuffer.get_settings
- local extra = { }
- if settings then extra.text = settings.text end
-
- local obj = dalos.object(d, tab, extra)
-
- return obj
- end,
-}
-
-dalos.textbuffer = dalosp.textbuffer.create
-dalos:register_obj("Text Buffer", dalos.textbuffer)
+dalosp.textbuffer = {
+ get_settings = function (self)
+ return { text = self.extra.text }
+ end,
+
+ activate = function (self)
+ local text = self.extra.text or ""
+ text = iup.GetText(self.name, text)
+ if text then
+ self.extra.text = text
+ local b = Buffer(true)
+ b:write(text)
+ self:set_houtput(b)
+ end
+ end,
+
+ create = function (d, tab, settings)
+ tab.ninputs = 0
+ tab.noutputs = 1
+ tab.otype = dalos.objtype.HANDLE
+ tab.activate = dalosp.textbuffer.activate
+ tab.default_name = "Text Buffer"
+ tab.ntype = "Text Buffer"
+ tab.get_settings = dalosp.textbuffer.get_settings
+ local extra = { }
+ if settings then extra.text = settings.text end
+
+ local obj = dalos.object(d, tab, extra)
+
+ return obj
+ end,
+}
+
+dalos.textbuffer = dalosp.textbuffer.create
+dalos:register_obj("Text Buffer", dalos.textbuffer)