Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Ambiguous Syntax Outcome? [closed]

Asked by
Muoshuu 580 Moderation Voter
9 years ago

What exactly would happen if I ran code with ambiguous syntax?

This is the reason for my asking.

0
I have never heard of this problem... Wow. That must be a RARE problem. MessorAdmin 598 — 9y
0
All I can do here is give a link.. http://wiki.roblox.com/index.php?title=Lua_errors MessorAdmin 598 — 9y
0
Provide a code snippet, please? Perci1 4988 — 9y
0
Wow I've never seen something like this before. DigitalVeer 1473 — 9y

Locked by FearMeIAmLag

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
3
Answered by 9 years ago

Whitespace

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.

Useful Links

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

Ad
Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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).

Log in to vote
-3
Answered by
parkderp1 105
9 years ago

You would add a ";" to the end of the line

Go here for more info: http://wiki.roblox.com/index.php/Lua_errors

0
I already know how to fix it, what i wanted to know was how Lua would interpret it. Muoshuu 580 — 9y