How many bytes does corona use for a number. Is it 64 or 32 bits?
Im trying to write bytes to a file and need to know the size of a number
How many bytes does corona use for a number. Is it 64 or 32 bits?
Im trying to write bytes to a file and need to know the size of a number
I believe that Lua out of the box uses doubles.
You can see some info on this here: http://bit.ly/1A7FQ8l
64 bit doubles, I would be *very* wary of relying on this
Lua does not use int’s. The data type for numbers is “double” floats.
or so I’ve been told
Rob
I’d first ask: why you want to dump binary data?
(why not json or xml? is file size that big an issue?)
What you’re asking about is a part of what it means to be a weakly/dynamically typed languages (though both of those terms are somewhat debated). The idea is that programmers shouldn’t need to define things as integers or floats, just use “numbers”, and the complier+run-time will just “figure it out” and “do the right thing”.
Most of the time, that works fine. But if you’re trying to write out the raw binary data, you might see some problems – as Rob mentioned, if you write out the binary “integer” data, you might find that it is actually in floating point format.
Perhaps I can help this discussion a bit. Back in the 1990’s when I was working for a company building online computer games and people were trying to play them on a 19,200 bps modem, packing information into as small a chunk of data as we could get away with was desirable. Our packets was a one byte command (giving us 256 possible things to tell the game to do, then we would have a two-byte length which represented the number of bytes that made up that packet of data. We could read just that amount and then unpack the data into char’s, int’s strings, etc. It was very important to be able to do bitwise math on things because frequently a single byte could represent 8 on/off settings.
However today, with the speed of transmission, this isn’t that big of a deal. A verbose, serialized text like JSON or XML is way easier to parse in a very standard way and the need for binary level packing just isn’t that important. However if you’re trying to do something like read the EXIF data from an image or write out the IPTC caption data to an image, those still need to be byte packed and you’re going to struggle trying to get Lua to do that. It’s not what the language was designed for.
Rob
My game we have several word list and they are saved as a bloom filter. If I save the bloom filter in string format it is 15 meg instead of 5 meg, and thats a big different if you have several word list.
And would not actually agree that lua is not design for it, one of the reasons lua is so popular is that you can always use the c language with. Unfortunately this is not possible with Corona.
But however, it seems to work, I split the double numbers in to 8 bytes and save the bytes to a binary file. And then I read byte by byte from the file and it works perfectly. Both android and apple uses little endian and I have tested it on several devices.
Right now I have 4 word lists, so 5 x 3 = 15 meg is much better then 15 * 3. Specially on an old device.
You can use C with Lua, but not with Corona SDK. You could either use Corona Cards or Corona Enterprise to be able to access the Lua-C bridge.
Rob
Yes I know you can use C with lua with Corona Enterprice, but if it cost 200 dollars a month, I would not say you support it for normal users
We don’t support it for Pro, Basic and Starter accounts.
Rob
I believe that Lua out of the box uses doubles.
You can see some info on this here: http://bit.ly/1A7FQ8l
64 bit doubles, I would be *very* wary of relying on this
Lua does not use int’s. The data type for numbers is “double” floats.
or so I’ve been told
Rob
I’d first ask: why you want to dump binary data?
(why not json or xml? is file size that big an issue?)
What you’re asking about is a part of what it means to be a weakly/dynamically typed languages (though both of those terms are somewhat debated). The idea is that programmers shouldn’t need to define things as integers or floats, just use “numbers”, and the complier+run-time will just “figure it out” and “do the right thing”.
Most of the time, that works fine. But if you’re trying to write out the raw binary data, you might see some problems – as Rob mentioned, if you write out the binary “integer” data, you might find that it is actually in floating point format.
Perhaps I can help this discussion a bit. Back in the 1990’s when I was working for a company building online computer games and people were trying to play them on a 19,200 bps modem, packing information into as small a chunk of data as we could get away with was desirable. Our packets was a one byte command (giving us 256 possible things to tell the game to do, then we would have a two-byte length which represented the number of bytes that made up that packet of data. We could read just that amount and then unpack the data into char’s, int’s strings, etc. It was very important to be able to do bitwise math on things because frequently a single byte could represent 8 on/off settings.
However today, with the speed of transmission, this isn’t that big of a deal. A verbose, serialized text like JSON or XML is way easier to parse in a very standard way and the need for binary level packing just isn’t that important. However if you’re trying to do something like read the EXIF data from an image or write out the IPTC caption data to an image, those still need to be byte packed and you’re going to struggle trying to get Lua to do that. It’s not what the language was designed for.
Rob
My game we have several word list and they are saved as a bloom filter. If I save the bloom filter in string format it is 15 meg instead of 5 meg, and thats a big different if you have several word list.
And would not actually agree that lua is not design for it, one of the reasons lua is so popular is that you can always use the c language with. Unfortunately this is not possible with Corona.
But however, it seems to work, I split the double numbers in to 8 bytes and save the bytes to a binary file. And then I read byte by byte from the file and it works perfectly. Both android and apple uses little endian and I have tested it on several devices.
Right now I have 4 word lists, so 5 x 3 = 15 meg is much better then 15 * 3. Specially on an old device.
You can use C with Lua, but not with Corona SDK. You could either use Corona Cards or Corona Enterprise to be able to access the Lua-C bridge.
Rob
Yes I know you can use C with lua with Corona Enterprice, but if it cost 200 dollars a month, I would not say you support it for normal users
We don’t support it for Pro, Basic and Starter accounts.
Rob