Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Tutorial: The difference between a . and a : when declaring functions in Lua — Gideros Forum

Tutorial: The difference between a . and a : when declaring functions in Lua

OZAppsOZApps Guru
edited January 2012 in General questions
This is one from the series of tutorials available on our site, many of the earlier tutorials were aimed towards a Mexican beer type framework, now they are more general in nature and applicable to most frameworks that use Lua.

http://howto.oz-apps.com/2012/01/safely-create-member-functions-in-lua.html

Likes: atilim

twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • A little bit difficult to understand for me but I think I got. Thanks!
  • Well yeah, I was also confused with that, but then I understood the idea from string object

    For example:
    for each method in string object we can pass string to it
    string.find("Hello Lua user", "Lua")
    or we can use this function for strings directly, because they are also string objects
    local str = "Hello Lua user"
    str:find("Lua")
    As you see in second example, we didn't have to pass string value again, because using ":" will pass string itself as first argument.

    I would say it is similar to having static and instance method in one
  • well, each one of us has different ways to learn, glad that the end result was the same, the journey and the experiences might have been different.

    When writing an article for the other framework, most users do not even know what a variable is, where as most users here are ones that write plug-ins etc. So, it is difficult ...
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • atilimatilim Maintainer
    Thank you OZApps :)

    Also I want to add a little info:
    Although x:foo(y) is same with x.foo(x, y), x:foo(y) is _a little bit_ faster because Lua VM has a special opcode for : operator.
Sign In or Register to comment.