Lua about "." The difference between the usage and the ":" Sign

Source: Internet
Author: User

"." Use of:

    Tsprite = {        0,        0,    }     function  Tsprite.setposition (M, x, y)         = x;         = y    end    local who = tsprite
Tsprite = Nil 12) print(who.x, WHO.Y)

--Output: 1 2

Usage of ":"

    Tsprite = {        0,        0,    }     function  Tsprite:setposition (x, y)-different         = x;         = y    end    local who = tsprite
Tsprite = nil who:setposition (12)--only this differs from print(who.x , WHO.Y)

--Output: 1 2

Do you see the difference? Yes, there's a missing caller parameter.

    Who.setposition (who, 1, 2)
    Who:setposition (1, 2)
Use the ":" equivalent to automatically enter the caller's parameter, either: the front table. ---Self is the default parameter hidden in LUA--the caller
and ":" This usage is mostly used in Lua's "class" usage, because after using ":", you can think of Tsprite as a class, and SetPosition () is Tsprite member method, but he needs to be in the outside definition of the class.

Lua about "." The difference between the usage and the ":" Sign

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.