So I'm starting to Learn Lua, my problem is that in a tutorial that teaches you to create Guess My Number Game starts with this line:
name = "John"
print<name>
So in the tutorial shows that prints the name but in mine gives this error:
stdin:1: '=' expected near '<'
Please, what am I getting this?
Thank you for all your help.
Functions use parentheses to enclose their arguments, so the second line should be
print (name)
Related
I am new to computercraft and have a problem with my code.
The error is
'=' expected near 'monitor'
Do anyone know the problem and can fix it?
I've been making a 2009 script builder for a few hours now, and I can't figure out how to make it print errors. If I do print(loadstring("a")) it prints into the roblox output nil [string "s"]:1: '=' expected near '<eof>', which == nil. What I want to get is the error it reports at the end : '=' expected near '<eof>', type type is nil, so I have no idea how to get it. If anyone could help that would be greatly appreciated!
Refer to the Lua 5.1 manual, which will point you to the documentation for load:
If there [are] errors, ... returns nil plus the error message.
It's typical for Lua to return error messages as a second return value:
local f, err = loadstring(mycode)
if not f then
print("There was an error: `" .. err .. "`")
end
This err begins with where the error happened, which unhelpfully quotes the input to loadstring.
For example, for the input code "hello there", the error is
[string "hello there"]:1: '=' expected near 'there'
Lua appears to cut the quote off at the first newline or 63 character, whichever is less:
For "hello\there" the error is
[string "hello..."]:2: '=' expected near 'there'
For "helloooooooooooooooooooooooooooooooooooooooooooooooooooooo there" the error is
[string "helloooooooooooooooooooooooooooooooooooooooooooooooooooooo ther..."]:1: '=' expected near 'there'
If you're sure there's no "]: in the first 63 characters/first line of your script, you can just search for that sequence to find where it stops:
local location, message = err:match('^(%[string ".*"%]:%d+:%s+)(.*)$')
This won't be right if your code is, for example, "hello\"]:1: there", which you may want to address.
The simplest way to address it would be to take user control away from the first line that is quoted: prepend the code with your own first line that is nice (and make sure to adjust the line number of the error if you display it to the user:)
local f, err = loadstring("--code\n" .. mycode)
print(err)
Now the error message should always begin
[string "--code..."]:
In Lua interpreter when I type
>print (12
>>3)
stdin:2: ')' expected (to close '(' at line 1) near '3'
Why am I getting this error?
When we type
>a=2
>a=a+
>>1
This works fine! Then why not print? What is wrong with print()?
The input is print (12 <NEWLINE> 3), which is a syntax error.
Adding a comma after 12 works fine.
I'm incredibly new to C and Xcode in general. Could somebody explain why this isn't working, and how to fix it?
You have a number of issues.
Regarding the Expected Expression error, you declared _declination and _latitude as UITextField. To get the integer value, you can use: _declination.text.intValue. In context:
if (_declination.text.intValue >= 90 - _latitude.text.intValue)
Regarding Missing terminating character " you need to change:
#The star is circumpolar"
to:
#"The star is circumpolar"
You are missing a quote:
"The star is circumpolar!"
I am new in Eralng . get a little query about applying functions
assumming got a funciton defined :
mysum(X) -> fun(Y)-> X + Y end.
then try to calling like this
mysum(32)(332)
getting error
* 1: syntax error before: '('
so I had to
apply(mysum(32),[333])
or
M = mysum(32), M(333)
but I would like to know a little bit more , why it is not supporting , what is the disadvantage
As you expected, mysum return a function. you must enclose the evaluation inside parenthesis to satisfy the erlang parser:
(mysum(32))(332)
this spelling is obviously not ambiguous.
Your expression seems not ambiguous because you know that mysum(32) is a function, but the types are solved at run time in erlang, so the parser has no idea of what is mysum(32), it is expecting some help here to know what it has to do: the parenthesis, the apply or the intermediate variables, but it could be an operator or a separator.