Write numbers to a file in lua in binary format

前端 未结 2 1521
我寻月下人不归
我寻月下人不归 2021-01-18 07:32

I have a big array with numbers I would like to write to a file.

But if I do this:

local out = io.open(\"file.bin\", \"wb\")
local i = 4324234
out:wr         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 08:09

    You could use lua struct for more fine-grained control over binary conversion.

    local struct = require('struct')
    out:write(struct.pack('i4',0x123432))
    

提交回复
热议问题