The difference between the dot (.) and colon (:) In the lua programming script is as follows:

Source: Internet
Author: User

The difference between the dot (.) and colon (:) In the lua programming script is as follows:

When you declare a function in lua, you can use either of the following methods:

1.

Function ClassA. show ()

Print ("test1 ")

End


2.

Function ClassA: show ()

Print ("test2 ")

End

So what are the differences between the two methods? Simple

When defining: ClassA: show () is equivalent to ClassA. show (self). To achieve the colon (:) effect, add a self parameter to the first parameter.

During the call, AObj: show () is equivalent to AObj. test (AObj). The dot (.) must add the object itself to the first parameter.

Summary

Periods (.) can be viewed as static methods, while colons (:) can be viewed as member methods.


How to Learn lua scripts

I learned this way: Read the lua manual first to understand the syntax. Then let's take a look at the next lua Program Design ebook. Finally, let's take an example for practice. The examples are from simple to complex, step by step, and patience is required to learn things. Hope to help you

Q: Have you read the book "lua program design version 2?

Lua and python are the two most common scripting languages used in the game. lua program design only talks about some content in lua language, but does not show how to use it in the game, or how it works with other languages.
For specific game examples, you can check some examples of lua's usage in the game. There are many examples on the Internet, or you can go to a game company for work experience.

Related Article

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.