I'd like to deserialize some lua tables to binary files. in c++ I can just use something like "fout << (char*)(&value)" where "value" is an integer or something else. but how to do this in lua? when I open a file with 'b' and write number and string to it they are quite readable in notepad...how can I convert lua values to binary format?
Asked
Active
Viewed 100 times
0
-
pardon my ignorance but what is a "binary data" actually? I used to think it as something more convenient than plain text data which is how numbers are stored in memory(in c++). but here it appears to be just another encoding method. and why we use it at all? – sunsflower Oct 04 '16 at 05:42
-
Simply because number `255`(unsigned char) in ASCII is `32 35 35`(16) but `FF`(16) in "binary". – Aki Oct 04 '16 at 05:54
-
so we write hexadecimal to file and call them "binary file"? nothing more than an encoding method? – sunsflower Oct 04 '16 at 06:04
-
Lua 5.3 has string.pack function. For preview versions you can use some other libraries e.g. struct or vstruct. – moteus Oct 04 '16 at 06:07