start of splubp prototype
This commit is contained in:
97
splubp.p8
Normal file
97
splubp.p8
Normal file
@@ -0,0 +1,97 @@
|
||||
pico-8 cartridge // http://www.pico-8.com
|
||||
version 42
|
||||
__lua__
|
||||
-- splubp data transport
|
||||
-- by kistaro windrider
|
||||
|
||||
-- main
|
||||
|
||||
-- >8
|
||||
-- utilities
|
||||
|
||||
-- generate standard "overlay"
|
||||
-- constructor for type tt.
|
||||
-- if tt.init is defined, generated
|
||||
-- new calls tt.init(ret) after
|
||||
-- ret is definitely not nil,
|
||||
-- after calling setmetatable.
|
||||
-- use to initialize mutables.
|
||||
--
|
||||
-- if there was a previous new,
|
||||
-- it is invoked before
|
||||
-- setting tt's metatable, so
|
||||
-- each new will see its
|
||||
-- inheritance chain.
|
||||
function mknew(tt)
|
||||
local mt,oldinit,more = {__index=tt},tt.superinit,rawget(tt, "init")
|
||||
tt.new=function(ret)
|
||||
if(not ret) ret = {}
|
||||
ret.new = false
|
||||
setmetatable(ret, mt)
|
||||
if(oldinit) oldinit(ret)
|
||||
if (more) more(ret)
|
||||
return ret
|
||||
end
|
||||
|
||||
if oldinit and more then
|
||||
tt.superinit = function(ret)
|
||||
oldinit(ret)
|
||||
more(ret)
|
||||
end
|
||||
elseif more then
|
||||
tt.superinit = more
|
||||
end
|
||||
return tt
|
||||
end
|
||||
|
||||
function set(t)
|
||||
local ret = {}
|
||||
for v in all(t) do
|
||||
ret[v]=true
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
whitespace = set(split" ,\t,\n")
|
||||
|
||||
function trim(s)
|
||||
local f, e = 1, #s
|
||||
while (f <= e and whitespace[s[f]]) f += 1
|
||||
while (e >= f and whitespace[s[e]]) e -= 1
|
||||
if (f<e) return sub(s,f,e)
|
||||
return ""
|
||||
end
|
||||
|
||||
-- >8
|
||||
-- writer
|
||||
|
||||
splubp_writer = mknew{
|
||||
init = function(self)
|
||||
-- fill from single file
|
||||
self.fmts = self.fmts or {}
|
||||
if self.ffile then
|
||||
for f in all(split(self.ffile, "===", false)) do
|
||||
local ext, fmt = split(f, "---")
|
||||
self.fmts[trim(ext)] = trim(fmt)
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
-->8
|
||||
-- loader
|
||||
|
||||
-- essay: `e` directive
|
||||
-- reads int16 char count,
|
||||
-- then parses that many bytes
|
||||
-- into a string (via chr).
|
||||
-- returns string, new read offset.
|
||||
function splubp_read_essay(addr)
|
||||
local cs, n = {}, %addr
|
||||
for a2 = addr+2, addr+n+1 do
|
||||
add(cs, @a2)
|
||||
end
|
||||
return chr(unpack(cs)), addr+2+n
|
||||
end
|
||||
|
Reference in New Issue
Block a user