lua-users home
lua-l archive

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


I've recently been investigating Lua structure packing libraries. vstruct is a thing of beauty as it allows me to layout a format string that looks like a structure, and it supports names, tables etc. The downside is that compared to struct it's very slow. struct is orders of magnitude faster but it's interface is not so nice. It brings me to tears to choose a library for speed over beauty but performance is important to my project.

How easy would it be to rewrite certain parts of vstruct in C or maybe even front end struct with the same semantics as vstruct? The format string below is what
I've knocked up for vstruct.

local fmtstr =
[[
  request:  s4
  key:{
    department: s1
    employee_no: s5
  }
  name: s20
  addr1: s20
  addr2: s20
  addr3: s20
  phone_no: s8
  timestamp: s8
  salary: s8
  start_date: s8
  remarks: s32
  msg: s60
  upd_ind: {
    name: s1
    addr1: s1
    addr2: s1
    addr3: s1
    phone_no: s1
    salary: s1
    start_date: s1
    remarks: s1
  }
  browseeq: s8
  update_ind: s1
  delete_ind: s1
  add_ind: s1
  error_ind: s1
  browse_ind: s1
  dept_ind: s1
  count: s2
  total: s2
  item_no: s2
  sbtot: s2
  sbnum: s2
  lineout: { 10 * {
    filler1: s6
    employee_no: s5
    filler2: s3
    employee_name: s20
    filler3: s3
    employee_phone: s8
    filler4: s34
  }}
]]