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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With