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(-) 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