编辑: 鱼饵虫 2019-07-06
1.

1 1.2 1.2.1 1.2.2 1.3 1.4 1.5 1.6 1.6.1 1.6.2 1.6.3 1.7 1.8 1.8.1 1.9 1.10 1.11 1.12 1.12.1 1.12.2 1.13 目录 Introduction Run lua Install Lua hello world! 注解 (Comment) 变数 (Variables) 运算子 (Operators) 流程控制 (Flow control) if - then - else 回圈 (Loop) 围 (Scope) 函式 (Functions) 递回 (Recursive) 尾调用 (Tail Call) 表格 (Table) 模块 (Modules) 元表与元方法 (Metatables and metamethods) 类别与继承 (Classes and inheritance) 简单的方法 复杂的方法 结语

1 Lua Basic Lua 是一个脚本语言,在

1993 年作为扩展既有软体的用途而诞生.Lua 跨平台、 轻量、语法简单的特性让他成为一个优秀的插件开发语言.著名的 Corona SDK 与 魔兽世界插件都是使用 lua 开发.本书以深入浅出的例,让读者学习 Lua 的基 础. Introduction

2 Run lua

3 Insatall Lua Mac OS X 开启 Terminal ,使用 brew 安装 lua: brew install lua 如果你没有安装 brew,请用以下指令安装: /usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) Windows 在 Windows,你可以直接透过以下的安装程式直接安装 https://code.google.com/archive/p/luaforwindows/downloads Install Lua

4 hello world! 建立档案 hello.lua print( hello world ) 执行 使用 Terminal 执行 Lua 开启 terminal,执行以下指令 lua hello.lua 你会在 terminal 看到执行结果 hello world!

5 使用 Atom 执行 Lua 安装套件按下组合键 Cmd + , ,开起设定视窗,并点选 Inatall 选单 hello world!

6 安装 script script 让你可以直接在 Atom 内执行程式码,使用 Cmd + i 执行后的结果会在下方 视窗内. hello world!

7 安装 autocomplete-coronaautocomplete corona 是 Corona 推出的 Atom 套件,它能帮助 Corona 开发者快速地寻找与 Corona SDK 有关的函式库.安装此套件也会自动安装相依套件:language-lua, 此套件能让 lua 程式码上色,方便开发者阅读与撰写 hello world!

8 使用快捷键 cmd + i 执行,或是从 Script 选单选择 Run Script: 执行结果位於下方栏位,这个例中,会印出字串:hello world hello world!

9 hello world!

10 注解 (Comment) 注解并不会被作为程式的一部分执行,他的作用在於将程式码文件化:提醒开发者 本人未来要在程式内完成的工作,或帮助他人理解程式码.Lua 支援两种注解:单 行注解、多行注解. 单行注解 (Single line comment) -- Two dashes make the rest of the line a comment 多行注解 (Multiline comment) --[[ Two square brackets in a row after two dashes make a multi-line comment. ―]] 注解 (Comment)

11 变数 (Variable) 变数是储存数闹饕侄,他可以是数字 (number)、字串 (string)、表格 (table)、布林 (boolean) 或是函式 function,与 C 和 JAVA 语言不同,宣告 Lua 变 数时,并不需要指定型态,Lua 透过被指定数值来辨认该变数的类型. myNumber =

12 myBoolean = true -- or false aString = Hello World anotherString = '

single quotes work too'

bigString = [[ Two square brackets begin and end a multi- line string. This is similar to multi-line comments but without the dashes.]] 此外 Lua 的数字型态,除了指派整数之外,也可以指派浮点数.然而不管你指派的 是数字或是浮点数,在 Lua 底层的运算中,所有的数字 (Number) 型态都是使用64 位元数乃陡〉闶 (double float) 表示.但开发者不会感觉到差异,当你试著印 出整数的时候,并不会以浮点数的型态表示. myNumber =

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题