当前位置:网站首页>Lua advanced
Lua advanced
2022-07-28 01:18:00 【Two blanks】
Preface
Learn to query documents : Official document link ——Lua 5.3 Reference manual - Catalog
Multiple file calls
Use require keyword :
- Run the specified file name .
- No extension at the end .
- For directory level '.' Separate .

- It will only run once .
- The return value of the call will be returned .

- The called file is from package.path Find... In the path .

commonly require It is used to call external library files , Generally, you don't need to call many times .

iterator
The function is to traverse table All the values of .
commonly table Iteration :

There are two kinds of iterators :
- ipairs
ipairs Apply to With numbers and continuous Subscript table.

If you encounter discontinuous numerical subscripts table, encounter table Numerical subscript not in , Until we return nil, here ,ipairs Will stop traversing .

- pairs
Applicable to string subscripts and discontinuous numerical subscripts .

pairs The internal call is next function .
next() function , Will return the incoming table The next value of the value ,pairs The obtained value is recorded in .

use next You can also quickly judge a table Is it empty .

string
lua in string Characteristics
- Storage structure of string .
stay lua The storage structure of string in is equivalent to C++ Medium vector<char> In the form of . One character, one character is saved in the array . What is actually saved is the bytecode of the character .

- You can save any character string , The scope is 0x00~0xff, Include invisible characters . What is special is 0x00, stay c The language is in the form of '0' Character ending , The following characters are lost . stay lua Not in the , Because it records the number of characters ,

- The string has a sequence number , Save positive sequence number and negative sequence number .
Positive sequence number , The starting position 1 Start , After that, add . Negative sequence number , At the end of -1 Start , Decrease in front .

string The interface of
Return characterstring.byte (s [, i [, j]])s[i],s[i+1], ... ,s[j]Internal digital code of .iThe default value of is 1 ;jThe default value of isi.

-
string.char (···)
Receive zero or more integers . Returns a string of the same length as the number of parameters . The internal code value of each character is equal to the corresponding parameter value .

-
string.format (formatstring, ···)Returns the formatted version of an indefinite number of parameters , Format the string as the first parameter ( Must be a string ). and c Linguistic printf It doesn't make any difference .

-
string.lower (s)
Receive a string , Turn all uppercase characters into lowercase and return a copy . Other strings will not change . The definition of upper case characters depends on the current locale .

-
string.pack (fmt, v1, v2, ···)Return a package ( That is, serialize in binary form )
v1,v2Equivalent binary string . character stringfmtIn packaging format ( See §6.4.2).

边栏推荐
- 深圳华强宣布拟不超2000万元入股比亚迪半导体
- Self use drawing bed building tutorial
- Interface test practical project 02: read interface test documents and practice
- Circular structure of shell system learning
- 文件系统的层次结构
- Wavelet transform learning notes
- Basic concept and classification of i/o equipment
- One year anniversary of creation, Chongba young Lang
- Hierarchy of file system
- BYD semiconductor completed the a+ round financing of 800million yuan: 30 well-known investment institutions entered the market, with a valuation of 10.2 billion yuan!
猜你喜欢

Sign up now | cloud native technology exchange meetup Guangzhou station has been opened, and I will meet you on August 6!

Node red interacts with tdengine

Go language variable

2022/07/27 学习笔记 (day17) 代码块和内部类

3年经验想拿20K,居然面了半个月都没拿到?

Detailed explanation of retinanet network structure

ABAP CDS Table Function介绍与示例

Use of postman

BAT大厂测试架构师如何解读测试平台的各种争议

Storage of deep planing data in memory
随机推荐
Basic use of calculation attributes
If a table has nearly ten million data and crud is relatively slow, how to optimize it
Spool timer
File system mount
Focal Loss讲解
C language programming | explanation and Simulation of offsetof macro
二维数组相关知识
Interface test practical project 02: read interface test documents and practice
Storage of deep planing data in memory
uni-app进阶之样式框架/生产环境
[original] [crawler series] briefly get the most popular topics, related topics and description information
Postman 的使用
Analysis and recurrence of network security vulnerabilities
The cooperation between starfish OS and metabell is just the beginning
Fabric2.4.4 version building process (complete process)
Cross desktop web container evolution
Operator depth anatomy
逻辑回归原理
Go language variable
Iperf installation and use