Lua Encapsulation class--lua and Android

Source: Internet
Author: User

The Lua wrapper class (in object-oriented parlance) has three ways of writing:

Way One

Lib = {}lib.name = Nillib.foo = function (x, y) return x + y Endlib.goo = function (x, y) return-X-y End

Way two:

Lib = {    = Nil,    return x + y end,    return x- y end,}

Way three:

Lib == nilfunction lib.foo (x, y)return x + yendfunction lib.goo (x, y)  Return X- yend


Authentication (Coronacard in Android):

------------------------------------------------------------------------------- DoStart and fill screenprint ("Start Lua ...") Mbackground= Display.newrect (0,0,2* Display.contentwidth,2*display.contentheight)--------------------------------------------------------------------------------------------------------------- ---------------------------------------------define Liblib={}lib.name=Nillib.foo= function (x, y)returnX +y Endlib.goo= function (x, y)returnX-y End-----------------------------------------------------------------------------Local Liba=Libliba.name="test Lib at 1"Local I,j=Ten, -;p rint (liba.name ."--".. Liba.foo (i, J)) Liba.name="test Lib at 2"print (Liba.name ."--".. Liba.goo (I,J))

Lua Encapsulation class--lua and Android

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.