cocos2dx lua 学习笔记(一)

本文介绍如何在MacOSX系统上安装Lua,并提供Lua的基础语法介绍,包括常用语句、数据类型、字符串操作等。此外还介绍了类定义、闭包函数以及元表方法等高级特性。
  • macosx 安装 lua
    • curl -R -O http://www.lua.org/ftp/lua-5.1.4.tar.gz
    • tar zxf lua-5.1.4.tar.gz
    • cd lua-5.1.4
    • make macosx
    • sudo make install
  • 进入lua方法:
    • 输入lua回车
  • 常用语句
    • print('Hello lua!');
    • io.write('Hello lua\n');
  • 基础类型:
    • nil 空
    • boolean 
    • number
    • string
    • function
    • table
    • userdata
    • thread
  • 字符串写法
    • 单引号 ,双引号 ,方括号
  • 字符连接
    • .. print("Hello " .. "world!")
  • 长度
    • #井号
  • 表达式
    • + - * / ^ %(取模)
  • 关系运算符
    • > < == ~=
  • 逻辑运算符
    • and or not
  • 类的定义
    • class = {}
    • function class.func1()
    • end (无self)
    • function class:func1()
    • end (传入self)
  • 闭包函数(函数内函数)
    • function outsider()
    • local i=0
    • return function insider()
    • i = i+1;
    • return i;
    • end
    • end
  • 元表方法(table 和 userdata的预定义方法)
    • setmetatable()
    • getmetatable()
    • __index __newindex __tostring __metatable __eq __lt __le __add__sub __mul __div __unm __pow __concat
    • 元表方法重要,需要单独练习

转载于:https://www.cnblogs.com/oldnull/p/5016017.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值