5 Replies - 2587 Views - Last Post: 25 December 2011 - 05:57 PM Rate Topic: ***-- 2 Votes

#1 lukeme99  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 15-March 11

[Lua] What exactly is the \n for?

Posted 25 December 2011 - 11:57 AM

What exactly is the
\n
in, for example,
print("Hello World!\n")
for?
There seems to be no difference between with and without the
\n
, so what's it for?

Thank you for any responses,
L99
Is This A Good Question/Topic? 0
  • +

Replies To: [Lua] What exactly is the \n for?

#2 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: [Lua] What exactly is the \n for?

Posted 25 December 2011 - 12:00 PM

\n stands for new line. Carrage return and or Line feed ASCII 13 and 10. It is like pressing return after you print Hello World, you will be on the next line to print something else. Without the \n, when you go to print something after Hello World, it will print right after that instead of on a new line.
Was This Post Helpful? 1
  • +
  • -

#3 lukeme99  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 15-March 11

Re: [Lua] What exactly is the \n for?

Posted 25 December 2011 - 12:11 PM

View PostGunnerInc, on 25 December 2011 - 12:00 PM, said:

\n stands for new line. Carrage return and or Line feed ASCII 13 and 10. It is like pressing return after you print Hello World, you will be on the next line to print something else. Without the \n, when you go to print something after Hello World, it will print right after that instead of on a new line.


Thank you, because it was never actually explained, as I was brought up on game specific Garrys Mod, Half-Life 2: Sandbox and other game specific Lua; as well on the standard Lua 51/52, so things weren't totally explained. Actually Gmod taught me about this wonderful world of programming, (I was stuck down with just ASM hacking mario roms!) and taught me about the FPS genre, and together these ambitions have made me want to create a game engine, like source mixed with hedgehog engine (but better), and a host of amazing games with that engine.


And, er... Thanks!
L99
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: [Lua] What exactly is the \n for?

Posted 25 December 2011 - 12:18 PM

\n is standard for new line in many languages. In Assembly, we use 13, 10.
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

Re: [Lua] What exactly is the \n for?

Posted 25 December 2011 - 02:17 PM

Just to clarify something: \n stands for the linefeed character (ASCII 10). It does not stand for carriage return (ASCII 13) or for the combination of the two. \r stands for carriage return.

Under Windows under some conditions (writing to a stream in non-binary mode) \n is translated to \r\n and under some other conditions (reading from a stream in non-binary mode) \r\n is translated to \n. This is because Windows (unlike other operating systems) uses both a carriage return and a linefeed to end lines while most other operating systems use just the linefeed. Because it would be unwieldy for programmers to have to use different line terminators depending on the system, the aforementioned translations are performed by Windows' system calls for non-binary IO.
Was This Post Helpful? 1
  • +
  • -

#6 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: [Lua] What exactly is the \n for?

Posted 25 December 2011 - 05:57 PM

just as a note, it's all stored as (ASCII 10) too. as sepp2k said it gets converted but he didn't say when; the "when" is with file IO. if you open a text file in binary mode you will get \r(on windows at least) but if you don't open it in binary mode the the conversion will be made seamlessly and you won't have to worry about it. the reason this is important is because only when working with binary data(Lua doesn't do that well anyway, it's possible with strings however) will you ever even have a \r in a string unless you put it there.

This post has been edited by ishkabible: 25 December 2011 - 06:00 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1