12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

30 Part I ■ Learning to ProgramThe second example throws an error that you should explore a bit more.What Lua sees here is an identifier (x), the assignment operator (=), <strong>and</strong> astring (’Isn’). Because Lua doesn’t require any whitespace between mostoperations, it immediately starts the next part <strong>of</strong> the expression, which beginswith the identifier t. The next thing the interpreter sees is another identifiercalled it, <strong>and</strong> doesn’t know what to do with it. In this case, the interpreterinfers that you meant to use the assignment operator <strong>and</strong> errors out with thissuggestion.You can get around this by escaping the tick mark that is inside the string totell Lua that it’s part <strong>of</strong> the string instead <strong>of</strong> the end <strong>of</strong> it. Here’s an example:> x = 'Isn\’t it nice?'> print(type(x))stringYou tackle the details <strong>of</strong> string escaping shortly.Double Quote (’’)Thedoublequote(“) can be used the same way as the single quote, with thesame caveat <strong>of</strong> needing to escape embedded quote characters. Here are someexamples:> x = “Hello“> print(type(x))string> x = “Isn’t it nice?“> print(type(x))string> x = “I play the game “<strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>““stdin:1: '=' expected near '<strong>of</strong>'The second works because the tick mark isn’t being used to delimit thequote, but the inner quote in the third example needs to be escaped with abackslash:> x = “I play the game, \“<strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>\““> print(type(x))stringBracket Quote ([[ ]])Lua has the concept <strong>of</strong> a long quote that enables you to include multiplelines <strong>and</strong> internal quote characters. These quotes begin with the open bracketcharacter ([), have any number <strong>of</strong> equal signs (=), including 0, <strong>and</strong> then

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!