ElvishJerricco, on 25 October 2012 - 03:33 AM, said:
faubiguy, on 24 October 2012 - 07:17 PM, said:
I don't see a reason for rednet.send to send strings in the context of ASCII. A string in lua is a series of bytes, and doesn't necessarily store text, ASCII or otherwise. A string can be used to store a sequence of arbitrary bytes. However, as mentioned above, this is likely unintended result of conversion to java and back, and can't be easily fixed.
It's because he's using string.char() and string.byte(). Those functions' purpose are to convert a number to its ASCII character and back. Like i said, strings in lua are objects, so it's not the string's fault. It's the method used to go from number to string. The purpose is to use the ASCII standard which really should behave the way it is here. It is not a bug, it is not bad behavior, it is not Java's fault. It is exactly what it was designed to be.
A string in Lua is a sequence of bytes. Source: "String represents arrays of characters. Lua is 8-bit clean: strings can contain any 8-bit character, including embedded zeros ('0')"
It does not specifically mention ASCII.
In the same reference manual:
"string.byte (s [, i [, j]])
Returns the internal numerical codes of the characters s[i], s[i+1], ···, s[j]. The default value for i is 1; the default value for j is i."
"string.char (···)
Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument."
Notice that characters are just numbers from 0 to 255. ASCII is just the way they're printed.
dan200, on 25 October 2012 - 02:23 PM, said:
Rednet isn't for sending "bytes", it's for sending strings of text. if you're trying to use strings to encode binary data using string.char/string.byte, you're making a lot of assumptions about character sets that may not hold true. If you really -must- send data in binary (i can't think why you would, sending the lua data you want using textutils.serialise, or just strings of numbers, is much simpler), write a base64 encoder.
Cloudy, on 25 October 2012 - 06:22 PM, said:
A simple solution is base64 /> Packet size is not important in a system where packet size is unlimited.