lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I have looked at http://lua-users.org/wiki/StructurePacking
Ihave tried vstruct ( works, but only read into a table(array), no
dictionary)
lunary it looks like it read into table but can not get it to work,
stream problem I think

It would be easier for me to write a C function and return a dictionary(
C background)

The documentation for vstruct could be much better, start with a very
simple working example


#!/usr/bin/env lua

require "vstruct"
require "serial"


local f = assert(io.open("SAVE10.GAM","rb"))

local sz = f:seek("end")
f:seek("set")
local stream = serial.filestream(f)
local block = 100

local data = "" block)

local fmt = "i4 s27 i4 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1 i1
i1 i1 i1 i1 i1 i1 i1 i1 i1"
local lfmt = {
    { "version", uint32},
    { "desc", cstring},
    { "gamtyp", uint8}
}
print ( type( lfmt), type(stream), stream, lfmt)
local out = vstruct.unpack(fmt,data)
f:seek("set")
local out2 = serial.read.struct(stream,lfmt) *****

for k,v in pairs(out2) do
    print( k,v)
end 

------
lua: /usr/share/lua/5.1/serial.lua:1147: no function to read field of
type nil
stack traceback:
    [C]: in function 'assert'
    /usr/share/lua/5.1/serial.lua:1147: in function '_struct'
    /usr/share/lua/5.1/serial.lua:1162: in function 'struct'
    struct.lua:25: in main chunk
    [C]: ?