Thank you so much
Blob.lua - binary serialization library
-
- Citizen
- Posts: 65
- Joined: Wed Mar 07, 2018 11:21 pm
Re: Blob.lua - binary serialization library
MissDanish wrote: ↑Wed Nov 28, 2018 6:12 amCode: Select all
function saves_load() if love.filesystem.getInfo(saveListPath) ~= nil then saves = BlobReader(love.filesystem.read(saveListPath)) end end
If that's the issue, then just adding parentheses suffices:
Code: Select all
function saves_load()
if love.filesystem.getInfo(saveListPath) ~= nil then
saves = BlobReader((love.filesystem.read(saveListPath)))
end
end
Re: Blob.lua - binary serialization library
Right, thanks.
I've changed the constructor and made the second parameter a variant type. It now accepts the love.filesystem.read() return values without the parentheses.
Code: Select all
local BlobReader = require('BlobReader')
local r = BlobReader(love.filesystem.read('main.lua'))
print(r:raw(r:size()))
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: Blob.lua - binary serialization library
Hi, it says support for c data type. Would this be compatible for https://github.com/novemberisms/brinevector
?
?
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Re: Blob.lua - binary serialization library
Not fully.yetneverdone wrote: ↑Fri Jan 25, 2019 1:50 am Hi, it says support for c data type. Would this be compatible for https://github.com/novemberisms/brinevector
?
This works:
Code: Select all
local v = Vector(23, 42)
-- serialize
local w = BlobWriter()
w:number(v.x):number(v.y)
-- deserialize
local r = BlobReader(w:tostring())
v = Vector(r:number(), r:number())
Code: Select all
local t = { Vector(23, 42) }
BlobWriter():write(t) -- error, can't serialize cdata in tables
Code: Select all
local v = Vector(23, 42)
local w = BlobWriter()
w:table(v) -- works
Code: Select all
local r = BlobReader(w:tostring())
local v = r:table()
print(v.x, v.y) -- works
print(v.length) -- does not work, v is a plain table, not a Vector
v = Vector(v.x, v.y) -- now v is a Vector again
print(v.length) -- works
Code: Select all
local v = Vector(23, 42)
local w = BlobWriter()
w:raw(v, ffi.sizeof(v))
local r = BlobReader(w:tostring())
local v2 = ffi.cast('brinevector*', r:raw(ffi.sizeof('brinevector')))
print(v2.x, v2.y, v2.length)
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: Blob.lua - binary serialization library
Thanks! Yeah, vector support is really needed since serialization is used for saving objects.grump wrote: ↑Fri Jan 25, 2019 8:50 amNot fully.yetneverdone wrote: ↑Fri Jan 25, 2019 1:50 am Hi, it says support for c data type. Would this be compatible for https://github.com/novemberisms/brinevector
?
This works:Serializing tables that contain Vectors is not supported. (I'm thinking about adding support for this)Code: Select all
local v = Vector(23, 42) -- serialize local w = BlobWriter() w:number(v.x):number(v.y) -- deserialize local r = BlobReader(w:tostring()) v = Vector(r:number(), r:number())
Serializing them directly with BlobWriter:table works, but that has drawbacks. BlobReader can't automatically recreate the Vector object.Code: Select all
local t = { Vector(23, 42) } BlobWriter():write(t) -- error, can't serialize cdata in tables
When you read this back, it becomes a plain table:Code: Select all
local v = Vector(23, 42) local w = BlobWriter() w:table(v) -- works
EDIT: this will also work:Code: Select all
local r = BlobReader(w:tostring()) local v = r:table() print(v.x, v.y) -- works print(v.length) -- does not work, v is a plain table, not a Vector v = Vector(v.x, v.y) -- now v is a Vector again print(v.length) -- works
I will add some code to simplify this a bit.Code: Select all
local v = Vector(23, 42) local w = BlobWriter() w:raw(v, ffi.sizeof(v)) local r = BlobReader(w:tostring()) local v2 = ffi.cast('brinevector*', r:raw(ffi.sizeof('brinevector'))) print(v2.x, v2.y, v2.length)
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Re: Blob.lua - binary serialization library
You can implement object saving without explicit ctype support if you use one of the methods I have shown in the previous comment.yetneverdone wrote: ↑Wed Jan 30, 2019 4:59 am Thanks! Yeah, vector support is really needed since serialization is used for saving objects.
Doing it automatically has proven somewhat difficult, so I'd need to write code to support custom types. Adding ctype (and class) support is on my list of TODOs, but the priority of the project is low, it may take some time.
Re: Blob.lua - binary serialization library
Still no support for cdata.
Re: Blob.lua - binary serialization library
cdata is supported. :raw can read and write cdata just fine.
All cdata has the same type ("cdata"). There is no ffi API that provides more detailled type information, which makes fully transparent support of cdata somewhat difficult to implement. Even if type information was available, serialization would break with opaque pointers, because in C there is no information about the size of data a pointer is pointing to.
Re: Blob.lua - binary serialization library
Yeah but that means I have to manually iterate over my tables doing hacky things instead of just this as per the example:
Code: Select all
local blob = BlobWriter()
blob:write(data)
Can I pass the ctype information to the library somehow? I have the string definition, after all.
Who is online
Users browsing this forum: RetroKevin and 2 guests