DEV Community

Karl Xavier
Karl Xavier

Posted on

1

Difference between . and : in Lua programming

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.

lua code

when we use the colon(:) operator what actually happens is that instead of calling v3 = returnX:fun1(100, 1) what gets called is −
v3 = returnX:fun1(returnX, 100, 1) and hence we get the output as an address, and so in the second case when we call returnX:bar(10,11) the second argument will be 10 and that’s what we get.

lua result

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay