--[[ file format document : int32 strtbloffset int32 n int32*n index table table*n strings table: int32 array int32 dict int8*(array+dict) type (align 4) value*array kvpair*dict kvpair: string k value v value: (union) int32 integer float real int32 boolean int32 table index int32 string offset type: (enum) 0 nil 1 integer 2 real 3 boolean 4 table 5 string ]] local ctd = {} local math = math local table = table local string = string function ctd.dump(root) local doc = { table_n = 0, table = {}, strings = {}, offset = 0, } local function dump_table(t) local index = doc.table_n + 1 doc.table_n = index doc.table[index] = false -- place holder local array_n = 0 local array = {} local kvs = {} local types = {} local function encode(v) local t = type(v) if t == "table" then local index = dump_table(v) return '\4', string.pack(" 0 and ik <= array_n) end end -- encode table local typeset = table.concat(types) local align = string.rep("\0", (4 - #typeset & 3) & 3) local tmp = { string.pack("