From 34dd8ccee048382aaae104159bdb6260be8df49e Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Dec 2009 15:24:13 +0100 Subject: Various fixes, and getting output on the struct. --- dalos-struct.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 9 deletions(-) (limited to 'dalos-struct.lua') diff --git a/dalos-struct.lua b/dalos-struct.lua index 84e9699..9bbe617 100644 --- a/dalos-struct.lua +++ b/dalos-struct.lua @@ -64,7 +64,8 @@ dalosp.struct = { input_change = function (self, ind) if ind == 1 then self:update_values() end if ind == 2 then - + local h = self:get_linked_input(2) + self:auto_template(dalosp.struct.templates, h:readstring()) end end, @@ -136,10 +137,7 @@ dalosp.struct = { self.extra.values_by_name[f.name] = v end self:output_selected() - local b = Buffer(true) - - ---- filling in the output structure in b - self:set_houtput(b, 2) + self:output_struct() else self:set_houtput(nil, 1) self:set_houtput(nil, 2) @@ -147,6 +145,43 @@ dalosp.struct = { end, output_selected = function (self) + local selected = self.extra.selected + local cache = self.extra.cache + local cursor = selected and cache[selected] or -1 + local h = self:get_linked_input(1) + if h and selected and selected > 0 and cursor >= 0 then + local field = self.extra.entries[selected].name + local maxsize = (cache[selected + 1] or self.extra.size) - cursor + h:seek(cursor) + local obj = { + h = h, + str = self, + origin = cursor, + field = field, + size = maxsize - cursor, + getname = function (self) return self.str.name .. ":" .. self.field end, + getmodif = function (self) return self.h: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), 1) + local b = Buffer(true) + b:write(field .. "\n") + self:set_houtput(b, 3) + else + self:set_houtput(nil, 1) + self:set_houtput(nil, 3) + end + end, + + output_struct = function (self) + local b = Buffer(true) + dumpvars(b, self.extra.values_by_name, "data") + self:set_houtput(b, 2) end, cacheoffset = function (self) @@ -346,6 +381,8 @@ dalosp.struct = { if col == 5 then entries[lin].name = newval + self.struct:output_selected() + self.struct:output_struct() elseif col == 6 then entries[lin].type = dalosp.struct.rtypes[newval] self.struct:cacheoffset() @@ -413,7 +450,8 @@ dalosp.struct = { end, act_click_cb = function (self, lin, col, status) - + self.struct.extra.selected = lin + self.struct:output_selected() end, create = function (d, tab, settings) @@ -432,7 +470,8 @@ dalosp.struct = { local extra = { } if not settings then settings = {} end - extra.entries = settings.entries or {} + local entries = settings.entries or {} + extra.entries = entries local obj = dalos.object(d, tab, extra) @@ -450,8 +489,7 @@ dalosp.struct = { obj.update_values = dalosp.struct.update_values obj.read_value = dalosp.struct.read_value obj.output_selected = dalosp.struct.output_selected - - obj:cacheoffset() + obj.output_struct = dalosp.struct.output_struct local cmx = iup.matrix { numcol = 11, @@ -535,6 +573,14 @@ dalosp.struct = { title = obj.name, } + if entries then + obj.cfg_dlg.mx.numlin = #entries + obj.cfg_dlg.mx.numlin_visible = #entries + obj.act_dlg.mx.numlin = #entries + obj.act_dlg.mx.numlin_visible = #entries + end + obj:cacheoffset() + return obj end, -- cgit v1.2.3