copy and paste this code (with "puny font"-mode - ctrl+p)
cls()
storage_readfn={peek,peek2,nil,peek4,[0]=bitread}
storage_writefn={poke,poke2,nil,poke4,[0]=bitwrite}
storage_adr=0x8000
storage_metabytefield={
__index=function(t,key)
return t.read(t.adr+t.byte*key)
end,
__newindex=function(t,key,value)
t.write(t.adr+t.byte*key,value)
end,
__len=function(t)
return t.len
end
}
storage_metadata={
__index=function (t,key)
local m=rawget(t,"_storage")
if tonum(key) then
local adr,byte,size=unpack(m._num)
if (key>0 and key<=size) return storage_readfn[byte](adr+byte*key)
elseif m[key] then
local adr,byte=unpack(m[key])
return storage_readfn[byte](adr)
end
end,
__newindex=function (t,key,value)
local m=rawget(t,"_storage")
if m._num and tonum(key) then
local adr,byte,size=unpack(m._num)
if (key>0 and key<=size) storage_writefn[byte](adr+byte*key,value)
elseif m[key] then
local adr,byte=unpack(m[key])
storage_writefn[byte](adr,value)
else
rawset(t,key,value)
end
end,
__len=function(t)
local m=rawget(t,"_storage")
return m._num and m._num[3] or 0
end,
__pairs=function(t)
local stage,v=1
return function(t,k)
--numbers
if stage==1 then
k+=1
if t._storage._num and k<=#t then
v=t[k]
else
stage,k=2
end
end
--storage
if stage==2 then
repeat
k,v=next(t._storage,k)
until k!="_num"
if (k) v=t[k] else stage=3
end
--normal table
if stage==3 then
repeat
k,v=next(t,k)
until k!="_storage"
end
return k,v
end,t,0
end
}
function storage_reserve(list,table)
local oldtable={}
table=table or {}
table._storage=table._storage or {}
setmetatable(table,storage_metadata)
local byte=1
for txt in all(split(list,"\n")) do
if (sub(txt,#txt)=="]") txt=sub(txt,1,#txt-1)
local c=ord(txt)
if txt=="" or c==45 then
--commend
elseif c==91 then
--[
local size=tonum(sub(txt,2))
table._storage._num={storage_adr-byte,byte,size}
storage_adr+=byte*size
elseif c==42 then
--*
byte=tonum(sub(txt,2))
elseif c==62 then
-->
txt=sub(txt,2)
add(oldtable,table)
local ntable=setmetatable({_storage={}},storage_metadata)
rawset(table,tonum(txt) or txt,ntable)
table=ntable
elseif c==60 then
--<
table=deli(oldtable)
else
table._storage[txt]={storage_adr,byte}
storage_adr+=byte
end
end
return table
end
storage_reserve( [[
>x
*1
hallo
>welt
[3]
<
-- txt
*2
score
xyz
>player
x
y
<
<
*1
>data
>1
[3]
<
>2
[3]
<
>3
[3]
<
<
]],_ENV)
x.hallo=10
x.score=512
x.xyz=0x7fff
x.neu="abc"
x.welt[1]=15
x.welt[2]=27
x.welt[3]=33
x.welt[4]=99
x.player.x=1003
x.player.y=1004
for k,v in pairs(x) do
?"entry:"..k.." = "..tostr(v)
if type(v)=="table" then
for k2,v2 in pairs(v) do
?"entry:"..k.."."..k2.." = "..tostr(v2)
end
end
end
for v in all(x) do
?v
end
for x=1,3 do
for y=1,3 do
data[x][y]=y*10+x
end
end
?data[1]
stop() |
run the code
it should output some code, now type:
?data[1] |
pico-8 will close without error message.
Thanks @GPI, this is fixed for PICO-8 0.2.7. The combination of a custom __pairs function, and the stop() at the end was causing a yield across C boundary the next time any command is entered at the prompt.
[Please log in to post a comment]




