incomplete work towards general ser and deser
This commit is contained in:
48
splubp.p8
48
splubp.p8
@@ -84,8 +84,8 @@ end
|
||||
--[[preserve-keys]] splubp = mknew{
|
||||
ptr = 0x8000,
|
||||
init = function(self)
|
||||
self.fmts,self.defers,self.files = {},{},{}
|
||||
-- fill from ffile or saved file
|
||||
self.fmts = {}
|
||||
if (not self.ffile) self.ffile, self.ptr = self:e()
|
||||
for f in all(split(self.ffile, "===", false)) do
|
||||
local tok = shatter(f)
|
||||
@@ -146,18 +146,19 @@ function splubp:emit_item(obj)
|
||||
if DEBUG then
|
||||
--[[global]] splubp_last_emit = obj
|
||||
end
|
||||
-- todo: should _addr skip the
|
||||
-- filename, instead?
|
||||
obj._addr = self.ptr
|
||||
self:write_s(obj._file)
|
||||
for row in all(self.fmts[split(filename, ".")[2]]) do
|
||||
local srow, scri = self.row, self.cri
|
||||
for row in all(self.fmts[split(obj._file, ".")[2]]) do
|
||||
self.row, self.cri = row, 1
|
||||
local alt = self.wdirectives[row[1]]
|
||||
if alt then
|
||||
alt(self, obj, row)
|
||||
alt(self, obj) -- they should check row
|
||||
else
|
||||
self:write_fmt(obj[row[1]], row, 2)
|
||||
self:wnx(obj[row[1]])
|
||||
end
|
||||
end
|
||||
self.row, self.cri = srow, scri
|
||||
end
|
||||
|
||||
-- TODO: splubp.wdirectives -- a
|
||||
@@ -165,7 +166,21 @@ end
|
||||
-- special values to
|
||||
-- functions to write them
|
||||
-- TODO: write_fmt: recursive
|
||||
-- writing thing
|
||||
-- writing thing. args:
|
||||
-- item
|
||||
-- fmt row (parsed)
|
||||
-- next column
|
||||
-- NOTE: args row and col might actually be self.row, self.cri.
|
||||
-- we probably need to push old values into locals and pop
|
||||
-- on return, in the emit_content_of_type helper, to support
|
||||
-- obj and potentially other nested parse scenarios
|
||||
-- NOTE: not actually recursive.
|
||||
-- right, this is literally just wnx isn't it? because the read version is rnx.
|
||||
-- now I have it based off wnx, setting row and cri appropriately.
|
||||
-- TODO: split emit_item up
|
||||
-- because write-without-name
|
||||
-- needs to be a thing, and
|
||||
-- write-with-name uses it
|
||||
|
||||
-- Write each argument as one
|
||||
-- byte at self.ptr, then
|
||||
@@ -262,3 +277,22 @@ function splubp:t()
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
-- read data of type (filetype)
|
||||
-- into table dest, without
|
||||
-- filename; do not set
|
||||
-- _file or _addr
|
||||
-- restores self.row and self.cr on return
|
||||
function splubp:rtp(dest, tp)
|
||||
local srow, scri = self.row, self.cri
|
||||
for row in all(self.fmts[tp]) do
|
||||
self.row, self.cri=row, 1
|
||||
local alt = self.rz[row[1]] -- rz: counterpart to wdirectives
|
||||
if alt then
|
||||
alt(self, dest)
|
||||
else
|
||||
dest[row[1]] = self:rnx()
|
||||
end
|
||||
end
|
||||
self.row, self.cri = srow, scri
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user