没有合适的资源?快使用搜索试试~ 我知道了~
首页Lua编程指南:开源授权与资源集成
Lua编程指南:开源授权与资源集成
需积分: 9 0 下载量 42 浏览量
更新于2024-07-20
收藏 1.24MB PDF 举报
"Lua Programming" 是一种轻量级的脚本语言,以其简洁的语法和高效的性能在游戏开发、嵌入式系统、网络编程等领域得到了广泛应用。该资源来源于2012年4月28日的英文维基百科和维基图书项目,其内容被授权遵循Creative Commons Attribution-ShareAlike 3.0 Unported许可证,这意味着用户可以根据此协议自由地复制、修改和分享作品,但需保持原作者署名和同样或兼容的许可条件。 该文档可能包含来自这些项目的内容,如果它是在这些内容仍受该许可约束时衍生的,那么衍生作品也必须遵守相同的条款。文档中提供了详细的贡献者名单,可以在第65页找到,以认可所有对内容作出贡献的人。此外,由于该书或部分内容可能采用GNU General Public License (GPL)、GNU Lesser General Public License (LGPL) 或 GNU Free Documentation License (GFDL)等开源许可,所以在第71页列出了相应的许可证,以确保合规性。 LATEX(LaTeX)是一种强大的排版软件,用于生成高质量的文档。在这个资源中,PDF文件是由LATEX创建的,源代码作为附件(source.7z.txt)附带在PDF中。用户可以通过名为pdfdetach的工具来提取源代码,以便于进一步编辑和学习。 "Lua Programming" 资源涵盖了编程语言的核心概念、语法特性、应用示例以及与版权和开源许可相关的法律细节,为学习者提供了一个全面且可扩展的学习平台。无论是初学者还是经验丰富的开发者,都能从中找到适合自己的学习材料。
资源详情
资源推荐
Expressions
consist of two things: an escape character, which will always be a backslash (’\’) in Lua,
and an identifier that identifies the character to be escaped.
Escape sequences in Lua
Escape se-
quence
Description
\n A new line
\” A double quote
\’ A single quote (or apostrophe)
\\ A backslash
\t A horizontal tab
\### ### must be a number from 0 to 255. The result will be the
corresponding ASCII
3
character.
Escape sequences are used when putting the character directly in the string would cause a
problem. For example, if you have a string of text that is enclosed in double quotes and
must contain double quotes, then you need to enclose the string in different characters or
to escape the double quotes. Escaping characters in strings delimited by long brackets is
not necessary, and this is true for all characters. All characters in a string delimited with
long brackets will be taken as-is. The % character is used in string patterns to escape magic
characters, but the term escaping is then used in another context.
"This is a valid string."
'This is also a valid string.'
"This is a valid \" string 'that contains unescaped single quotes and escaped
double quotes."
[[
This is a line that can continue
on more than one line.
It can contain single quotes, double quotes and everything else (-- including
comments). It ignores everything (including escape characters) except closing
long brackets of the same level as the opening long bracket.
]]
"This is a valid string that contains tabs \t, double quotes \" and backlashes
\\"
"This is " not a valid string because there is an unescaped double quote in the
middle of it."
For convenience, if an opening long string bracket is immediately followed by a new line,
that new line will be ignored. Therefore, the two following strings are equivalent:
[[This is a string
that can continue on many lines.]]
[[
This is a string
that can continue on many lines.]]
3
https://en.wikipedia.org/wiki/ASCII
10
Literals
-- Since the opening long bracket of the second string is immediately followed
by a new line, that new line is ignored.
It is possible to get the length of a string, as a number, by using the unary length operator
(’#’):
print(#("This is a string")) --> 16
Concatenation
In formal language theory
a
and computer programming
b
, string concatenation is the
operation of joining two character strings
c
end-to-end. For example, the concatenation
of ”snow” and ”ball” is ”snowball”.
a
https://en.wikipedia.org/wiki/formal%20language
b
https://en.wikipedia.org/wiki/computer%20programming
c
https://en.wikipedia.org/wiki/character%20string%20%28computer%20science%29
The string concatenation operator in Lua is denoted by two dots (’..’). Here is an example
of concatenation that concatenates ”snow” and ”ball” and prints the result:
print("snow" .. "ball") --> snowball
This code will concatenate ”snow” and ”ball” and will print the result.
2.1.5 Other types
The four basic types in Lua (numbers, booleans, nil and strings) have been described in
the previous sections, but four types are missing: functions, tables, userdata and threads.
Functions are pieces of code that can be called, receive values and return values back.
Tables are data structures that can be used for data manipulation. Userdata are used inter-
nally by applications Lua is embedded in to allow Lua to communicate with that program
through objects controlled by the application. Finally, threads are used by coroutines, which
allow many functions to run at the same time. These will all be described later, so you only
need to keep in mind that there are other data types.
2.2 Literals
Literals are notations for representing fixed values in source code. All values can be repre-
sented as literals in Lua except threads and userdata. String literals (literals that evaluate
to strings), for example, consist of the text that the string must represent enclosed into
single quotes, double quotes or long brackets. Number literals, on the other hand, consist
the number they represent expressed using decimal notation (ex: 12.43), scientific notation
(ex: 3.1416e-2 and 0.31416E1) or hexadecimal notation (ex: 0xff).
11
Expressions
2.3 Coercion
Coercion is the conversion of a value of one data type to a value of another data type. Lua
provides automatic coercion between string and number values. Any arithmetic operation
applied to a string will attempt to convert this string to a number. Conversely, whenever a
string is expected and a number is used instead, the number will be converted to a string.
This applies both to Lua operators and to default functions (functions that are provided
with the language).
print("122" + 1) --> 123
print("The number is " .. 5 .. ".") --> The number is 5.
Coercion of numbers to strings and strings to numbers can also be done manually with
the tostring and tonumber functions. The former accepts a number as an argument and
converts it to a string, while the second accepts a string as an argument and converts it
to a number (a different base than the default decimal one can optionally be given in the
second argument).
2.4 Bitwise operations
Since Lua 5.3, bitwise operators are provided to operate on binary numerals (bit patterns).
These operators are not used as frequently as the others, so you may skip this section if you
do not need them.
The bitwise operators in Lua always operate on integers, converting their operands if this
is necessary. They also give integers.
The bitwise AND operation (with operator &) performs logical conjunction on each pair of
bits of two binary representations of equal length. For example, 5 & 3 evaluates to 1. We
can explain this by looking at the binary representation of these numbers (the subscripts
are used to denote the base):
(5)
10
= (0101)
2
(3)
10
= (0011)
2
(1)
10
= (0001)
2
If the bits in a given position in the binary representation of both 5 and 3 are 1 (as is the
case for the last bit), then the bit at that position will be 1 in the result; in all other cases,
it will be 0.
The bitwise OR operation (with operator |) works in the same way as the bitwise AND,
performing logical disjunction instead where it performs logical conjunction. Thus, 5 |
3 will evaluate to 7:
(5)
10
= (0101)
2
(3)
10
= (0011)
2
(7)
10
= (0111)
2
12
Bitwise operations
Here, we can see that the bit in each position in the final result was 0 only when the binary
representations of the two operands had a 0-bit at that position.
The bitwise XOR operation (with operator ˜) works like two others, but at a given position,
the final bit is only 1 if one, and not both, of the bits in the operands are 1.
(5)
10
= (0101)
2
(3)
10
= (0011)
2
(6)
10
= (0110)
2
This is the same as the previous example, but we can see that the last bit in the result is 0
instead of 1, since the last bit of both operands was 1.
The bitwise NOT operation (with operator ˜) performs logical negation on each bit of its
unique operand, which means that each 0 becomes 1 and that each 1 becomes 0. Thusly,
˜7 will evaluate to -8:
(7)
10
= (0111)
2
(8)
10
= (1000)
2
Here, the first bit became 1 in the result because it was 0 in the operand, and the other
bits became 0 because they were all 1.
Figure 1 Left shift
13
剩余75页未读,继续阅读
wlh550
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C++标准程序库:权威指南
- Java解惑:奇数判断误区与改进方法
- C++编程必读:20种设计模式详解与实战
- LM3S8962微控制器数据手册
- 51单片机C语言实战教程:从入门到精通
- Spring3.0权威指南:JavaEE6实战
- Win32多线程程序设计详解
- Lucene2.9.1开发全攻略:从环境配置到索引创建
- 内存虚拟硬盘技术:提升电脑速度的秘密武器
- Java操作数据库:保存与显示图片到数据库及页面
- ISO14001:2004环境管理体系要求详解
- ShopExV4.8二次开发详解
- 企业形象与产品推广一站式网站建设技术方案揭秘
- Shopex二次开发:触发器与控制器重定向技术详解
- FPGA开发实战指南:创新设计与进阶技巧
- ShopExV4.8二次开发入门:解决升级问题与功能扩展
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功