Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ' and " within Lua

Tags:

lua

I just have a general question.

Is there any difference using single and double quote marks within Lua?

Example:

require('test.lua') require("test.lua") 

When I programmed in PAWN, a language similar to C, single quote marks could be used for characters, but not strings of text, you had to use double quote marks for them.

And if there is no difference, which one is recommended to be used?

This question has most likely been answered already, however I failed to find a topic already answered.

Thank you.

like image 365
Bicentric Avatar asked Jun 19 '13 22:06

Bicentric


People also ask

Whats the difference between and in Lua?

The . (dot) operator in Lua is used to invoke the method of an object, and it is a widely used operator in Lua. The :(colon) operator in Lua is used when you want to pass an invisible parameter to the method of an object that you are calling.

What does == mean in Lua?

The operator == tests for equality; the operator ~= is the negation of equality. We can apply both operators to any two values. If the values have different types, Lua considers them different values. Otherwise, Lua compares them according to their types.

How do I compare two strings in Lua?

In lua '==' for string will return true if contents of the strings are equal. As it was pointed out in the comments, lua strings are interned, which means that any two strings that have the same value are actually the same string.

Does ~= mean not equal?

The ~= symbol or operator in Lua is known as the not-equal to operator. In many programming languages you might have seen the symbol != which is also known as the not equals operator.


1 Answers

Nope. No difference, except that you can enclose the other inside the ones that you are using.

-- No difference between these myStr = "Hi!!" myStr = 'Hi!!' myStr = [[Hi!!]] -- The 'weird' way to make a string literal IMO...  -- Double quotes enclosed in single quotes     myStr = 'My friend said: "Hi!!"'  -- Single quotes enclosed in double quotes myStr = "My friend said: 'Hi!!'"  -- Single and double quotes enclosed in double brackets myStr = [[My friend said: "What's up?"]] 

See: Strings in Lua for more information.

like image 131
AtinSkrita Avatar answered Sep 19 '22 13:09

AtinSkrita