From 1eef19bf7577799096f9133f38e8a9c8f0d65248 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 19 Dec 2009 21:08:42 -0800 Subject: Adding limiter. --- dalos-limiter.lua | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 dalos-limiter.lua (limited to 'dalos-limiter.lua') diff --git a/dalos-limiter.lua b/dalos-limiter.lua new file mode 100644 index 0000000..8f1a863 --- /dev/null +++ b/dalos-limiter.lua @@ -0,0 +1,86 @@ +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, + + input_change = function (self, ind) + local h = self:get_linked_input(1) + if h then + self.color = cd.GREEN + local obj = { + h = h, + offset = 0, + size = math.max(h:getsize(), self.limit), + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + getname = function (self) return 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 + self.h:seek(self.offset) + 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 = self.h:read(count, userdata) + self.offset = self.offset + r + return r + end, + } + local newh = HandleLua(obj) + obj.lh = newh + self:set_houtput(newh) + self.dcanvas:draw() + else + self.color = cd.YELLOW + self:set_houtput(nil) + self.dcanvas:draw() + end + end, + + + create = function (d, tab) + 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" + local extra = { } + + local obj = dalos.object(d, tab, extra) + end, +} + +dalos.limiter = dalosp.limiter.create +dalos:register_obj("Limiter", dalos.limiter) -- cgit v1.2.3 From cb7c8031ced6e9a393e8bdc3f409687741ef9feb Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 03:02:33 -0800 Subject: Factorizing some bits of code. --- dalos-binaryops.lua | 40 +++------------------------------------- dalos-hexview.lua | 43 ++++--------------------------------------- dalos-limiter.lua | 48 ++++++------------------------------------------ dalos-luahandle.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ dalos.lua | 5 +++-- 5 files changed, 67 insertions(+), 120 deletions(-) create mode 100644 dalos-luahandle.lua (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 356a58b..eda76e5 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -40,40 +40,8 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} maximize = self.extra.maximize, offset = 0, size = self.extra.maximize and math.max(h1:getsize(), h2:getsize()) or math.min(h1:getsize(), h2:getsize()), - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - getname = function (self) return 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 - return self.offset - end, - read = function (self, dummy, 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 - + getname = function () return self.name end, + do_read = function (self, dummy, count) self.h1:seek(self.offset) self.h2:seek(self.offset) @@ -101,9 +69,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} return r, t end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh) + self:set_houtput(dalos.luahandle(obj)) self.dcanvas:draw() else self.color = cd.YELLOW diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 8aa53bb..381ffd4 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -50,52 +50,17 @@ dalosp.hexview = { hvo = self, ind = ind, origin = cursor, - offset = 0, size = maxsize - cursor, - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return self.h:canwatch() end, getname = function (self) return self.hvo.name .. ":" .. self.ind end, - tell = function (self) return self.offset end, - getsize = function (self) return self.size end, getmodif = function (self) return self.hvo:getmodif() end, - flush = function (self) return self.hvo:flush() 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 + do_seek = function (self) self.h:seek(self.offset + self.origin) - 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 = self.h:read(count, userdata) - self.offset = self.offset + r - if r == 0 then self.got_eof = true end - return r + do_read = function (self, userdata, count) + return self.h:read(count, userdata) end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh, ind) + self:set_houtput(dalos.luahandle(obj), ind) end end, diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 8f1a863..b423d7a 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -15,51 +15,16 @@ Limit: %i{The actual size this limiter is going to produce} self.color = cd.GREEN local obj = { h = h, - offset = 0, size = math.max(h:getsize(), self.limit), - canread = function (self) return true end, - canwrite = function (self) return false end, - canseek = function (self) return true end, - canwatch = function (self) return false end, - getname = function (self) return 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 - self.h:seek(self.offset) - return self.offset + getname = function () return self.name end, + do_read = function (self, userdata, count) + return self.h:read(count, userdata) 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 = self.h:read(count, userdata) - self.offset = self.offset + r - return r + do_seek = function (self) + self.h:seek(self.offset, SEEK_SET) end, } - local newh = HandleLua(obj) - obj.lh = newh - self:set_houtput(newh) + self:set_houtput(dalos.luahandle(obj)) self.dcanvas:draw() else self.color = cd.YELLOW @@ -68,7 +33,6 @@ Limit: %i{The actual size this limiter is going to produce} end end, - create = function (d, tab) tab.ninputs = 1 tab.noutputs = 1 diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua new file mode 100644 index 0000000..3254490 --- /dev/null +++ b/dalos-luahandle.lua @@ -0,0 +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 + self:set_houtput(newh) + end, +} + +dalos.luahandle = dalosp.luahandle.create diff --git a/dalos.lua b/dalos.lua index b0b9aee..07b534f 100644 --- a/dalos.lua +++ b/dalos.lua @@ -550,11 +550,11 @@ dalosp.object = { end, default_activate = function (self) - print "activate" + print "default activate" end, default_configure = function (self) - print "configure" + print "default configure" end, change_curinput = function (self, delta) @@ -662,6 +662,7 @@ dalos.objtype = { ---------------- +load "dalos-luahandle.lua" load "dalos-hexview.lua" load "dalos-binaryops.lua" load "dalos-limiter.lua" -- cgit v1.2.3 From 775500b709be0d14ad89f63970bf971d68c89407 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 16:38:06 +0100 Subject: Introducing serialization / deserialization mechanism. --- dalos-binaryops.lua | 8 +++++++- dalos-hexview.lua | 32 +++++++++++++++++++++++++++++++- dalos-limiter.lua | 8 +++++++- dalos.lua | 5 +++++ 4 files changed, 50 insertions(+), 3 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index eda76e5..095e7eb 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -27,6 +27,10 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} 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) @@ -87,7 +91,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} cv:Text(cx, cy, dalosp.binaryops.opnames[op]) end, - create = function (d, tab) + create = function (d, tab, settings) tab.ninputs = 2 tab.noutputs = 1 tab.otype = dalos.objtype.LUA_FILTER @@ -95,7 +99,9 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} tab.input_change = dalosp.binaryops.input_change tab.default_name = "Binary Ops" tab.draw = dalosp.binaryops.draw + tab.get_settings = dalosp.binaryops.get_settings local extra = { } + if settings then extra.op = settings.op extra.maximize = settings.maximize end local obj = dalos.object(d, tab, extra) end, diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 381ffd4..f3111d7 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -34,6 +34,22 @@ dalosp.hexview = { 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 + rmarkers[i] = hv.markers[i] + 0 + end + return r + end, + output_change = function (self, ind) self.watchees[ind] = self.outputs[ind] and true or false end, @@ -87,12 +103,13 @@ dalosp.hexview = { end end, - create = function (d, tab) + 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.get_settings tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" @@ -114,6 +131,19 @@ dalosp.hexview = { 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 + hv.markers[i] = settings.markers[i] + end + end + hv.mcursor = settings.mcursor + hv.kcursor = settings.kcursor + hv.filecursor = settings.filecursor + hv.nbbytes = settings.nbbytes + hv.nblines = settings.nblines + end + hv:registercb(dalosp.hexview.dalos_hv_cb, obj) return obj diff --git a/dalos-limiter.lua b/dalos-limiter.lua index b423d7a..8454775 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -9,6 +9,10 @@ Limit: %i{The actual size this limiter is going to produce} 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 @@ -33,14 +37,16 @@ Limit: %i{The actual size this limiter is going to produce} end end, - create = function (d, tab) + 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.get_settings = dalosp.limiter.get_settings local extra = { } + if settings then extra.limit = settings.limit end local obj = dalos.object(d, tab, extra) end, diff --git a/dalos.lua b/dalos.lua index 07b534f..0b94d53 100644 --- a/dalos.lua +++ b/dalos.lua @@ -593,6 +593,10 @@ dalosp.object = { end end, + default_get_settings = function (self) + return {} + end, + create = function (dcanvas, tab, extra) if not tab then tab = {} end if not tab.name then @@ -623,6 +627,7 @@ dalosp.object = { input_change = tab.input_change or dalosp.object.default_inputchange, output_change = tab.output_change or dalosp.object.default_outputchange, set_houtput = dalosp.object.set_houtput, + get_settings = tab.get_setings or dalosp.object.default_get_settings, houtputs = {}, get_linked_input = dalosp.object.get_linked_input, dcanvas = dcanvas, -- cgit v1.2.3 From 3bf6f4ddfbcd61b28e918312090db8322d7ecc91 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 20 Dec 2009 17:57:53 +0100 Subject: Save is almost done. --- dalos-binaryops.lua | 3 +- dalos-hexview.lua | 1 + dalos-input.lua | 3 +- dalos-limiter.lua | 1 + dalos-textbuffer.lua | 3 +- dalos.lua | 82 ++++++++++++++++++++++++++++++++++++---------------- 6 files changed, 65 insertions(+), 28 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 095e7eb..17c9b63 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -100,6 +100,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} 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 @@ -108,4 +109,4 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} } dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) \ No newline at end of file +dalos:register_obj("Binary Ops", dalos.binaryops) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index f3111d7..26eaa77 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -113,6 +113,7 @@ dalosp.hexview = { tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" + tab.ntype = "Hexview" local extra = { } diff --git a/dalos-input.lua b/dalos-input.lua index 7588046..86dce5a 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -1,6 +1,6 @@ dalosp.input = { get_settings = function (self) - return { filename = extra.filename } + return { filename = self.extra.filename } end, configure = function (self) @@ -25,6 +25,7 @@ dalosp.input = { 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 diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 8454775..d27c0b5 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -44,6 +44,7 @@ Limit: %i{The actual size this limiter is going to produce} 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 diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index 5b15e5f..d52bb76 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -1,6 +1,6 @@ dalosp.textbuffer = { get_settings = function (self) - return { text = extra.text } + return { text = self.extra.text } end, activate = function (self) @@ -20,6 +20,7 @@ dalosp.textbuffer = { 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 diff --git a/dalos.lua b/dalos.lua index 1b64704..e226faf 100644 --- a/dalos.lua +++ b/dalos.lua @@ -7,8 +7,8 @@ load "iupe-tview.lua" if not dalosp then dalosp = {} end if not dalos then dalos = {} end -dalos.objects = {} -dalos.objects_by_name = {} +dalos.objectstypes = {} +dalos.objectstypes_by_name = {} dalosp.NORTH = 1 dalosp.SOUTH = 2 @@ -17,11 +17,11 @@ dalosp.EAST = 4 dalosp.cross = { } function dalos:register_obj(name, constructor) - if self.objects_by_name[name] then + if self.objectstypes_by_name[name] then error("An object of that name already exists: " .. name) end - table.insert(self.objects, { name = name, constructor = constructor, counter = 1 }) - self.objects_by_name[name] = #self.objects + table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1 }) + self.objectstypes_by_name[name] = #self.objectstypes if self.activemenu then self.activemenu:update_objects() end @@ -427,6 +427,39 @@ dalosp.menu = { end, action_save = function(self) + local s_obj = { } + if not dalos.active_canvas then return end + local d = dalos.active_canvas + for i, v in ipairs(d.objects) do + s_obj[i] = { x = v.x, y = v.y, name = v.obj.name, ntype = v.obj.ntype, settings = v.obj:get_settings(), lookup = v } + end + local s_links = { } + for iobj, obj in ipairs(d.objects) do + for iout, out in pairs(obj.obj.outputs) do + for ilookup, lobj in ipairs(s_obj) do + if lobj.lookup == out.obj then + table.insert(s_links, { src = iobj, dst = ilookup, isrc = iout, idst = out.ind }) + end + end + end + end + for i, v in ipairs(s_obj) do + v.lookup = nil + end + local save = { objects = s_obj, links = s_links } + local dlg = iup.filedlg { + dialogtype = "Save", + } + iup.Popup(dlg) + if dlg.status ~= -1 then + print(dlg.value) + local s, v = pcall(Output, dlg.value) + if s then + v:write "local " + dumpvars(v, save, "save") + v:write "return save" + end + end end, action_exit = function (self) @@ -484,25 +517,23 @@ dalosp.menu = { local east_menu = { radio = "1" } local west_menu = { radio = "1" } local south_menu = { radio = "1" } - if type(dalos.objects) == "table" then - local item - for k, v in ipairs(dalos.objects) do - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.add_object(canvas, v) end - table.insert(add_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end - table.insert(north_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end - table.insert(east_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end - table.insert(west_menu, item) - item = iup.item { title = v.name } - item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end - table.insert(south_menu, item) - end + local item + for k, v in ipairs(dalos.objectstypes) do + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.add_object(canvas, v) end + table.insert(add_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end + table.insert(north_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end + table.insert(east_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end + table.insert(west_menu, item) + item = iup.item { title = v.name } + item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end + table.insert(south_menu, item) end local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } @@ -623,6 +654,7 @@ dalosp.object = { outputs = {}, curinput = 1, curoutput = 1, + ntype = tab.ntype, quicksetting = tab.quicksetting, otype = tab.otype or dalos.objtype.DUMMY, activate = tab.activate or dalosp.object.default_activate, @@ -635,7 +667,7 @@ dalosp.object = { input_change = tab.input_change or dalosp.object.default_inputchange, output_change = tab.output_change or dalosp.object.default_outputchange, set_houtput = dalosp.object.set_houtput, - get_settings = tab.get_setings or dalosp.object.default_get_settings, + get_settings = tab.get_settings or dalosp.object.default_get_settings, houtputs = {}, get_linked_input = dalosp.object.get_linked_input, dcanvas = dcanvas, -- cgit v1.2.3 From 85d327879aafffcf0f3c811195cbdd07aa6eda7b Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 00:18:36 +0100 Subject: Fixing and finishing up serialization. --- dalos-binaryops.lua | 2 ++ dalos-hexview.lua | 16 ++++++------ dalos-input.lua | 4 ++- dalos-limiter.lua | 2 ++ dalos-textbuffer.lua | 2 ++ dalos.lua | 73 ++++++++++++++++++++++++++++++++++++++++++---------- 6 files changed, 77 insertions(+), 22 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 17c9b63..022020c 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -105,6 +105,8 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} if settings then extra.op = settings.op extra.maximize = settings.maximize end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos-hexview.lua b/dalos-hexview.lua index 26eaa77..a302d39 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -45,7 +45,7 @@ dalosp.hexview = { nblines = hv.nblines + 0, } for i = 1, 10 do - rmarkers[i] = hv.markers[i] + 0 + r.markers[i] = hv.markers[i] + 0 end return r end, @@ -109,7 +109,7 @@ dalosp.hexview = { tab.input_change = dalosp.hexview.input_change tab.output_change = dalosp.hexview.output_change tab.configure = dalosp.hexview.configure - tab.get_settings = dalosp.get_settings + tab.get_settings = dalosp.hexview.get_settings tab.ninputs = 1 tab.noutputs = 12 tab.default_name = "Hexview" @@ -135,14 +135,14 @@ dalosp.hexview = { if settings then if settings.markers then for i = 1, 10 do - hv.markers[i] = settings.markers[i] + if settings.markers[i] then hv.markers[i] = settings.markers[i] end end end - hv.mcursor = settings.mcursor - hv.kcursor = settings.kcursor - hv.filecursor = settings.filecursor - hv.nbbytes = settings.nbbytes - hv.nblines = settings.nblines + 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) diff --git a/dalos-input.lua b/dalos-input.lua index 86dce5a..be2cf75 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -34,7 +34,9 @@ dalosp.input = { if extra.filename then local s, v = pcall(Input, extra.filename) if s then obj:set_houtput(v) end - end + end + + return obj end, } diff --git a/dalos-limiter.lua b/dalos-limiter.lua index d27c0b5..ee9b106 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -50,6 +50,8 @@ Limit: %i{The actual size this limiter is going to produce} if settings then extra.limit = settings.limit end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index d52bb76..cd91689 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -26,6 +26,8 @@ dalosp.textbuffer = { if settings then extra.text = settings.text end local obj = dalos.object(d, tab, extra) + + return obj end, } diff --git a/dalos.lua b/dalos.lua index e226faf..7f554d1 100644 --- a/dalos.lua +++ b/dalos.lua @@ -18,7 +18,7 @@ dalosp.cross = { } function dalos:register_obj(name, constructor) if self.objectstypes_by_name[name] then - error("An object of that name already exists: " .. name) + error("An object type of that name already exists: " .. name) end table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1 }) self.objectstypes_by_name[name] = #self.objectstypes @@ -27,6 +27,18 @@ function dalos:register_obj(name, constructor) end end +function dalos:clean() + local d = dalos.active_canvas + for k, v in ipairs(d.objects) do + for ind = 1, v.obj.noutputs do + d:destroylink(v, ind) + end + end + + while #d.objects ~= 0 do table.remove(d.objects) end + d.objects = {} +end + dalosp.canvas = { DARK_WHITE = cd.EncodeColor(224, 224, 224), BEZIER_CTRL_LEN = 40, @@ -243,9 +255,11 @@ dalosp.canvas = { end end, - createlink = function (self, src, dst) - local oldsrc = src.obj.outputs[src.obj.curoutput] - local olddst = dst.obj.inputs[dst.obj.curinput] + createlink = function (self, src, dst, srcind, dstind) + if not srcind then srcind = src.obj.curoutput end + if not dstind then dstind = dst.obj.curinput end + local oldsrc = src.obj.outputs[srcind] + local olddst = dst.obj.inputs[dstind] if oldsrc then oldsrc.obj.obj.inputs[oldsrc.ind] = nil oldsrc.obj.obj:input_change(oldsrc.ind) @@ -254,17 +268,18 @@ dalosp.canvas = { olddst.obj.obj.outputs[olddst.ind] = nil olddst.obj.obj:output_change(olddst.ind) end - src.obj.outputs[src.obj.curoutput] = { obj = dst, ind = dst.obj.curinput } - dst.obj.inputs[dst.obj.curinput] = { obj = src, ind = src.obj.curoutput } - src.obj:output_change(src.obj.curoutput) - dst.obj:input_change(dst.obj.curinput) + src.obj.outputs[src.obj.curoutput] = { obj = dst, ind = dstind } + dst.obj.inputs[dst.obj.curinput] = { obj = src, ind = srcind } + src.obj:output_change(srcind) + dst.obj:input_change(dstind) end, - destroylink = function (self, src) - local oldsrc = src.obj.outputs[src.obj.curoutput] + destroylink = function (self, src, ind) + if not ind then ind = src.obj.curoutput end + local oldsrc = src.obj.outputs[ind] if oldsrc then - src.obj.outputs[src.obj.curoutput] = nil - src.obj:output_change(src.obj.curoutput) + src.obj.outputs[ind] = nil + src.obj:output_change(ind) oldsrc.obj.obj.inputs[oldsrc.ind] = nil oldsrc.obj.obj:input_change(oldsrc.ind) @@ -424,6 +439,39 @@ dalosp.canvas = { dalosp.menu = { action_load = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + } + iup.Popup(dlg) + if dlg.status == -1 then return end + + local s, v = pcall(Input, dlg.value) + if not s then error("Problem loading file " .. dlg.value) end + local f = preload(v) + if not f then error("Syntax error loading file " .. dlg.value) end + local data = f() + local tlup = dalos.objectstypes_by_name + local ot = dalos.objectstypes + local d = dalos.active_canvas + local lup = {} + for k, v in ipairs(data.objects) do + if not tlup[v.ntype] then error("Object " .. v.ntype .. " isn't declared") end + end + dalos:clean() + for k, v in ipairs(data.objects) do + local tab = { x = v.x, y = v.y, name = v.name } + local o = ot[tlup[v.ntype]].constructor(d, tab, v.settings) + for iobj, obj in ipairs(d.objects) do + if obj.obj == o then + lup[iobj] = obj + end + end + end + for k, v in ipairs(data.links) do + if not lup[v.src] then error("Can't find object for id src " .. v.src) end + if not lup[v.dst] then error("Can't find object for id dst " .. v.dst) end + d:createlink(lup[v.src], lup[v.dst], v.isrc, v.idst) + end end, action_save = function(self) @@ -452,7 +500,6 @@ dalosp.menu = { } iup.Popup(dlg) if dlg.status ~= -1 then - print(dlg.value) local s, v = pcall(Output, dlg.value) if s then v:write "local " -- cgit v1.2.3 From e294e63159e9596dd23bdb33e6ac3c574c32289f Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 21 Dec 2009 21:22:38 +0100 Subject: Various fixes. --- dalos-binaryops.lua | 2 +- dalos-hexview.lua | 17 +++++++++++------ dalos-limiter.lua | 2 +- dalos-luahandle.lua | 2 +- dalos.lua | 8 ++++++-- iupe-hexview.lua | 30 ++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 022020c..1ced26f 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -45,7 +45,7 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} 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, dummy, count) + do_read = function (self, count) self.h1:seek(self.offset) self.h2:seek(self.offset) diff --git a/dalos-hexview.lua b/dalos-hexview.lua index a302d39..ee9412e 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -52,12 +52,16 @@ dalosp.hexview = { 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 maxsixe = h and h:getsize() or -1 - if h and self.watchees[ind] then + 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 @@ -72,7 +76,7 @@ dalosp.hexview = { do_seek = function (self) self.h:seek(self.offset + self.origin) end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, } @@ -84,20 +88,20 @@ dalosp.hexview = { local m for i = 1, 10 do m = hv.markers[i] - if self.oldcursors[i] ~= m then + if m and self.oldcursors[i] ~= m then self:update_houtput(i, m) self.oldcursors[i] = m end end m = hv.kcursor - if self.oldcursors[11] ~= m then + if m and self.oldcursors[11] ~= m then self:update_houtput(11, m) self.oldcursors[11] = m end m = hv.mcursor - if self.oldcursors[12] ~= m then + if m and self.oldcursors[12] ~= m then self:update_houtput(12, m) self.oldcursors[12] = m end @@ -146,6 +150,7 @@ dalosp.hexview = { end hv:registercb(dalosp.hexview.dalos_hv_cb, obj) + obj.dalos_hv_cb = dalosp.hexview.dalos_hv_cb return obj end, diff --git a/dalos-limiter.lua b/dalos-limiter.lua index ee9b106..99bd07f 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -21,7 +21,7 @@ Limit: %i{The actual size this limiter is going to produce} h = h, size = math.max(h:getsize(), self.limit), getname = function () return self.name end, - do_read = function (self, userdata, count) + do_read = function (self, count, userdata) return self.h:read(count, userdata) end, do_seek = function (self) diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua index 3254490..332a90e 100644 --- a/dalos-luahandle.lua +++ b/dalos-luahandle.lua @@ -44,7 +44,7 @@ dalosp.luahandle = { for k, v in pairs(tab) do obj[k] = v end local newh = HandleLua(obj) obj.lh = newh - self:set_houtput(newh) + return newh end, } diff --git a/dalos.lua b/dalos.lua index 7f554d1..06058de 100644 --- a/dalos.lua +++ b/dalos.lua @@ -16,6 +16,8 @@ dalosp.WEST = 3 dalosp.EAST = 4 dalosp.cross = { } +dalos.version = { MAJOR = 0, MINOR = 1, suffix = "alpha" } + function dalos:register_obj(name, constructor) if self.objectstypes_by_name[name] then error("An object type of that name already exists: " .. name) @@ -502,7 +504,9 @@ dalosp.menu = { if dlg.status ~= -1 then local s, v = pcall(Output, dlg.value) if s then - v:write "local " + v:write "---- Dalos save\nlocal " + dumpvars(v, dalos.version, "version") + v:write "if dalos.version.MAJOR < version.MAJOR or dalos.version.MAJOR == version.MAJOR and dalos.version.MINOR < version.MINOR then error 'Dalos version too old for this save.' end\n\nlocal " dumpvars(v, save, "save") v:write "return save" end @@ -519,7 +523,7 @@ dalosp.menu = { ButtonDefault = "1", Buttons = "OK", Title = "About", - Value = 'DALOS (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', + Value = 'DALOS ' .. dalos.version.MAJOR .. '.' .. dalos.version.MINOR .. dalos.version.suffix .. ' (c) 2009-2010 Nicolas "Pixel" Noble.\nThis is free software with ABSOLUTELY NO WARRANTY.\nPlease look at the COPYRIGHT file for details.', } dlg:popup() return iup.DEFAULT diff --git a/iupe-hexview.lua b/iupe-hexview.lua index 0567cd0..4b135f0 100644 --- a/iupe-hexview.lua +++ b/iupe-hexview.lua @@ -340,6 +340,36 @@ iupep.hexview = { elseif c == iup.K_m0 then kaction = true self.markers[10] = kcursor + elseif c == iup.K_c1 then + kaction = true + self.markers[1] = nil + elseif c == iup.K_c2 then + kaction = true + self.markers[2] = nil + elseif c == iup.K_c3 then + kaction = true + self.markers[3] = nil + elseif c == iup.K_c4 then + kaction = true + self.markers[4] = nil + elseif c == iup.K_c5 then + kaction = true + self.markers[5] = nil + elseif c == iup.K_c6 then + kaction = true + self.markers[6] = nil + elseif c == iup.K_c7 then + kaction = true + self.markers[7] = nil + elseif c == iup.K_c8 then + kaction = true + self.markers[8] = nil + elseif c == iup.K_c9 then + kaction = true + self.markers[9] = nil + elseif c == iup.K_c0 then + kaction = true + self.markers[10] = nil elseif c == iup.K_SP then kaction = true end -- cgit v1.2.3 From f6ac50837aabd69c6ea5892a858359f51f40ee03 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:11:30 +0100 Subject: Mbmbmlmlm \r is evil. --- dalos-binaryops.lua | 228 ++++++++++++++++++------------------ dalos-buffer.lua | 60 +++++----- dalos-hexview.lua | 320 +++++++++++++++++++++++++-------------------------- dalos-input.lua | 88 +++++++------- dalos-limiter.lua | 118 +++++++++---------- dalos-luafilter.lua | 276 ++++++++++++++++++++++---------------------- dalos-luahandle.lua | 102 ++++++++-------- dalos-tee.lua | 100 ++++++++-------- dalos-textbuffer.lua | 70 +++++------ 9 files changed, 681 insertions(+), 681 deletions(-) (limited to 'dalos-limiter.lua') 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) -- cgit v1.2.3 From 86df190bee91eb38038a39b98448dd1623db1b6f Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 00:25:32 +0100 Subject: Fixing limiter. --- dalos-limiter.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-limiter.lua b/dalos-limiter.lua index b8387e3..5badfbb 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -19,7 +19,7 @@ Limit: %i{The actual size this limiter is going to produce} self.color = cd.GREEN local obj = { h = h, - size = math.max(h:getsize(), self.limit), + size = math.min(h:getsize(), self.extra.limit), getname = function () return self.name end, do_read = function (self, count, userdata) return self.h:read(count, userdata) @@ -47,7 +47,8 @@ Limit: %i{The actual size this limiter is going to produce} tab.ntype = "Limiter" tab.get_settings = dalosp.limiter.get_settings local extra = { } - if settings then extra.limit = settings.limit end + if not settings then settings = {} end + extra.limit = settings.limit or 0 local obj = dalos.object(d, tab, extra) -- cgit v1.2.3 From 7fea58bef326515437b3729c749fd22d85c62aaa Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 23 Dec 2009 01:13:20 +0100 Subject: Adding category menus system. --- dalos-binaryops.lua | 2 +- dalos-buffer.lua | 2 +- dalos-hexview.lua | 2 +- dalos-input.lua | 2 +- dalos-limiter.lua | 2 +- dalos-luafilter.lua | 2 +- dalos-tee.lua | 2 +- dalos-textbuffer.lua | 2 +- dalos.lua | 49 +++++++++++++++++++++++++++++++++++++++++++------ 9 files changed, 51 insertions(+), 14 deletions(-) (limited to 'dalos-limiter.lua') diff --git a/dalos-binaryops.lua b/dalos-binaryops.lua index 59e8361..c739450 100644 --- a/dalos-binaryops.lua +++ b/dalos-binaryops.lua @@ -111,4 +111,4 @@ Maximize: %b[No,Yes]{Check if you want to maximize the output} } dalos.binaryops = dalosp.binaryops.create -dalos:register_obj("Binary Ops", dalos.binaryops) +dalos:register_obj("Binary Ops", dalos.binaryops, "Basic Filters") diff --git a/dalos-buffer.lua b/dalos-buffer.lua index 8abcadc..3743f46 100644 --- a/dalos-buffer.lua +++ b/dalos-buffer.lua @@ -27,4 +27,4 @@ dalosp.buffer = { } dalos.buffer = dalosp.buffer.create -dalos:register_obj("Buffer", dalos.buffer) +dalos:register_obj("Buffer", dalos.buffer, "Basic Filters") diff --git a/dalos-hexview.lua b/dalos-hexview.lua index cfd8652..79f2a08 100644 --- a/dalos-hexview.lua +++ b/dalos-hexview.lua @@ -157,4 +157,4 @@ dalosp.hexview = { } dalos.hexview = dalosp.hexview.create -dalos:register_obj("Hexview", dalos.hexview) +dalos:register_obj("Hexview", dalos.hexview, "Basic Viewers") diff --git a/dalos-input.lua b/dalos-input.lua index 625dcab..bf37b9d 100644 --- a/dalos-input.lua +++ b/dalos-input.lua @@ -41,4 +41,4 @@ dalosp.input = { } dalos.input = dalosp.input.create -dalos:register_obj("Input", dalos.input) +dalos:register_obj("Input", dalos.input, "Basic Inputs") diff --git a/dalos-limiter.lua b/dalos-limiter.lua index 5badfbb..5643f30 100644 --- a/dalos-limiter.lua +++ b/dalos-limiter.lua @@ -57,4 +57,4 @@ Limit: %i{The actual size this limiter is going to produce} } dalos.limiter = dalosp.limiter.create -dalos:register_obj("Limiter", dalos.limiter) +dalos:register_obj("Limiter", dalos.limiter, "Basic Filters") diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 20f4f99..8181442 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -135,4 +135,4 @@ end } dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter) +dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable") diff --git a/dalos-tee.lua b/dalos-tee.lua index 1d75fb2..b5193c0 100644 --- a/dalos-tee.lua +++ b/dalos-tee.lua @@ -47,4 +47,4 @@ dalosp.tee = { } dalos.tee = dalosp.tee.create -dalos:register_obj("Tee", dalos.tee) +dalos:register_obj("Tee", dalos.tee, "Basic Filters") diff --git a/dalos-textbuffer.lua b/dalos-textbuffer.lua index a5a4f40..2bda77f 100644 --- a/dalos-textbuffer.lua +++ b/dalos-textbuffer.lua @@ -32,4 +32,4 @@ dalosp.textbuffer = { } dalos.textbuffer = dalosp.textbuffer.create -dalos:register_obj("Text Buffer", dalos.textbuffer) +dalos:register_obj("Text Buffer", dalos.textbuffer, "Basic Inputs") diff --git a/dalos.lua b/dalos.lua index d8169e5..8e95028 100644 --- a/dalos.lua +++ b/dalos.lua @@ -38,7 +38,7 @@ function dalos:register_obj(name, constructor, category) if self.objectstypes_by_name[name] then error("An object type of that name already exists: " .. name) end - table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category or "Basic" }) + table.insert(self.objectstypes, { name = name, constructor = constructor, counter = 1, category = category }) self.objectstypes_by_name[name] = #self.objectstypes if self.activemenu then self.activemenu:update_objects() @@ -677,22 +677,59 @@ dalosp.menu = { local west_menu = { radio = "1" } local south_menu = { radio = "1" } local item + local add_submenus = { } + local north_submenus = { } + local east_submenus = { } + local west_submenus = { } + local south_submenus = { } + local category + local add_smenu, north_smenu, east_smenu, west_smenu, south_smenu + local categories = {} for k, v in ipairs(dalos.objectstypes) do + category = v.category + if category then + if not add_submenus[category] then + add_submenus[category] = { } + north_submenus[category] = { } + south_submenus[category] = { } + east_submenus[category] = { } + west_submenus[category] = { } + table.insert(categories, 1, category) + end + add_smenu = add_submenus[category] + north_smenu = north_submenus[category] + east_smenu = east_submenus[category] + west_smenu = west_submenus[category] + south_smenu = south_submenus[category] + else + add_smenu = add_menu + north_smenu = north_menu + east_smenu = east_menu + west_smenu = west_menu + south_smenu = south_menu + end item = iup.item { title = v.name } item.action = function (self) dalosp.menu.add_object(canvas, v) end - table.insert(add_menu, item) + table.insert(add_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.NORTH) end - table.insert(north_menu, item) + table.insert(north_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.EAST) end - table.insert(east_menu, item) + table.insert(east_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.WEST) end - table.insert(west_menu, item) + table.insert(west_smenu, item) item = iup.item { title = v.name } item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end - table.insert(south_menu, item) + table.insert(south_smenu, item) + end + for i, v in ipairs(categories) do + table.insert(add_menu, 1, iup.submenu { iup.menu(add_submenus[v]), title = v }) + table.insert(north_menu, 1, iup.submenu { iup.menu(north_submenus[v]), title = v }) + table.insert(south_menu, 1, iup.submenu { iup.menu(south_submenus[v]), title = v }) + table.insert(east_menu, 1, iup.submenu { iup.menu(east_submenus[v]), title = v }) + table.insert(west_menu, 1, iup.submenu { iup.menu(west_submenus[v]), title = v }) end local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } -- cgit v1.2.3