"'=' expected near" error

I have main.lua as follows:
[lua]doit={}
function doit.foo()
return 2
end

print doit.foo[/lua]
It causes the error:
‘=’ expected near ‘doit’
on the last line.

I’ve tried last line as:
[lua]print doit.foo()
print doit:foo()
print doit.foo
print doit:foo[/lua]

All have same error.
I think I must be missing something obvious!
Any ideas? [import]uid: 67842 topic_id: 13059 reply_id: 313059[/import]

I think you need the other function syntax for this:

[lua]doit={}
doit.foo = function()
return 2
end

print doit.foo()[/lua]

[import]uid: 19626 topic_id: 13059 reply_id: 47928[/import]

i think it should be like

doit={}
function doit.foo()
return 2
end

print (doit.foo())

[import]uid: 12482 topic_id: 13059 reply_id: 47939[/import]

Thanks hgvyas123,
Your solution of adding the brackets:
print (doit.foo())
solves the problem.

At first I couldn’t understand why but then I found in PiL:
“If the function has one single argument and this argument is either a literal string or a table constructor , then the parentheses are optional”

So while it’s ok to write:
print “Hello World” instead of print(“Hello World”)
and
print {“hello”, “world”} instead of print ({“hello”, “world”})
it’s not ok to write:
print 5
or
print foo()
or
print doit.foo()
the brackets are needed in these situations.
Maybe the way to remember this, is that you can only drop the brackets when there’s a matching pair of characters surrounding the argument.
In the case of print “Hello World” this is " and "
In the case of print {“hello”, “world”} this is { and }
And print foo() doesn’t have this matching pair so we need:
print (foo())
[import]uid: 67842 topic_id: 13059 reply_id: 48038[/import]