Jump to content




HELP! All my \13s are being converted to \10s


  • You cannot reply to this topic
5 replies to this topic

#1 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 June 2018 - 12:59 AM

I tried the following code in the Lua console:
h = fs.open("x", "w")
h.write("\13")
h.close()
h=fs.open("x", "r")
string.byte(h.read())
h.close()

And the result was 13, even though I expected it to be 10

It's causing major flaws in a program that I am writing, it took a tremendous amount of debugging to find this issue, and I can't really escape it in the auto-generated file that easily

Edited by EveryOS, 30 June 2018 - 01:00 AM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 30 June 2018 - 01:52 AM

Carriage return (\r) and line feed (\n) are handled differently at the OS level by eg. OSX vs. Windows. Sometimes git will change these around, if you're using that for versino control.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 June 2018 - 09:05 AM

I'm not entirely sure that this is an "OS level" thing, but the behaviour is certainly decided according to the OS in use.

If this actually matters to your code, then odds are you should be using binary mode for your file handles instead:

h = fs.open("x", "wb")
h.write(13)
h.close()
h=fs.open("x", "rb")
result = h.read()
h.close()

If you really feel that you must use text mode, then convert through base64 or similar before writing to disk.

#4 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 June 2018 - 06:22 PM

Whoa, binary mode might actually be really useful for what I am writing! It will decrease the amount of code, and increase effeciency

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 30 June 2018 - 07:47 PM

View PostBomb Bloke, on 30 June 2018 - 09:05 AM, said:

I'm not entirely sure that this is an "OS level" thing

Yeah, I doubt the OS is actually doing anything. I suspect another program (eg. Git) is changing it for that reason.

#6 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 June 2018 - 10:19 PM

I wasn't even using git, so it couldn't have. But using binary mode fixed it





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users