What exactly would happen if I ran code with ambiguous syntax?
This is the reason for my asking.
What exactly would happen if I ran code with ambiguous syntax?
This is the reason for my asking.
If you take a look at the link provided by MessorAdmin in the comments
http://wiki.roblox.com/index.php/Lua_errors
You will notice that the wiki explains how Lua reads the syntax of code.
For example,
y
=
1
+
3
Is the same as:
y=1+3
This is because Lua reads code almost as if it was all in a single line, with the exception of when Lua notices a ; because that indicates a statement/link break.
Let's take a look at the replication I was able to do:
function func()
return function(...)
print(table.concat({...},","))
end
end
func()
(a="hey",b="steve")
Now, the returned function inside func is expecting parameters so that it can print a concatenation of all the values inside the tuple given. Now, I might actually want to call func with no parameters whatsoever, and just set variables a to hey and b to steve.
Now, if we take whitespace into account, Lua is actually interpreting the code segment as:
function()(a="hey",b="steve")
So in this case, Lua is not sure if you are trying to make a new line segment or if you're passing in Parameters into the returned function from func()
The Lua programming language uses a freeform syntax. This means that whitespace characters, such as space, tab characters and newline characters can be inserted into the program code for the purpose of spacing, alignment or indentation in either the horizontal or vertical directions.
http://en.wikibooks.org/wiki/Lua_Programming/whitespace http://wiki.roblox.com/index.php?title=Lua_errors#Ambiguous_Syntax_Errors http://en.wikipedia.org/wiki/Free-form_language
A great write up by BlueTaslem here:
https://scriptinghelpers.org/questions/16925/how-do-i-use-this-symbol
It's an error -- it won't let you run.
If it did run, it just might not mean what you think it means. It might be what you expect, though (that's what "ambiguous" means -- it could be interpreted multiple ways)
See this question for what causes this (a semicolon, or fewer parenthesis, fixes this).
You would add a ";" to the end of the line
Go here for more info: http://wiki.roblox.com/index.php/Lua_errors
I already know how to fix it, what i wanted to know was how Lua would interpret it.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
I have never heard of this problem... Wow. That must be a RARE problem.
All I can do here is give a link.. http://wiki.roblox.com/index.php?title=Lua_errors
Provide a code snippet, please?
Wow I've never seen something like this before.