Javascript không bằng chuỗi

Lua là ngôn ngữ lập trình mở rộng được thiết kế để hỗ trợ lập trình thủ tục chung với các phương tiện mô tả dữ liệu. Nó cũng hỗ trợ tốt cho lập trình hướng đối tượng, lập trình chức năng và lập trình hướng dữ liệu. Lua nhằm mục đích sử dụng như một ngôn ngữ kịch bản nhẹ, mạnh mẽ cho bất kỳ chương trình nào cần. Lua được triển khai dưới dạng thư viện, được viết bằng ngôn ngữ C sạch [tức là trong tập hợp con chung của ANSI C và C++]

Là một ngôn ngữ mở rộng, Lua không có khái niệm về một chương trình "chính". nó chỉ hoạt động được nhúng trong một máy khách chủ, được gọi là chương trình nhúng hoặc đơn giản là máy chủ. Chương trình máy chủ này có thể gọi các hàm để thực thi một đoạn mã Lua, có thể viết và đọc các biến Lua cũng như có thể đăng ký các hàm C để mã Lua gọi. Thông qua việc sử dụng các hàm C, Lua có thể được tăng cường để xử lý nhiều miền khác nhau, do đó tạo ra các ngôn ngữ lập trình tùy chỉnh chia sẻ một khung cú pháp. Bản phân phối Lua bao gồm một chương trình lưu trữ mẫu có tên là

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66, chương trình này sử dụng thư viện Lua để cung cấp một trình thông dịch Lua hoàn chỉnh, độc lập

Lua là phần mềm miễn phí và được cung cấp như thường lệ mà không có bảo đảm, như đã nêu trong giấy phép của nó. Việc triển khai được mô tả trong sách hướng dẫn này có tại trang web chính thức của Lua,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
67

Giống như bất kỳ tài liệu hướng dẫn tham khảo nào khác, tài liệu này còn khô khan ở những chỗ. Để thảo luận về các quyết định đằng sau thiết kế của Lua, hãy xem các tài liệu kỹ thuật có sẵn trên trang web của Lua. Để có phần giới thiệu chi tiết về lập trình trong Lua, hãy xem cuốn sách của Roberto, Lập trình trong Lua [Ấn bản thứ hai]

Phần này mô tả từ vựng, cú pháp và ngữ nghĩa của Lua. Nói cách khác, phần này mô tả mã thông báo nào hợp lệ, cách chúng có thể được kết hợp và ý nghĩa của sự kết hợp của chúng

Các cấu trúc ngôn ngữ sẽ được giải thích bằng cách sử dụng ký hiệu BNF mở rộng thông thường, trong đó {a} có nghĩa là 0 hoặc nhiều a và [a] có nghĩa là một tùy chọn a. Các ký hiệu không phải thiết bị đầu cuối được hiển thị giống như không phải thiết bị đầu cuối, các từ khóa được hiển thị như kword và các ký hiệu thiết bị đầu cuối khác được hiển thị như `=´. Cú pháp hoàn chỉnh của Lua có thể được tìm thấy trong §8 ở cuối sách hướng dẫn này

Tên [còn được gọi là định danh] trong Lua có thể là bất kỳ chuỗi chữ cái, chữ số và dấu gạch dưới nào, không bắt đầu bằng một chữ số. Điều này trùng khớp với định nghĩa về tên trong hầu hết các ngôn ngữ. [Định nghĩa của chữ cái phụ thuộc vào ngôn ngữ hiện tại. bất kỳ ký tự nào được coi là chữ cái theo ngôn ngữ hiện tại đều có thể được sử dụng trong mã định danh. ] Định danh được sử dụng để đặt tên cho các biến và trường bảng

Các từ khóa sau được dành riêng và không thể được sử dụng làm tên

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while

Lua là ngôn ngữ phân biệt chữ hoa chữ thường.

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
68 là một từ dành riêng, nhưng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
69 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
70 là hai tên hợp lệ khác nhau. As a convention, names starting with an underscore followed by uppercase letters [such as
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
71] are reserved for internal global variables used by Lua

The following strings denote other tokens

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...

Literal strings can be delimited by matching single or double quotes, and can contain the following C-like escape sequences. '

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
72' [bell], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
73' [backspace], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
74' [form feed], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
75' [newline], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
76' [carriage return], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
77' [horizontal tab], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
78' [vertical tab], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
79' [backslash], '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
80' [quotation mark [double quote]], and '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
81' [apostrophe [single quote]]. Moreover, a backslash followed by a real newline results in a newline in the string. A character in a string can also be specified by its numerical value using the escape sequence
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
82, where ddd is a sequence of up to three decimal digits. [Note that if a numerical escape is to be followed by a digit, it must be expressed using exactly three digits. ] Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
83'

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
84, an opening long bracket of level 1 is written as
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
85, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
86. Một chuỗi dài bắt đầu bằng một dấu ngoặc dài mở ở bất kỳ cấp nào và kết thúc ở dấu ngoặc dài đóng đầu tiên cùng cấp. Chữ ở dạng ngoặc đơn này có thể chạy trong một số dòng, không diễn giải bất kỳ chuỗi thoát nào và bỏ qua dấu ngoặc dài ở bất kỳ cấp độ nào khác. Chúng có thể chứa bất cứ thứ gì ngoại trừ dấu ngoặc đóng ở mức phù hợp

Để thuận tiện, khi dấu ngoặc dài mở ngay sau đó là một dòng mới, dòng mới không được bao gồm trong chuỗi. Ví dụ: trong một hệ thống sử dụng ASCII [trong đó '_______087' được mã hóa là 97, dòng mới được mã hóa là 10 và '

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
88' được mã hóa là 49], năm chuỗi ký tự bên dưới biểu thị cùng một chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]

Một hằng số có thể được viết với phần thập phân tùy chọn và số mũ thập phân tùy chọn. Lua cũng chấp nhận các hằng số thập lục phân số nguyên, bằng cách thêm tiền tố vào trước chúng là

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
89. Ví dụ về các hằng số hợp lệ là

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
7

Nhận xét bắt đầu bằng dấu gạch ngang kép [

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
90] ở bất kỳ đâu bên ngoài chuỗi. Nếu văn bản ngay sau
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
90 không phải là một dấu ngoặc dài mở đầu, bình luận là một bình luận ngắn, chạy cho đến cuối dòng. Mặt khác, đó là một nhận xét dài, chạy cho đến khi đóng dấu ngoặc dài tương ứng. Bình luận dài thường được sử dụng để tắt mã tạm thời

Lua là một ngôn ngữ gõ động. Điều này có nghĩa là các biến không có kiểu; . Không có định nghĩa loại trong ngôn ngữ. Tất cả các giá trị mang loại riêng của họ

Tất cả các giá trị trong Lua đều là giá trị hạng nhất. Điều này có nghĩa là tất cả các giá trị có thể được lưu trữ trong các biến, được truyền dưới dạng đối số cho các hàm khác và được trả về dưới dạng kết quả

Có tám loại cơ bản trong Lua. nil, boolean, số, chuỗi, hàm, dữ liệu người dùng, chủ đề và bảng. Nil là loại giá trị nil, có thuộc tính chính là khác với bất kỳ giá trị nào khác; . Boolean là loại giá trị sai và đúng. Cả nil và false đều tạo ra một điều kiện sai; . Số đại diện cho các số thực [dấu phẩy động có độ chính xác kép]. [Thật dễ dàng để xây dựng các trình thông dịch Lua sử dụng các biểu diễn bên trong khác cho các số, chẳng hạn như số thực float hoặc số nguyên dài có độ chính xác đơn; xem tệp

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92. ] Chuỗi đại diện cho mảng ký tự. Lua là 8-bit sạch. các chuỗi có thể chứa bất kỳ ký tự 8-bit nào, kể cả các số 0 được nhúng ['
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
83'] [xem §2. 1]

Lua có thể gọi [và thao tác] các hàm viết bằng Lua và các hàm viết bằng C [xem §2. 5. số 8]

Loại dữ liệu người dùng được cung cấp để cho phép dữ liệu C tùy ý được lưu trữ trong các biến Lua. Loại này tương ứng với một khối bộ nhớ thô và không có thao tác được xác định trước trong Lua, ngoại trừ phép thử gán và nhận dạng. Tuy nhiên, bằng cách sử dụng các metatable, lập trình viên có thể định nghĩa các thao tác cho các giá trị dữ liệu người dùng [xem §2. số 8]. Giá trị dữ liệu người dùng không thể được tạo hoặc sửa đổi trong Lua, chỉ thông qua C API. Điều này đảm bảo tính toàn vẹn của dữ liệu thuộc sở hữu của chương trình máy chủ

Chủ đề loại đại diện cho các chủ đề thực thi độc lập và nó được sử dụng để triển khai các coroutine [xem §2. 11]. Đừng nhầm lẫn luồng Lua với luồng hệ điều hành. Lua hỗ trợ coroutine trên tất cả các hệ thống, ngay cả những hệ thống không hỗ trợ luồng

Bảng kiểu thực hiện các mảng kết hợp, nghĩa là các mảng có thể được lập chỉ mục không chỉ bằng số mà còn với bất kỳ giá trị nào [ngoại trừ nil]. Các bảng có thể không đồng nhất; . Các bảng là cơ chế cấu trúc dữ liệu duy nhất trong Lua; . Để đại diện cho các bản ghi, Lua sử dụng tên trường làm chỉ mục. Ngôn ngữ hỗ trợ biểu diễn này bằng cách cung cấp

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
94 dưới dạng đường cú pháp cho
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
95. Có một số cách thuận tiện để tạo bảng trong Lua [xem §2. 5. 7]

Giống như các chỉ mục, giá trị của trường bảng có thể thuộc bất kỳ loại nào [ngoại trừ nil]. Đặc biệt, vì các hàm là giá trị hạng nhất nên các trường bảng có thể chứa các hàm. Do đó, các bảng cũng có thể mang các phương thức [xem §2. 5. 9]

Các bảng, hàm, luồng và giá trị dữ liệu người dùng [đầy đủ] là các đối tượng. các biến không thực sự chứa các giá trị này, chỉ tham chiếu đến chúng. Phép gán, truyền tham số và trả về hàm luôn thao tác với các tham chiếu đến các giá trị đó;

Hàm thư viện

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
96 trả về một chuỗi mô tả loại của một giá trị đã cho

Lua cung cấp chuyển đổi tự động giữa các giá trị chuỗi và số trong thời gian chạy. Bất kỳ phép toán số học nào được áp dụng cho một chuỗi đều cố gắng chuyển đổi chuỗi này thành một số, tuân theo các quy tắc chuyển đổi thông thường. Ngược lại, bất cứ khi nào một số được sử dụng khi một chuỗi được mong đợi, thì số đó sẽ được chuyển đổi thành một chuỗi, ở định dạng hợp lý. Để kiểm soát hoàn toàn cách số được chuyển đổi thành chuỗi, hãy sử dụng hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97 từ thư viện chuỗi [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
98]

Biến là nơi lưu trữ giá trị. Có ba loại biến trong Lua. biến toàn cục, biến cục bộ và trường bảng

Một tên duy nhất có thể biểu thị biến toàn cục hoặc biến cục bộ [hoặc tham số chính thức của hàm, là một loại biến cục bộ cụ thể]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
7

Tên biểu thị định danh, như được định nghĩa trong §2. 1

Bất kỳ biến nào được coi là toàn cục trừ khi được khai báo rõ ràng là cục bộ [xem §2. 4. 7]. Các biến cục bộ có phạm vi từ vựng. các biến cục bộ có thể được truy cập tự do bởi các hàm được định nghĩa bên trong phạm vi của chúng [xem §2. 6]

Trước lần gán đầu tiên cho một biến, giá trị của nó là không

Dấu ngoặc vuông được sử dụng để lập chỉ mục cho bảng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
8

Ý nghĩa của việc truy cập vào các biến toàn cục và trường bảng có thể được thay đổi thông qua metatables. Quyền truy cập vào một biến được lập chỉ mục

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
99 tương đương với một cuộc gọi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
700. [Xem §2. 8 để biết mô tả đầy đủ về hàm
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
701. Hàm này không được xác định hoặc không thể gọi được trong Lua. Chúng tôi sử dụng nó ở đây chỉ cho mục đích giải thích. ]

Cú pháp

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
702 chỉ là đường cú pháp cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
703

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
4

Tất cả các biến toàn cục tồn tại dưới dạng các trường trong bảng Lua thông thường, được gọi là bảng môi trường hoặc đơn giản là môi trường [xem §2. 9]. Mỗi hàm có tham chiếu riêng đến một môi trường, do đó tất cả các biến toàn cục trong hàm này sẽ tham chiếu đến bảng môi trường này. Khi một hàm được tạo, nó sẽ kế thừa môi trường từ hàm đã tạo ra nó. Để lấy bảng môi trường của hàm Lua, bạn gọi

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
704. Để thay thế nó, bạn gọi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705. [Bạn chỉ có thể thao tác với môi trường của các hàm C thông qua thư viện gỡ lỗi; [xem §5. 9]. ]

Quyền truy cập vào biến toàn cục

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 tương đương với
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
707, do đó tương đương với

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
9

trong đó

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
708 là môi trường của chức năng đang chạy. [Xem §2. 8 để biết mô tả đầy đủ về hàm
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
701. Hàm này không được xác định hoặc không thể gọi được trong Lua. Tương tự, biến
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
708 không được định nghĩa trong Lua. Chúng tôi sử dụng chúng ở đây chỉ cho mục đích giải thích. ]

Lua hỗ trợ một tập hợp các câu lệnh gần như thông thường, tương tự như trong Pascal hoặc C. Bộ này bao gồm các phép gán, cấu trúc điều khiển, lời gọi hàm và khai báo biến

Đơn vị thực hiện Lua được gọi là chunk. Một đoạn chỉ đơn giản là một chuỗi các câu lệnh, được thực hiện tuần tự. Mỗi câu lệnh có thể được tùy chọn theo sau bởi dấu chấm phẩy

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
3

Không có tuyên bố trống và do đó '______2711' là không hợp pháp

Lua xử lý một đoạn dưới dạng phần thân của hàm ẩn danh với số lượng đối số thay đổi [xem §2. 5. 9]. Như vậy, các khối có thể xác định các biến cục bộ, nhận đối số và trả về giá trị

Một đoạn có thể được lưu trữ trong một tệp hoặc trong một chuỗi bên trong chương trình máy chủ. Để thực thi một đoạn mã, trước tiên, Lua biên dịch trước đoạn mã đó thành các hướng dẫn cho máy ảo, sau đó nó thực thi mã đã biên dịch bằng một trình thông dịch cho máy ảo

Các khối cũng có thể được biên dịch trước thành dạng nhị phân; . Các chương trình ở dạng mã nguồn và biên dịch có thể hoán đổi cho nhau;

Một khối là một danh sách các câu lệnh;

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
6

Một khối có thể được phân định rõ ràng để tạo ra một câu lệnh

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
0

Các khối rõ ràng rất hữu ích để kiểm soát phạm vi khai báo biến. Các khối rõ ràng đôi khi cũng được sử dụng để thêm câu lệnh return hoặc break vào giữa một khối khác [xem §2. 4. 4]

Lua cho phép nhiều nhiệm vụ. Do đó, cú pháp gán định nghĩa một danh sách các biến ở bên trái và một danh sách các biểu thức ở bên phải. Các phần tử trong cả hai danh sách được phân tách bằng dấu phẩy

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
1

Biểu thức được thảo luận trong §2. 5

Trước khi gán, danh sách các giá trị được điều chỉnh theo độ dài của danh sách các biến. Nếu có nhiều giá trị hơn mức cần thiết, các giá trị dư thừa sẽ bị loại bỏ. Nếu có ít giá trị hơn mức cần thiết, danh sách sẽ được mở rộng với bao nhiêu giá trị không cần thiết. Nếu danh sách các biểu thức kết thúc bằng một lời gọi hàm, thì tất cả các giá trị được trả về bởi lời gọi đó sẽ nhập danh sách các giá trị, trước khi điều chỉnh [ngoại trừ khi lời gọi được đặt trong ngoặc đơn; xem §2. 5]

Câu lệnh gán trước tiên đánh giá tất cả các biểu thức của nó và chỉ sau đó các phép gán mới được thực hiện. Như vậy mã

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
2

đặt

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
713 thành 20 mà không ảnh hưởng đến
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
714 vì
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 trong
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
716 được đánh giá [thành 3] trước khi được chỉ định 4. Similarly, the line

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
3

trao đổi các giá trị của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
718, và

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
4

hoán vị theo chu kỳ các giá trị của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
718 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
721

Ý nghĩa của việc gán cho các biến toàn cục và các trường bảng có thể được thay đổi thông qua metatables. Một phép gán cho một biến được lập chỉ mục

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
722 tương đương với
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
723. [Xem §2. 8 để biết mô tả đầy đủ về hàm
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
724. Hàm này không được xác định hoặc không thể gọi được trong Lua. Chúng tôi sử dụng nó ở đây chỉ cho mục đích giải thích. ]

Phép gán cho một biến toàn cục

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
725 tương đương với phép gán
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
726, đến lượt nó tương đương với

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
5

trong đó

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
708 là môi trường của chức năng đang chạy. [Biến
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
708 không được định nghĩa trong Lua. Chúng tôi sử dụng nó ở đây chỉ cho mục đích giải thích. ]

Các cấu trúc điều khiển if, while và repeat có nghĩa thông thường và cú pháp quen thuộc

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
6

Lua cũng có một câu lệnh for, có hai dạng [xem §2. 4. 5]

Biểu thức điều kiện của cấu trúc điều khiển có thể trả về bất kỳ giá trị nào. Cả sai và không đều được coi là sai. Mọi giá trị khác nil và false đều được coi là đúng [đặc biệt số 0 và chuỗi rỗng cũng đúng]

Trong vòng lặp repeat–until, khối bên trong không kết thúc ở từ khóa until mà chỉ kết thúc sau điều kiện. Vì vậy, điều kiện có thể tham chiếu đến các biến cục bộ được khai báo bên trong khối vòng lặp

Câu lệnh return được sử dụng để trả về các giá trị từ một hàm hoặc một đoạn [chỉ là một hàm]. Các hàm và khối có thể trả về nhiều hơn một giá trị, do đó, cú pháp của câu lệnh trả về là

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
7

Câu lệnh break được sử dụng để kết thúc việc thực hiện vòng lặp while, repeat hoặc for, chuyển sang câu lệnh tiếp theo sau vòng lặp

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
8

Một sự phá vỡ kết thúc vòng lặp kèm theo trong cùng

Câu lệnh return và break chỉ có thể được viết dưới dạng câu lệnh cuối cùng của khối. Nếu thực sự cần thiết phải quay lại hoặc ngắt ở giữa một khối, thì có thể sử dụng khối bên trong rõ ràng, như trong thành ngữ

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
729 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
730, bởi vì bây giờ trả về và ngắt là câu lệnh cuối cùng trong khối [bên trong] của chúng

The for statement has two forms. một số và một chung chung

Vòng lặp số cho lặp lại một khối mã trong khi một biến điều khiển chạy qua một cấp số cộng. Nó có cú pháp sau

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
9

Khối được lặp lại cho tên bắt đầu từ giá trị của điểm kinh nghiệm đầu tiên, cho đến khi nó vượt qua điểm kinh nghiệm thứ hai theo các bước của điểm kinh nghiệm thứ ba. Chính xác hơn, một câu lệnh for như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
0

tương đương với mã

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
1

Lưu ý những điều dưới đây

  • Tất cả ba biểu thức điều khiển chỉ được đánh giá một lần, trước khi vòng lặp bắt đầu. Tất cả chúng đều phải dẫn đến những con số
  •      and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    731,
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    732 và
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    733 là các biến vô hình. Tên hiển thị ở đây chỉ nhằm mục đích giải thích
  • Nếu biểu thức thứ ba [bước] không có, thì bước 1 được sử dụng
  • Bạn có thể sử dụng break để thoát khỏi vòng lặp for
  • Biến vòng lặp
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    734 là cục bộ của vòng lặp; . Nếu bạn cần giá trị này, hãy gán nó cho một biến khác trước khi ngắt hoặc thoát khỏi vòng lặp

Câu lệnh for chung hoạt động trên các hàm, được gọi là trình vòng lặp. Trên mỗi lần lặp, hàm lặp được gọi để tạo ra một giá trị mới, dừng khi giá trị mới này bằng không. Vòng lặp for chung có cú pháp sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
2

Một tuyên bố cho như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
3

tương đương với mã

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
4

Lưu ý những điều dưới đây

  •      and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    735 chỉ được đánh giá một lần. Kết quả của nó là một hàm lặp, trạng thái và giá trị ban đầu cho biến lặp đầu tiên
  •      and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    736,
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    737 và
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    731 là các biến vô hình. Các tên ở đây chỉ nhằm mục đích giải thích
  • Bạn có thể sử dụng break để thoát khỏi vòng lặp for
  • Các biến vòng lặp
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    739 là cục bộ của vòng lặp; . Nếu bạn cần những giá trị này, hãy gán chúng cho các biến khác trước khi ngắt hoặc thoát khỏi vòng lặp

Để cho phép các tác dụng phụ có thể xảy ra, các lệnh gọi hàm có thể được thực hiện dưới dạng các câu lệnh

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
5

Trong trường hợp này, tất cả các giá trị trả về sẽ bị loại bỏ. Các cuộc gọi chức năng được giải thích trong §2. 5. 8

Các biến cục bộ có thể được khai báo ở bất cứ đâu bên trong một khối. Tuyên bố có thể bao gồm một nhiệm vụ ban đầu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
6

Nếu có, phép gán ban đầu có cùng ngữ nghĩa của phép gán nhiều lần [xem §2. 4. 3]. Mặt khác, tất cả các biến được khởi tạo bằng nil

Một đoạn cũng là một khối [xem §2. 4. 1] và vì vậy các biến cục bộ có thể được khai báo trong một đoạn bên ngoài bất kỳ khối rõ ràng nào. Phạm vi của các biến cục bộ như vậy kéo dài cho đến khi kết thúc đoạn

Các quy tắc hiển thị cho các biến cục bộ được giải thích trong §2. 6

Các biểu thức cơ bản trong Lua như sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
7

Số và chuỗi ký tự được giải thích trong §2. 1; . 3; . 5. 9; . 5. số 8; . 5. 7. Các biểu thức Vararg, được biểu thị bằng ba dấu chấm ['______2740'], chỉ có thể được sử dụng khi trực tiếp bên trong một hàm vararg; . 5. 9

Các toán tử nhị phân bao gồm các toán tử số học [xem §2. 5. 1], toán tử quan hệ [xem §2. 5. 2], toán tử logic [xem §2. 5. 3] và toán tử nối [xem §2. 5. 4]. Toán tử đơn nguyên bao gồm phép trừ đơn nguyên [xem §2. 5. 1], đơn thức không [xem §2. 5. 3] và toán tử độ dài một ngôi [xem §2. 5. 5]

Cả lệnh gọi hàm và biểu thức vararg đều có thể dẫn đến nhiều giá trị. Nếu một biểu thức được sử dụng như một câu lệnh [chỉ khả thi đối với các lời gọi hàm [xem §2. 4. 6]], thì danh sách trả về của nó được điều chỉnh thành các phần tử bằng 0, do đó loại bỏ tất cả các giá trị được trả về. Nếu một biểu thức được sử dụng làm thành phần cuối cùng [hoặc duy nhất] của danh sách các biểu thức, thì không có điều chỉnh nào được thực hiện [trừ khi lệnh gọi được đặt trong ngoặc đơn]. Trong tất cả các ngữ cảnh khác, Lua điều chỉnh danh sách kết quả thành một phần tử, loại bỏ tất cả các giá trị ngoại trừ phần tử đầu tiên

Dưới đây là một số ví dụ

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
8

Bất kỳ biểu thức nào được đặt trong ngoặc đơn luôn chỉ dẫn đến một giá trị. Do đó,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
741 luôn là một giá trị duy nhất, ngay cả khi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 trả về một số giá trị. [Giá trị của
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
741 là giá trị đầu tiên được trả về bởi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 hoặc nil nếu
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 không trả về bất kỳ giá trị nào. ]

Lua hỗ trợ các toán tử số học thông thường. nhị phân

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
746 [cộng],
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
747 [phép trừ],
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
748 [nhân],
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
749 [chia],
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
750 [mô đun] và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
751 [lũy thừa]; . Nếu toán hạng là số hoặc chuỗi có thể chuyển đổi thành số [xem §2. 2. 1], sau đó tất cả các hoạt động có ý nghĩa thông thường. Lũy thừa hoạt động cho bất kỳ số mũ nào. Chẳng hạn,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
753 tính nghịch đảo của căn bậc hai của
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706. Modulo được định nghĩa là

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
9

Nghĩa là, phần còn lại của một phép chia làm tròn thương số về âm vô cực

Các toán tử quan hệ trong Lua là

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
70

Các toán tử này luôn dẫn đến sai hoặc đúng

Đẳng thức [

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
755] trước tiên so sánh loại toán hạng của nó. Nếu các loại khác nhau, thì kết quả là sai. Mặt khác, các giá trị của toán hạng được so sánh. Số và chuỗi được so sánh theo cách thông thường. Các đối tượng [bảng, dữ liệu người dùng, luồng và hàm] được so sánh bằng tham chiếu. hai đối tượng được coi là bằng nhau chỉ khi chúng là cùng một đối tượng. Mỗi khi bạn tạo một đối tượng mới [bảng, dữ liệu người dùng, chuỗi hoặc hàm], đối tượng mới này sẽ khác với bất kỳ đối tượng nào đã tồn tại trước đó

Bạn có thể thay đổi cách Lua so sánh các bảng và dữ liệu người dùng bằng cách sử dụng siêu phương thức "eq" [xem §2. số 8]

Quy tắc chuyển đổi của §2. 2. 1 không áp dụng cho so sánh bình đẳng. Do đó,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
756 đánh giá là sai và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
757 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
758 biểu thị các mục khác nhau trong một bảng

Toán tử

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
759 chính xác là phủ định của đẳng thức [
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
755]

Các toán tử đặt hàng hoạt động như sau. Nếu cả hai đối số là số, thì chúng được so sánh như vậy. Mặt khác, nếu cả hai đối số đều là chuỗi, thì giá trị của chúng được so sánh theo ngôn ngữ hiện tại. Mặt khác, Lua cố gắng gọi siêu phương thức "lt" hoặc "le" [xem §2. số 8]. Một so sánh

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
761 được dịch sang
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
762 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
763 được dịch sang
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
764

Các toán tử logic trong Lua là và, hoặc, và không. Giống như các cấu trúc điều khiển [xem §2. 4. 4], tất cả các toán tử logic coi cả false và nil là false và bất kỳ thứ gì khác là true

Toán tử phủ định không phải lúc nào cũng trả về false hoặc true. Toán tử kết hợp và trả về đối số đầu tiên của nó nếu giá trị này là sai hoặc không; . Toán tử phân tách hoặc trả về đối số đầu tiên của nó nếu giá trị này khác với nil và false; . Cả hai và và hoặc sử dụng đánh giá ngắn hạn; . Dưới đây là một số ví dụ

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
71

[Trong sách hướng dẫn này,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
765 biểu thị kết quả của biểu thức trước. ]

Toán tử nối chuỗi trong Lua được biểu thị bằng hai dấu chấm ['

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
766']. Nếu cả hai toán hạng đều là chuỗi hoặc số, thì chúng được chuyển đổi thành chuỗi theo các quy tắc được đề cập trong §2. 2. 1. Mặt khác, siêu phương thức "concat" được gọi [xem §2. số 8]

Toán tử độ dài được biểu thị bằng toán tử một ngôi

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
767. Độ dài của một chuỗi là số byte của nó [nghĩa là ý nghĩa thông thường của độ dài chuỗi khi mỗi ký tự là một byte]

Độ dài của bảng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 được định nghĩa là bất kỳ chỉ số số nguyên nào
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 sao cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
770 không phải là số không và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
771 là số không; . Đối với một mảng thông thường, với các giá trị khác không từ 1 đến một
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 đã cho, độ dài của nó chính xác là
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769, chỉ mục của giá trị cuối cùng của nó. Nếu mảng có "lỗ hổng" [nghĩa là giá trị nil giữa các giá trị không phải nil khác], thì
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
776 có thể là bất kỳ chỉ số nào trực tiếp đứng trước giá trị nil [nghĩa là, nó có thể coi bất kỳ giá trị nil nào như vậy là kết thúc của

Thứ tự ưu tiên của toán tử trong Lua tuân theo bảng bên dưới, từ mức ưu tiên thấp hơn đến cao hơn

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
72

Như thường lệ, bạn có thể sử dụng dấu ngoặc đơn để thay đổi thứ tự ưu tiên của một biểu thức. Toán tử nối ['

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
766'] và lũy thừa ['
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
751'] là phép kết hợp đúng. Tất cả các toán tử nhị phân khác được để lại kết hợp

Hàm tạo bảng là các biểu thức tạo bảng. Mỗi khi một hàm tạo được đánh giá, một bảng mới sẽ được tạo. Một hàm tạo có thể được sử dụng để tạo một bảng trống hoặc để tạo một bảng và khởi tạo một số trường của nó. Cú pháp chung cho các hàm tạo là

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
73

Mỗi trường của biểu mẫu

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
779 thêm vào bảng mới một mục có khóa
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
780 và giá trị
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
781. Một trường có dạng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
782 tương đương với
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
783. Finally, fields of the form
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
784 are equivalent to
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
785, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 are consecutive numerical integers, starting with 1. Fields in the other formats do not affect this counting. For example,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
74

is equivalent to

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
75

If the last field in the list has the form

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
784 and the expression is a function call or a vararg expression, then all values returned by this expression enter the list consecutively [see §2. 5. 8]. To avoid this, enclose the function call or the vararg expression in parentheses [see §2. 5]

The field list can have an optional trailing separator, as a convenience for machine-generated code

Một lời gọi hàm trong Lua có cú pháp như sau

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
76

In a function call, first prefixexp and args are evaluated. If the value of prefixexp has type function, then this function is called with the given arguments. Otherwise, the prefixexp "call" metamethod is called, having as first parameter the value of prefixexp, followed by the original call arguments [see §2. 8]

The form

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
77

can be used to call "methods". A call

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
788 is syntactic sugar for
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
789, except that
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734 is evaluated only once

Arguments have the following syntax

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
78

All argument expressions are evaluated before the call. A call of the form

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
791 is syntactic sugar for
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
792; that is, the argument list is a single new table. A call of the form
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
793 [or
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
794 or
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
795] is syntactic sugar for
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
796; that is, the argument list is a single literal string

As an exception to the free-format syntax of Lua, you cannot put a line break before the '

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
797' in a function call. This restriction avoids some ambiguities in the language. If you write

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
79

Lua would see that as a single statement,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
798. So, if you want two statements, you must add a semi-colon between them. If you actually want to call
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742, you must remove the line break before
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
700

A call of the form

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
701 functioncall is called a tail call. Lua implements proper tail calls [or proper tail recursion]. trong một cuộc gọi đuôi, chức năng được gọi sử dụng lại mục ngăn xếp của chức năng gọi. Therefore, there is no limit on the number of nested tail calls that a program can execute. However, a tail call erases any debug information about the calling function. Note that a tail call only happens with a particular syntax, where the return has one single function call as argument; this syntax makes the calling function return exactly the returns of the called function. So, none of the following examples are tail calls

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
70

The syntax for function definition is

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
71

The following syntactic sugar simplifies function definitions

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
72

The statement

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
73

translates to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
74

The statement

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
75

translates to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
76

The statement

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
77

translates to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
78

not to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
79

[This only makes a difference when the body of the function contains references to

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742. ]

A function definition is an executable expression, whose value has type function. When Lua pre-compiles a chunk, all its function bodies are pre-compiled too. Then, whenever Lua executes the function definition, the function is instantiated [or closed]. This function instance [or closure] is the final value of the expression. Different instances of the same function can refer to different external local variables and can have different environment tables

Parameters act as local variables that are initialized with the argument values

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
80

When a function is called, the list of arguments is adjusted to the length of the list of parameters, unless the function is a variadic or vararg function, which is indicated by three dots ['

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
740'] at the end of its parameter list. A vararg function does not adjust its argument list; instead, it collects all extra arguments and supplies them to the function through a vararg expression, which is also written as three dots. The value of this expression is a list of all actual extra arguments, similar to a function with multiple results. If a vararg expression is used inside another expression or in the middle of a list of expressions, then its return list is adjusted to one element. Nếu biểu thức được sử dụng làm thành phần cuối cùng của danh sách các biểu thức, thì không có điều chỉnh nào được thực hiện [trừ khi biểu thức cuối cùng đó được đặt trong ngoặc đơn]

As an example, consider the following definitions

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
81

Then, we have the following mapping from arguments to parameters and to the vararg expression

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
82

Results are returned using the return statement [see §2. 4. 4]. If control reaches the end of a function without encountering a return statement, then the function returns with no results

The colon syntax is used for defining methods, that is, functions that have an implicit extra parameter

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
704. Thus, the statement

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
83

is syntactic sugar for

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
84

Lua is a lexically scoped language. The scope of variables begins at the first statement after their declaration and lasts until the end of the innermost block that includes the declaration. Xem xét ví dụ sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
85

Lưu ý rằng, trong một khai báo như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
705, biến
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 mới được khai báo chưa nằm trong phạm vi, và vì vậy, biến
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 thứ hai đề cập đến biến bên ngoài

Because of the lexical scoping rules, local variables can be freely accessed by functions defined inside their scope. A local variable used by an inner function is called an upvalue, or external local variable, inside the inner function

Notice that each execution of a local statement defines new local variables. Consider the following example

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
86

The loop creates ten closures [that is, ten instances of the anonymous function]. Each of these closures uses a different

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
718 variable, while all of them share the same
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Because Lua is an embedded extension language, all Lua actions start from C code in the host program calling a function from the Lua library [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710]. Whenever an error occurs during Lua compilation or execution, control returns to C, which can take appropriate measures [such as printing an error message]

Lua code can explicitly generate an error by calling the

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
711 function. If you need to catch errors in Lua, you can use the
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
712 function

Every value in Lua can have a metatable. This metatable is an ordinary Lua table that defines the behavior of the original value under certain special operations. You can change several aspects of the behavior of operations over a value by setting specific fields in its metatable. For instance, when a non-numeric value is the operand of an addition, Lua checks for a function in the field

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
713 in its metatable. If it finds one, Lua calls this function to perform the addition

We call the keys in a metatable events and the values metamethods. In the previous example, the event is

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
714 and the metamethod is the function that performs the addition

You can query the metatable of any value through the

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
715 function

You can replace the metatable of tables through the

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
716 function. You cannot change the metatable of other types from Lua [except by using the debug library]; you must use the C API for that

Tables and full userdata have individual metatables [although multiple tables and userdata can share their metatables]. Values of all other types share one single metatable per type; that is, there is one single metatable for all numbers, one for all strings, etc

A metatable controls how an object behaves in arithmetic operations, order comparisons, concatenation, length operation, and indexing. A metatable also can define a function to be called when a userdata is garbage collected. For each of these operations Lua associates a specific key called an event. When Lua performs one of these operations over a value, it checks whether this value has a metatable with the corresponding event. If so, the value associated with that key [the metamethod] controls how Lua will perform the operation

Metatables control the operations listed next. Each operation is identified by its corresponding name. Chìa khóa cho mỗi thao tác là một chuỗi có tên bắt đầu bằng hai dấu gạch dưới, '

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
717'; . Ngữ nghĩa của các thao tác này được giải thích rõ hơn bằng hàm Lua mô tả cách trình thông dịch thực hiện thao tác

The code shown here in Lua is only illustrative; the real behavior is hard coded in the interpreter and it is much more efficient than this simulation. All functions used in these descriptions [

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
719,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
720, etc. ] are described in §5. 1. In particular, to retrieve the metamethod of a given object, we use the expression

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
87

This should be read as

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
88

That is, the access to a metamethod does not invoke other metamethods, and the access to objects with no metatables does not fail [it simply results in nil]

  • "add". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    746 operation

    The function

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    722 below defines how Lua chooses a handler for a binary operation. First, Lua tries the first operand. If its type does not define a handler for the operation, then Lua tries the second operand

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    89

    By using this function, the behavior of the

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    723 is

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    40
  • "sub". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747 operation. Behavior similar to the "add" operation
  • "mul". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    748 operation. Behavior similar to the "add" operation
  • "div". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    749 operation. Behavior similar to the "add" operation
  • "mod". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    750 operation. Behavior similar to the "add" operation, with the operation
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    728 as the primitive operation
  • "pow". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    751 [exponentiation] operation. Behavior similar to the "add" operation, with the function
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    730 [from the C math library] as the primitive operation
  • "unm". the unary
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747 operation.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    41
  • "concat". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    766 [concatenation] operation.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    42
  • "len". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    767 operation.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    43

    See §2. 5. 5 for a description of the length of a table

  • "eq". the
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    755 operation. The function
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    735 defines how Lua chooses a metamethod for comparison operators. A metamethod only is selected when both objects being compared have the same type and the same metamethod for the selected operation.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    44

    The "eq" event is defined as follows

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    45

         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    736 is equivalent to
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    737

  • "lt". the
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    738 operation.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    46

         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    761 is equivalent to
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    762

  • "le". hoạt động của
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    741.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    47

         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    763 is equivalent to
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    764. Note that, in the absence of a "le" metamethod, Lua tries the "lt", assuming that
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    744 is equivalent to
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    745

  • "index". The indexing access
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    746.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    48
  • "newindex". The indexing assignment
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    747.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    49
  • "call". called when Lua calls a value.
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    90

Besides metatables, objects of types thread, function, and userdata have another table associated with them, called their environment. Like metatables, environments are regular tables and multiple objects can share the same environment

Threads are created sharing the environment of the creating thread. Userdata and C functions are created sharing the environment of the creating C function. Non-nested Lua functions [created by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
748,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
749 or
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
750] are created sharing the environment of the creating thread. Nested Lua functions are created sharing the environment of the creating Lua function

Environments associated with userdata have no meaning for Lua. It is only a convenience feature for programmers to associate a table to a userdata

Environments associated with threads are called global environments. They are used as the default environment for threads and non-nested Lua functions created by the thread and can be directly accessed by C code [see §3. 3]

The environment associated with a C function can be directly accessed by C code [see §3. 3]. It is used as the default environment for other C functions and userdata created by the function

Environments associated with Lua functions are used to resolve all accesses to global variables within the function [see §2. 3]. They are used as the default environment for nested Lua functions created by the function

You can change the environment of a Lua function or the running thread by calling

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705. Bạn có thể lấy môi trường của một hàm Lua hoặc luồng đang chạy bằng cách gọi _
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
704. To manipulate the environment of other objects [userdata, C functions, other threads] you must use the C API

Lua performs automatic memory management. This means that you have to worry neither about allocating memory for new objects nor about freeing it when the objects are no longer needed. Lua manages memory automatically by running a garbage collector from time to time to collect all dead objects [that is, objects that are no longer accessible from Lua]. Tất cả bộ nhớ được Lua sử dụng đều được quản lý tự động. tables, userdata, functions, threads, strings, etc

Lua implements an incremental mark-and-sweep collector. It uses two numbers to control its garbage-collection cycles. the garbage-collector pause and the garbage-collector step multiplier. Both use percentage points as units [so that a value of 100 means an internal value of 1]

The garbage-collector pause controls how long the collector waits before starting a new cycle. Larger values make the collector less aggressive. Values smaller than 100 mean the collector will not wait to start a new cycle. A value of 200 means that the collector waits for the total memory in use to double before starting a new cycle

The step multiplier controls the relative speed of the collector relative to memory allocation. Larger values make the collector more aggressive but also increase the size of each incremental step. Values smaller than 100 make the collector too slow and can result in the collector never finishing a cycle. The default, 200, means that the collector runs at "twice" the speed of memory allocation

You can change these numbers by calling

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
753 in C or
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
754 in Lua. With these functions you can also control the collector directly [e. g. , stop and restart it]

Using the C API, you can set garbage-collector metamethods for userdata [see §2. 8]. These metamethods are also called finalizers. Finalizers allow you to coordinate Lua's garbage collection with external resource management [such as closing files, network or database connections, or freeing your own memory]

Garbage userdata with a field

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
755 in their metatables are not collected immediately by the garbage collector. Instead, Lua puts them in a list. After the collection, Lua does the equivalent of the following function for each userdata in that list

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
91

At the end of each garbage-collection cycle, the finalizers for userdata are called in reverse order of their creation, among those collected in that cycle. That is, the first finalizer to be called is the one associated with the userdata created last in the program. The userdata itself is freed only in the next garbage-collection cycle

A weak table is a table whose elements are weak references. A weak reference is ignored by the garbage collector. In other words, if the only references to an object are weak references, then the garbage collector will collect this object

A weak table can have weak keys, weak values, or both. A table with weak keys allows the collection of its keys, but prevents the collection of its values. A table with both weak keys and weak values allows the collection of both keys and values. In any case, if either the key or the value is collected, the whole pair is removed from the table. The weakness of a table is controlled by the

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
756 field of its metatable. If the
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
756 field is a string containing the character '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
758', the keys in the table are weak. If
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
756 contains '
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734', the values in the table are weak

Sau khi bạn sử dụng bảng làm bảng siêu dữ liệu, bạn không nên thay đổi giá trị của trường

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
756 của bảng đó. Mặt khác, hành vi yếu của các bảng được kiểm soát bởi siêu dữ liệu này là không xác định

Lua supports coroutines, also called collaborative multithreading. A coroutine in Lua represents an independent thread of execution. Unlike threads in multithread systems, however, a coroutine only suspends its execution by explicitly calling a yield function

You create a coroutine with a call to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
762. Its sole argument is a function that is the main function of the coroutine. The
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
763 function only creates a new coroutine and returns a handle to it [an object of type thread]; it does not start the coroutine execution

When you first call

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764, passing as its first argument a thread returned by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
762, the coroutine starts its execution, at the first line of its main function. Extra arguments passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764 are passed on to the coroutine main function. After the coroutine starts running, it runs until it terminates or yields

A coroutine can terminate its execution in two ways. normally, when its main function returns [explicitly or implicitly, after the last instruction]; and abnormally, if there is an unprotected error. In the first case,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764 returns true, plus any values returned by the coroutine main function. In case of errors,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764 returns false plus an error message

A coroutine yields by calling

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
769. When a coroutine yields, the corresponding
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764 returns immediately, even if the yield happens inside nested function calls [that is, not in the main function, but in a function directly or indirectly called by the main function]. In the case of a yield,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764 also returns true, plus any values passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
769. The next time you resume the same coroutine, it continues its execution from the point where it yielded, with the call to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
769 returning any extra arguments passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764

Like

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
762, the
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
776 function also creates a coroutine, but instead of returning the coroutine itself, it returns a function that, when called, resumes the coroutine. Any arguments passed to this function go as extra arguments to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
776 returns all the values returned by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764, except the first one [the boolean error code]. Unlike
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
764,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
776 does not catch errors; any error is propagated to the caller

As an example, consider the following code

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92

When you run it, it produces the following output

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
93

This section describes the C API for Lua, that is, the set of C functions available to the host program to communicate with Lua. All API functions and related types and constants are declared in the header file

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
782

Ngay cả khi chúng tôi sử dụng thuật ngữ "chức năng", bất kỳ cơ sở nào trong API có thể được cung cấp dưới dạng macro thay thế. Tất cả các macro như vậy sử dụng mỗi đối số của chúng đúng một lần [ngoại trừ đối số đầu tiên, luôn ở trạng thái Lua] và do đó không tạo ra bất kỳ tác dụng phụ ẩn nào

Như trong hầu hết các thư viện C, các hàm Lua API không kiểm tra đối số của chúng về tính hợp lệ hoặc nhất quán. However, you can change this behavior by compiling Lua with a proper definition for the macro

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
783, in file
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92

Lua uses a virtual stack to pass values to and from C. Each element in this stack represents a Lua value [nil, number, string, etc. ]

Whenever Lua calls C, the called function gets a new stack, which is independent of previous stacks and of stacks of C functions that are still active. This stack initially contains any arguments to the C function and it is where the C function pushes its results to be returned to the caller [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
785]

For convenience, most query operations in the API do not follow a strict stack discipline. Instead, they can refer to any element in the stack by using an index. A positive index represents an absolute stack position [starting at 1]; a negative index represents an offset relative to the top of the stack. More specifically, if the stack has n elements, then index 1 represents the first element [that is, the element that was pushed onto the stack first] and index n represents the last element; index -1 also represents the last element [that is, the element at the top] and index -n represents the first element. We say that an index is valid if it lies between 1 and the stack top [that is, if

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
786]

When you interact with Lua API, you are responsible for ensuring consistency. In particular, you are responsible for controlling stack overflow. You can use the function

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
787 to grow the stack size

Whenever Lua calls C, it ensures that at least

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
788 stack positions are available.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
788 is defined as 20, so that usually you do not have to worry about stack space unless your code has loops pushing elements onto the stack

Most query functions accept as indices any value inside the available stack space, that is, indices up to the maximum stack size you have set through

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
787. Such indices are called acceptable indices. More formally, we define an acceptable index as follows

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
94

Note that 0 is never an acceptable index

Unless otherwise noted, any function that accepts valid indices can also be called with pseudo-indices, which represent some Lua values that are accessible to C code but which are not in the stack. Pseudo-indices are used to access the thread environment, the function environment, the registry, and the upvalues of a C function [see §3. 4]

The thread environment [where global variables live] is always at pseudo-index

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
791. The environment of the running C function is always at pseudo-index
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
792

To access and change the value of global variables, you can use regular table operations over an environment table. For instance, to access the value of a global variable, do

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
95

When a C function is created, it is possible to associate some values with it, thus creating a C closure; these values are called upvalues and are accessible to the function whenever it is called [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
793]

Whenever a C function is called, its upvalues are located at specific pseudo-indices. These pseudo-indices are produced by the macro

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
794. The first value associated with a function is at position
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
795, and so on. Any access to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
796, where n is greater than the number of upvalues of the current function [but not greater than 256], produces an acceptable [but invalid] index

Lua provides a registry, a pre-defined table that can be used by any C code to store whatever Lua value it needs to store. This table is always located at pseudo-index

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
797. Any C library can store data into this table, but it should take care to choose keys different from those used by other libraries, to avoid collisions. Typically, you should use as key a string containing your library name or a light userdata with the address of a C object in your code

The integer keys in the registry are used by the reference mechanism, implemented by the auxiliary library, and therefore should not be used for other purposes

Internally, Lua uses the C

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
798 facility to handle errors. [You can also choose to use exceptions if you use C++; see file
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92. ] When Lua faces any error [such as memory allocation errors, type errors, syntax errors, and runtime errors] it raises an error; that is, it does a long jump. A protected environment uses
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
800 to set a recover point; any error jumps to the most recent active recover point

Most functions in the API can throw an error, for instance due to a memory allocation error. The documentation for each function indicates whether it can throw errors

Inside a C function you can throw an error by calling

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
801

Here we list all functions and types from the C API in alphabetical order. Each function has an indicator like this. [-o, +p, x]

The first field,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
802, is how many elements the function pops from the stack. The second field,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
803, is how many elements the function pushes onto the stack. [Any function always pushes its results after popping its arguments. ] A field in the form
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
804 means the function can push [or pop]
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 or
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
718 elements, depending on the situation; an interrogation mark '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
807' means that we cannot know how many elements the function pops/pushes by looking only at its arguments [e. g. , they may depend on what is on the stack]. The third field,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706, tells whether the function may throw errors. '
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
747' means the function never throws any error; '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
810' means the function may throw an error only due to not enough memory; '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811' means the function may throw other kinds of errors; '
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734' means the function may throw an error on purpose

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
96

The type of the memory-allocation function used by Lua states. The allocator function must provide a functionality similar to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
813, but not exactly the same. Its arguments are
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
814, an opaque pointer passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
815;
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
816, a pointer to the block being allocated/reallocated/freed;
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
817, the original size of the block;
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
818, the new size of the block.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
816 is
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 if and only if
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
817 is zero. When
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
818 is zero, the allocator must return
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820; if
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
817 is not zero, it should free the block pointed to by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
816. When
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
818 is not zero, the allocator returns
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 if and only if it cannot fill the request. When
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
818 is not zero and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
817 is zero, the allocator should behave like
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
830. Khi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
818 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
817 khác không, bộ cấp phát hoạt động như
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
813. Lua assumes that the allocator never fails when
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
834

Here is a simple implementation for the allocator function. It is used in the auxiliary library by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
835

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97

This code assumes that

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
836 has no effect and that
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
837 is equivalent to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
838. ANSI C ensures both behaviors

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
98

Đặt chức năng hoảng loạn mới và trả về chức năng cũ

Nếu một lỗi xảy ra bên ngoài bất kỳ môi trường được bảo vệ nào, Lua sẽ gọi một hàm hoảng loạn và sau đó gọi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
839, do đó thoát khỏi ứng dụng máy chủ. Chức năng hoảng loạn của bạn có thể tránh lối thoát này bằng cách không bao giờ quay lại [e. g. , nhảy xa]

Chức năng hoảng loạn có thể truy cập thông báo lỗi ở đầu ngăn xếp

[-[nargs + 1], +nresults, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
99

Calls a function

To call a function you must use the following protocol. first, the function to be called is pushed onto the stack; then, the arguments to the function are pushed in direct order; that is, the first argument is pushed first. Finally you call

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
840;
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
841 is the number of arguments that you pushed onto the stack. All arguments and the function value are popped from the stack when the function is called. The function results are pushed onto the stack when the function returns. The number of results is adjusted to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
842, unless
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
842 is
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
844. In this case, all results from the function are pushed. Lua takes care that the returned values fit into the stack space. The function results are pushed onto the stack in direct order [the first result is pushed first], so that after the call the last result is on the top of the stack

Any error inside the called function is propagated upwards [with a

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
798]

The following example shows how the host program can do the equivalent to this Lua code

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
30

Here it is in C

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
31

Note that the code above is "balanced". at its end, the stack is back to its original configuration. This is considered good programming practice

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
32

Nhập cho hàm C

Để giao tiếp đúng cách với Lua, một hàm C phải sử dụng giao thức sau, giao thức này xác định cách truyền tham số và kết quả. a C function receives its arguments from Lua in its stack in direct order [the first argument is pushed first]. So, when the function starts,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
846 returns the number of arguments received by the function. The first argument [if any] is at index 1 and its last argument is at index
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
846. To return values to Lua, a C function just pushes them onto the stack, in direct order [the first result is pushed first], and returns the number of results. Any other value in the stack below the results will be properly discarded by Lua. Like a Lua function, a C function called by Lua can also return many results

As an example, the following function receives a variable number of numerical arguments and returns their average and sum

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
33

[-0, +0, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
34

Đảm bảo rằng có ít nhất

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
848 vị trí ngăn xếp miễn phí trong ngăn xếp. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
35

Destroys all objects in the given Lua state [calling the corresponding garbage-collection metamethods, if any] and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. Mặt khác, các chương trình chạy lâu, chẳng hạn như daemon hoặc máy chủ web, có thể cần giải phóng trạng thái ngay khi không cần thiết, để tránh phát triển quá lớn.

[-n, +1, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
36

Concatenates the

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 values at the top of the stack, pops them, and leaves the result at the top. If
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 is 1, the result is the single value on the stack [that is, the function does nothing]; if
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 is 0, the result is the empty string. Concatenation is performed following the usual semantics of Lua [see §2. 5. 4]

[-0, +[0. 1], -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
37

Calls the C function

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 in protected mode.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 starts with only one element in its stack, a light userdata containing
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
814. In case of errors,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
855 returns the same error codes as
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710, plus the error object on the top of the stack; otherwise, it returns zero, and does not change the stack. All values returned by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 are discarded

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
38

Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
858 array elements and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
859 non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
860

[-0, +0, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
39

Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
861 calls function
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
862 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
863] with the given
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
864 to write them

The value returned is the error code returned by the last call to the writer; 0 means no errors

This function does not pop the Lua function from the stack

[-0, +0, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
60

Returns 1 if the two values in acceptable indices

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
865 and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
866 are equal, following the semantics of the Lua
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
755 operator [that is, may call metamethods]. Otherwise returns 0. Also returns 0 if any of the indices is non valid

[-1, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
61

Generates a Lua error. The error message [which can actually be a Lua value of any type] must be on the stack top. This function does a long jump, and therefore never returns. [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
868]

[-0, +0, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
62

Controls the garbage collector

This function performs several tasks, according to the value of the parameter

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869

  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    870. stops the garbage collector
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    871. restarts the garbage collector
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    872. performs a full garbage-collection cycle
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    873. returns the current amount of memory [in Kbytes] in use by Lua
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    874. returns the remainder of dividing the current amount of bytes of memory in use by Lua by 1024
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    875. performs an incremental step of garbage collection. The step "size" is controlled by
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    864 [larger values mean more steps] in a non-specified way. If you want to control the step size you must experimentally tune the value of
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    864. Hàm trả về 1 nếu bước kết thúc chu trình thu gom rác
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    878. sets
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    864 as the new value for the pause of the collector [see §2. 10]. The function returns the previous value of the pause
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    880. sets
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    864 as the new value for the step multiplier of the collector [see §2. 10]. The function returns the previous value of the step multiplier

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
63

Returns the memory-allocation function of a given state. If

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
814 is not
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, Lua stores in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
884 the opaque pointer passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
815

[-0, +1, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
64

Pushes onto the stack the environment table of the value at the given index

[-0, +1, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
65

Pushes onto the stack the value

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
886, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event [see §2. số 8]

[-0, +1, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66

Đẩy vào ngăn xếp giá trị của

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 toàn cầu. Nó được định nghĩa là một macro

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
67

[-0, +[0. 1], -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
68

Đẩy vào ngăn xếp giá trị có thể thay đổi được tại chỉ mục được chấp nhận. Nếu chỉ mục không hợp lệ hoặc nếu giá trị không có bảng chuyển đổi, hàm sẽ trả về 0 và không đẩy gì vào ngăn xếp

[-1, +1, e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
69

Pushes onto the stack the value

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
886, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 is the value at the given valid index and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
758 is the value at the top of the stack

This function pops the key from the stack [putting the resulting value in its place]. As in Lua, this function may trigger a metamethod for the "index" event [see §2. 8]

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
00

Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack [and so 0 means an empty stack]

[-1, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
01

Moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
02

The type used by the Lua API to represent integral values

By default it is a

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
892, which is usually the largest signed integral type the machine handles "comfortably"

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
03

Returns 1 if the value at the given acceptable index has type boolean, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
04

Returns 1 if the value at the given acceptable index is a C function, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
05

Returns 1 if the value at the given acceptable index is a function [either C or Lua], and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
06

Returns 1 if the value at the given acceptable index is a light userdata, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
07

Returns 1 if the value at the given acceptable index is nil, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
08

Returns 1 if the given acceptable index is not valid [that is, it refers to an element outside the current stack], and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
09

Returns 1 if the given acceptable index is not valid [that is, it refers to an element outside the current stack] or if the value at this index is nil, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
10

Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
11

Returns 1 if the value at the given acceptable index is a string or a number [which is always convertible to a string], and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
12

Returns 1 if the value at the given acceptable index is a table, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
13

Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
14

Returns 1 if the value at the given acceptable index is a userdata [either full or light], and 0 otherwise

[-0, +0, e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
15

Returns 1 if the value at acceptable index

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
865 is smaller than the value at acceptable index
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
866, following the semantics of the Lua
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
738 operator [that is, may call metamethods]. Otherwise returns 0. Also returns 0 if any of the indices is non valid

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
16

Loads a Lua chunk. If there are no errors,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 pushes the compiled chunk as a Lua function on top of the stack. Nếu không, nó đẩy một thông báo lỗi. Các giá trị trả về của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 là

This function only loads a chunk; it does not run it

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 automatically detects whether the chunk is text or binary, and loads it accordingly [see program
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
712]

The

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 function uses a user-supplied
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
401 function to read the chunk [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
402]. The
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
864 argument is an opaque value passed to the reader function

The

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
404 argument gives a name to the chunk, which is used for error messages and in debug information [see §3. 8]

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
17

Creates a new, independent state. Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 if cannot create the state [due to lack of memory]. The argument
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 is the allocator function; Lua does all memory allocation for this state through this function. The second argument,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
814, is an opaque pointer that Lua simply passes to the allocator in every call

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
18

Tạo một bảng trống mới và đẩy nó vào ngăn xếp. It is equivalent to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
408

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
19

Creates a new thread, pushes it on the stack, and returns a pointer to a

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
409 that represents this new thread. The new state returned by this function shares with the original state all global objects [such as tables], but has an independent execution stack

There is no explicit function to close or to destroy a thread. Chủ đề có thể được thu gom rác, giống như bất kỳ đối tượng Lua nào

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
20

This function allocates a new block of memory with the given size, pushes onto the stack a new full userdata with the block address, and returns this address

Userdata represent C values in Lua. Dữ liệu người dùng đầy đủ đại diện cho một khối bộ nhớ. Nó là một đối tượng [như một cái bàn]. you must create it, it can have its own metatable, and you can detect when it is being collected. A full userdata is only equal to itself [under raw equality]

When Lua collects a full userdata with a

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
410 metamethod, Lua calls the metamethod and marks the userdata as finalized. When this userdata is collected again then Lua frees its corresponding memory

[-1, +[2. 0], e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
21

Pops a key from the stack, and pushes a key-value pair from the table at the given index [the "next" pair after the given key]. If there are no more elements in the table, then

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
411 returns 0 [and pushes nothing]

A typical traversal looks like this

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
22

While traversing a table, do not call

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 directly on a key, unless you know that the key is actually a string. Recall that
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 changes the value at the given index; this confuses the next call to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
411

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
23

The type of numbers in Lua. By default, it is double, but that can be changed in

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92

Through the configuration file you can change Lua to operate with another type for numbers [e. g. , float or long]

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
24

Returns the "length" of the value at the given acceptable index. for strings, this is the string length; for tables, this is the result of the length operator ['

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
767']; for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0

[-[nargs + 1], +[nresults. 1], -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
25

Calls a function in protected mode

Both

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
841 and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
842 have the same meaning as in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
840. If there are no errors during the call,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710 behaves exactly like
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
840. However, if there is any error,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710 catches it, pushes a single value on the stack [the error message], and returns an error code. Like
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
840,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710 always removes the function and its arguments from the stack

If

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
425 is 0, then the error message returned on the stack is exactly the original error message. Otherwise,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
425 is the stack index of an error handler function. [In the current implementation, this index cannot be a pseudo-index. ] In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710

Typically, the error handler function is used to add more debug information to the error message, such as a stack traceback. Such information cannot be gathered after the return of

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710, since by then the stack has unwound

The

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710 function returns 0 in case of success or one of the following error codes [defined in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
782]

  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    431. a runtime error
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    432. lỗi cấp phát bộ nhớ. Đối với những lỗi như vậy, Lua không gọi hàm xử lý lỗi
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    433. lỗi trong khi chạy chức năng xử lý lỗi

[-n, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
26

Pops

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 elements from the stack

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
27

Pushes a boolean value with value

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
435 onto the stack

[-n, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
28

Pushes a new C closure onto the stack

When a C function is created, it is possible to associate some values with it, thus creating a C closure [see §3. 4]; these values are then accessible to the function whenever it is called. To associate values with a C function, first these values should be pushed onto the stack [when there are multiple values, the first value is pushed first]. Then

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
793 is called to create and push the C function onto the stack, with the argument
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 telling how many values should be associated with the function.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
793 also pops these values from the stack

The maximum value for

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 is 255

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
29

Pushes a C function onto the stack. This function receives a pointer to a C function and pushes onto the stack a Lua value of type

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440 that, when called, invokes the corresponding C function

Any function to be registered in Lua must follow the correct protocol to receive its parameters and return its results [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
785]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
442 is defined as a macro

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
30

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
31

Pushes onto the stack a formatted string and returns a pointer to this string. It is similar to the C function

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
443, but has some important differences

  • You do not have to allocate space for the result. the result is a Lua string and Lua takes care of memory allocation [and deallocation, through garbage collection]
  • The conversion specifiers are quite restricted. There are no flags, widths, or precisions. The conversion specifiers can only be '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    444' [inserts a '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    750' in the string], '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    446' [inserts a zero-terminated string, with no size restrictions], '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    447' [inserts a
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    448], '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    449' [inserts a pointer as a hexadecimal numeral], '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    450' [inserts an
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    451], and '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    452' [inserts an
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    451 as a character]

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
32

Pushes a number with value

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 onto the stack

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
33

Pushes a light userdata onto the stack

Userdata represent C values in Lua. A light userdata represents a pointer. It is a value [like a number]. you do not create it, it has no individual metatable, and it is not collected [as it was never created]. A light userdata is equal to "any" light userdata with the same C address

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
34

This macro is equivalent to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
455, but can be used only when
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 is a literal string. In these cases, it automatically provides the string length

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
35

Pushes the string pointed to by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 with size
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
458 onto the stack. Lua makes [or reuses] an internal copy of the given string, so the memory at
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 can be freed or reused immediately after the function returns. The string can contain embedded zeros

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
36

Pushes a nil value onto the stack

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
37

Pushes a number with value

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 onto the stack

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
38

Pushes the zero-terminated string pointed to by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 onto the stack. Lua makes [or reuses] an internal copy of the given string, so the memory at
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 can be freed or reused immediately after the function returns. Chuỗi không được chứa các số 0 được nhúng;

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
39

Đẩy chuỗi được đại diện bởi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
463 vào ngăn xếp. Trả về 1 nếu luồng này là luồng chính của trạng thái của nó

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
40

Pushes a copy of the element at the given valid index onto the stack

[-0, +1, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
41

Tương đương với

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
464, ngoại trừ việc nó nhận được một
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
465 thay vì một số đối số khác nhau

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
42

Returns 1 if the two values in acceptable indices

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
865 and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
866 are primitively equal [that is, without calling metamethods]. Otherwise returns 0. Cũng trả về 0 nếu bất kỳ chỉ số nào không hợp lệ

[-1, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
43

Similar to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
468, but does a raw access [i. e. , without metamethods]

[-0, +1, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
44

Đẩy vào ngăn xếp giá trị

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
770, trong đó
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 là giá trị tại chỉ mục hợp lệ đã cho. The access is raw; that is, it does not invoke metamethods

[-2, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
45

Similar to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
471, but does a raw assignment [i. e. , without metamethods]

[-1, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
46

Does the equivalent of

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
472, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 is the value at the given valid index and
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734 is the value at the top of the stack

This function pops the value from the stack. The assignment is raw; that is, it does not invoke metamethods

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
47

The reader function used by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896. Every time it needs another piece of the chunk,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 calls the reader, passing along its
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
864 parameter. The reader must return a pointer to a block of memory with a new piece of the chunk and set
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
478 to the block size. The block must exist until the reader function is called again. To signal the end of the chunk, the reader must return
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 or set
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
478 to zero. The reader function may return pieces of any size greater than zero

[-0, +0, e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
48

Sets the C function

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 as the new value of global
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888. It is defined as a macro

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
49

[-1, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
50

Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position

[-1, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
51

Moves the top element into the given position [and pops it], without shifting any element [therefore replacing the value at the given position]

[-?, +?, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
52

Starts and resumes a coroutine in a given thread

To start a coroutine, you first create a new thread [see

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
483]; then you push onto its stack the main function plus any arguments; then you call
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
484, with
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 being the number of arguments. This call returns when the coroutine suspends or finishes its execution. When it returns, the stack contains all values passed to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
486, or all values returned by the body function.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
484 returns
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
488 if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
710]. In case of errors, the stack is not unwound, so you can use the debug API over it. The error message is on the top of the stack. To restart a coroutine, you put on its stack only the values to be passed as results from
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
490, and then call
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
484

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
53

Changes the allocator function of a given state to

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 with user data
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
814

[-1, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
54

Pops a table from the stack and sets it as the new environment for the value at the given index. If the value at the given index is neither a function nor a thread nor a userdata,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
494 returns 0. Nếu không, nó trả về 1

[-1, +0, e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
55

Does the equivalent to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
495, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 is the value at the given valid index and
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734 is the value at the top of the stack

This function pops the value from the stack. Như trong Lua, hàm này có thể kích hoạt siêu phương thức cho sự kiện "newindex" [xem §2. 8]

[-1, +0, e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
56

Pops a value from the stack and sets it as the new value of global

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888. Nó được định nghĩa là một macro

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
57

[-1, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
58

Bật một bảng từ ngăn xếp và đặt nó làm bảng có thể chuyển đổi mới cho giá trị tại chỉ mục được chấp nhận đã cho

[-2, +0, e]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
59

Does the equivalent to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
495, where
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 is the value at the given valid index,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734 is the value at the top of the stack, and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
758 is the value just below the top

This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event [see §2. 8]

[-?, +?, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
60

Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903 is 0, then all stack elements are removed

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
61

Opaque structure that keeps the whole state of a Lua interpreter. The Lua library is fully reentrant. it has no global variables. All information about a state is kept in this structure

A pointer to this state must be passed as the first argument to every function in the library, except to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
815, which creates a Lua state from scratch

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
62

Returns the status of the thread

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
463

The status can be 0 for a normal thread, an error code if the thread finished its execution with an error, or

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
488 if the thread is suspended

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
63

Converts the Lua value at the given acceptable index to a C boolean value [0 or 1]. Like all tests in Lua,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
907 returns 1 for any Lua value different from false and nil; otherwise it returns 0. It also returns 0 when called with a non-valid index. [If you want to accept only actual boolean values, use
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
908 to test the value's type. ]

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
64

Converts a value at the given acceptable index to a C function. That value must be a C function; otherwise, returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
65

Converts the Lua value at the given acceptable index to the signed integral type

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
910. The Lua value must be a number or a string convertible to a number [see §2. 2. 1]; otherwise,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
911 returns 0

If the number is not an integer, it is truncated in some non-specified way

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
66

Converts the Lua value at the given acceptable index to a C string. If

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
458 is not
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, it also sets
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
914 with the string length. The Lua value must be a string or a number; otherwise, the function returns
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820. If the value is a number, then
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 also changes the actual value in the stack to a string. [This change confuses
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
411 when
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 is applied to keys during a table traversal. ]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 returns a fully aligned pointer to a string inside the Lua state. This string always has a zero ['
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
83'] after its last character [as in C], but can contain other zeros in its body. Because Lua has garbage collection, there is no guarantee that the pointer returned by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 will be valid after the corresponding value is removed from the stack

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
67

Converts the Lua value at the given acceptable index to the C type

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
448 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
448]. The Lua value must be a number or a string convertible to a number [see §2. 2. 1]; otherwise,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
924 returns 0

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
68

Converts the value at the given acceptable index to a generic C pointer [

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
925]. The value can be a userdata, a table, a thread, or a function; otherwise,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
926 returns
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820. Different objects will give different pointers. There is no way to convert the pointer back to its original value

Typically this function is used only for debug information

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
69

Equivalent to

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 with
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
458 equal to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
70

Converts the value at the given acceptable index to a Lua thread [represented as

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
931]. This value must be a thread; otherwise, the function returns
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
71

If the value at the given acceptable index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
72

Returns the type of the value in the given acceptable index, or

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
934 for a non-valid index [that is, an index to an "empty" stack position]. The types returned by
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
935 are coded by the following constants defined in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
782.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
937,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
938,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
939,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
940,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
941,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
942,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
943,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
944 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
945

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
73

Trả về tên của loại được mã hóa bởi giá trị

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
946, giá trị này phải là một trong những giá trị được trả về bởi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
935

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
74

Loại hàm ghi được sử dụng bởi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
861. Mỗi khi nó tạo ra một đoạn mã khác,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
861 gọi bộ ghi, chuyển bộ đệm được ghi [
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
803], kích thước của nó [
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
951] và tham số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
864 được cung cấp cho
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
861

Người viết trả về một mã lỗi. 0 có nghĩa là không có lỗi;

[-?, +?, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
75

Trao đổi giá trị giữa các luồng khác nhau của cùng một trạng thái toàn cầu

Hàm này bật các giá trị

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 từ ngăn xếp
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
956 và đẩy chúng vào ngăn xếp
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
957

[-?, +?, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
76

Yields a coroutine

This function should only be called as the return expression of a C function, as follows

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
77

When a C function calls

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
486 in that way, the running coroutine suspends its execution, and the call to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
484 that started this coroutine returns. The parameter
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
842 is the number of values from the stack that are passed as results to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
484

Lua has no built-in debugging facilities. Thay vào đó, nó cung cấp một giao diện đặc biệt bằng các chức năng và hook. This interface allows the construction of different kinds of debuggers, profilers, and other tools that need "inside information" from the interpreter

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
78

A structure used to carry different pieces of information about an active function.

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
962 fills only the private part of this structure, for later use. To fill the other fields of
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
963 with useful information, call
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
964

The fields of

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
963 have the following meaning

  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    966. If the function was defined in a string, then
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    966 is that string. If the function was defined in a file, then
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    966 starts with a '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    969' followed by the file name
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    970. a "printable" version of
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    966, to be used in error messages
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    972. the line number where the definition of the function starts
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    973. the line number where the definition of the function ends
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    869. the string
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    975 if the function is a Lua function,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    976 if it is a C function,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    977 if it is the main part of a chunk, and
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    978 if it was a function that did a tail call. In the latter case, Lua has no other information about the function
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    979. the current line where the given function is executing. When no line information is available,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    979 is set to -1
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    888. a reasonable name for the given function. Because functions in Lua are first-class values, they do not have a fixed name. some functions can be the value of multiple global variables, while others can be stored only in a table field. The
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    964 function checks how the function was called to find a suitable name. If it cannot find a name, then
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    888 is set to
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    820
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    985. explains the
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    888 field. The value of
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    985 can be
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    988,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    989,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    990,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    991,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    992, or
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    993 [the empty string], according to how the function was called. [Lua uses the empty string when no other option seems to apply. ]
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    994. the number of upvalues of the function

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
79

Returns the current hook function

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
80

Returns the current hook count

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
81

Returns the current hook mask

[-[0. 1], +[0. 1. 2], m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
82

Returns information about a specific function or function invocation

To get information about a function invocation, the parameter

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995 must be a valid activation record that was filled by a previous call to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
962 or given as argument to a hook [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
997]

To get information about a function you push it onto the stack and start the

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869 string with the character '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
999'. [In that case,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
964 pops the function in the top of the stack. ] For instance, to know in which line a function
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 was defined, you can write the following code

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
83

Each character in the string

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869 selects some fields of the structure
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995 to be filled or a value to be pushed on the stack

  • '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    769'. fills in the field
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    888 and
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    985;
  • '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    307'. fills in the fields
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    966,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    970,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    972,
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    973, and
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    869;
  • '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    313'. fills in the field
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    979;
  • '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    315'. fills in the field
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    994;
  • '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    742'. đẩy vào ngăn xếp chức năng đang chạy ở mức nhất định;
  • '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    463'. pushes onto the stack a table whose indices are the numbers of the lines that are valid on the function. [A valid line is a line with some associated code, that is, a line where you can put a break point. Các dòng không hợp lệ bao gồm các dòng trống và nhận xét. ]

This function returns 0 on error [for instance, an invalid option in

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869]

[-0, +[0. 1], -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
84

Gets information about a local variable of a given activation record. The parameter

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995 must be a valid activation record that was filled by a previous call to
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
962 or given as argument to a hook [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
997]. The index
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 selects which local variable to inspect [1 is the first parameter or active local variable, and so on, until the last active local variable].
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
324 đẩy giá trị của biến vào ngăn xếp và trả về tên của nó

Variable names starting with '

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
797' [open parentheses] represent internal variables [loop control variables, temporaries, and C function locals]

Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 [and pushes nothing] when the index is greater than the number of active local variables

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
85

Get information about the interpreter runtime stack

This function fills parts of a

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
963 structure with an identification of the activation record of the function executing at a given level. Level 0 is the current running function, whereas level n+1 is the function that has called level n. When there are no errors,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
962 returns 1; when called with a level greater than the stack depth, it returns 0

[-0, +[0. 1], -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
86

Gets information about a closure's upvalue. [For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure. ]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
329 gets the index
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 of an upvalue, pushes the upvalue's value onto the stack, and returns its name.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
331 points to the closure in the stack. [Upvalues have no particular order, as they are active through the whole function. So, they are numbered in an arbitrary order. ]

Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 [and pushes nothing] when the index is greater than the number of upvalues. For C functions, this function uses the empty string
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
993 as a name for all upvalues

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
87

Type for debugging hook functions

Whenever a hook is called, its

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995 argument has its field
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
335 set to the specific event that triggered the hook. Lua identifies these events with the following constants.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
336,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
337,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
338,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
339, and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
340. Moreover, for line events, the field
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
979 is also set. To get the value of any other field in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995, the hook must call
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
964. Đối với các sự kiện trả lại,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
335 có thể là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
337, giá trị bình thường hoặc
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
338. In the latter case, Lua is simulating a return from a function that did a tail call; in this case, it is useless to call
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
964

While Lua is running a hook, it disables other calls to hooks. Therefore, if a hook calls back Lua to execute a function or a chunk, this execution occurs without any calls to hooks

[-0, +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
88

Sets the debugging hook function

Argument

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 is the hook function.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
349 specifies on which events the hook will be called. it is formed by a bitwise or of the constants
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
350,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
351,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
352, and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
353. The
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
354 argument is only meaningful when the mask includes
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
353. For each event, the hook is called as explained below

  • The call hook. is called when the interpreter calls a function. The hook is called just after Lua enters the new function, before the function gets its arguments
  • The return hook. is called when the interpreter returns from a function. The hook is called just before Lua leaves the function. You have no access to the values to be returned by the function
  • The line hook. is called when the interpreter is about to start the execution of a new line of code, or when it jumps back in the code [even to the same line]. [This event only happens while Lua is executing a Lua function. ]
  • The count hook. is called after the interpreter executes every
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    354 instructions. [This event only happens while Lua is executing a Lua function. ]

A hook is disabled by setting

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
349 to zero

[-[0. 1], +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
89

Sets the value of a local variable of a given activation record. Parameters

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
995 and
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 are as in
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
324 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
324].
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
362 assigns the value at the top of the stack to the variable and returns its name. It also pops the value from the stack

Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 [and pops nothing] when the index is greater than the number of active local variables

[-[0. 1], +0, -]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
90

Sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack. Parameters

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
331 and
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 are as in the
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
329 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
329]

Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 [and pops nothing] when the index is greater than the number of upvalues

The auxiliary library provides several convenient functions to interface C with Lua. While the basic API provides the primitive functions for all interactions between C and Lua, the auxiliary library provides higher-level functions for some common tasks

All functions from the auxiliary library are defined in header file

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
369 and have a prefix
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
370

All functions in the auxiliary library are built on top of the basic API, and so they provide nothing that cannot be done with this API

Một số hàm trong thư viện phụ trợ được sử dụng để kiểm tra đối số hàm C. Their names are always

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
371 or
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
372. All of these functions throw an error if the check is not satisfied. Because the error message is formatted for arguments [e. g. , "
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
373"], you should not use these functions for other stack values

Here we list all functions and types from the auxiliary library in alphabetical order

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
91

Adds the character

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
374 to the buffer
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
92

Adds the string pointed to by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 with length
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
313 to the buffer
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]. The string may contain embedded zeros

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
93

Adds to the buffer

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376] a string of length
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 previously copied to the buffer area [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
384]

[-0, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
94

Adds the zero-terminated string pointed to by

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 to the buffer
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]. The string may not contain embedded zeros

[-1, +0, m]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
95

Adds the value at the top of the stack to the buffer

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]. Pops the value

This is the only function on string buffers that can [and must] be called with an extra element on the stack, which is the value to be added to the buffer

[-0, +0, v]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
96

Checks whether

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
390 is true. If not, raises an error with the following message, where
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 is retrieved from the call stack

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
97

[-0, +0, v]

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
98

Raises an error with the following message, where

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 is retrieved from the call stack

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
97

This function never returns, but it is an idiom to use it in C functions as

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
393

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
00

Type for a string buffer

Bộ đệm chuỗi cho phép mã C xây dựng chuỗi Lua từng phần. Mô hình sử dụng của nó như sau

  • Đầu tiên bạn khai báo một biến
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    435 kiểu
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    376
  • Sau đó, bạn khởi tạo nó bằng một cuộc gọi
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    396
  • Sau đó, bạn thêm các đoạn chuỗi vào bộ đệm gọi bất kỳ hàm
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    397 nào
  • You finish by calling
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    398. This call leaves the final string on the top of the stack

During its normal operation, a string buffer uses a variable number of stack slots. So, while using a buffer, you cannot assume that you know where the top of the stack is. You can use the stack between successive calls to buffer operations as long as that use is balanced; that is, when you call a buffer operation, the stack is at the same level it was immediately after the previous buffer operation. [The only exception to this rule is

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
399. ] After calling
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
600 the stack is back to its level when the buffer was initialized, plus the final string on its top

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
01

Initializes a buffer

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375. This function does not allocate any space; the buffer must be declared as a variable [see
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]

[-0, +[0. 1], e]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
02

Calls a metamethod

If the object at index

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603 has a metatable and this metatable has a field
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811, this function calls this field and passes the object as its only argument. Trong trường hợp này, hàm này trả về 1 và đẩy vào ngăn xếp giá trị được trả về bởi lệnh gọi. If there is no metatable or no metamethod, this function returns 0 [without pushing any value on the stack]

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
03

Checks whether the function has an argument of any type [including nil] at position

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
04

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một số hay không và trả về số này được truyền cho một
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
451

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
05

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một số hay không và trả về số này được chuyển thành một
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
910

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
06

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một số hay không và trả về số này được truyền cho một
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
611

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
07

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một chuỗi hay không và trả về chuỗi này;

Hàm này sử dụng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 để nhận kết quả, vì vậy tất cả chuyển đổi và cảnh báo của hàm đó sẽ áp dụng tại đây

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
08

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một số hay không và trả về số này

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
09

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một chuỗi hay không và tìm kiếm chuỗi này trong mảng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
619 [phải được kết thúc bằng NULL]. Trả về chỉ mục trong mảng nơi tìm thấy chuỗi. Raises an error if the argument is not a string or if the string cannot be found

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
620 không phải là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, thì hàm sử dụng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
620 làm giá trị mặc định khi không có đối số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 hoặc nếu đối số này bằng không

Đây là một hàm hữu ích để ánh xạ chuỗi tới C enums. [Quy ước thông thường trong các thư viện Lua là sử dụng chuỗi thay vì số để chọn tùy chọn. ]

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
10

Tăng kích thước ngăn xếp lên

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
624 phần tử, gây ra lỗi nếu ngăn xếp không thể tăng đến kích thước đó.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
625 là một văn bản bổ sung để đi vào thông báo lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
11

Kiểm tra xem đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là một chuỗi hay không và trả về chuỗi này

Hàm này sử dụng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
412 để nhận kết quả, vì vậy tất cả chuyển đổi và cảnh báo của hàm đó sẽ áp dụng tại đây

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
12

Kiểm tra xem đối số hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có loại
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 không. Xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
935 để biết cách mã hóa các loại cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
13

Kiểm tra xem đối số hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 có phải là dữ liệu người dùng thuộc loại
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
633 hay không [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
634]

[-0, +?, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
14

Tải và chạy tệp đã cho. It is defined as the following macro

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
15

Nó trả về 0 nếu không có lỗi hoặc 1 trong trường hợp có lỗi

[-0, +?, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
16

Tải và chạy chuỗi đã cho. Nó được định nghĩa là macro sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
17

Nó trả về 0 nếu không có lỗi hoặc 1 trong trường hợp có lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
18

Tăng một lỗi. Định dạng thông báo lỗi được cung cấp bởi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
635 cộng với bất kỳ đối số bổ sung nào, tuân theo các quy tắc tương tự của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
464. Nó cũng thêm vào đầu thông báo tên tệp và số dòng xảy ra lỗi, nếu thông tin này có sẵn

Hàm này không bao giờ trả về, nhưng nó là một thành ngữ để sử dụng nó trong các hàm C như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
637

[-0, +[0. 1], m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
19

Đẩy vào ngăn xếp trường

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 từ metatable của đối tượng tại chỉ mục
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603. Nếu đối tượng không có metatable hoặc nếu metatable không có trường này, trả về 0 và không đẩy gì

[-0, +1, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
20

Đẩy vào ngăn xếp metatable được liên kết với tên

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
633 trong sổ đăng ký [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
634]

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
21

Tạo một bản sao của chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 bằng cách thay thế bất kỳ lần xuất hiện nào của chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
803 bằng chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
644. Đẩy chuỗi kết quả vào ngăn xếp và trả về nó

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
22

Tải bộ đệm dưới dạng đoạn Lua. Hàm này sử dụng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 để tải đoạn trong bộ đệm được chỉ định bởi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
646 với kích thước
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
951

Hàm này trả về kết quả tương tự như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 là tên đoạn, được sử dụng cho thông tin gỡ lỗi và thông báo lỗi

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
23

Tải một tập tin dưới dạng Lua chunk. Hàm này sử dụng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 để tải đoạn trong tệp có tên
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
651. Nếu
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
651 là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, thì nó sẽ tải từ đầu vào tiêu chuẩn. Dòng đầu tiên trong tệp bị bỏ qua nếu nó bắt đầu bằng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
767

Hàm này trả về kết quả giống như hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 nhưng có thêm mã lỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
656 nếu không thể mở/đọc tệp

As

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896, this function only loads the chunk; it does not run it

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
24

Tải một chuỗi dưới dạng một đoạn Lua. Hàm này sử dụng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896 để tải đoạn mã trong chuỗi có đầu cuối bằng 0
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456

Hàm này trả về kết quả tương tự như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896

Cũng như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
896, hàm này chỉ tải đoạn dữ liệu;

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
25

Nếu sổ đăng ký đã có khóa

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
633, trả về 0. Nếu không, hãy tạo một bảng mới để sử dụng làm bảng siêu dữ liệu cho dữ liệu người dùng, thêm bảng đó vào sổ đăng ký bằng khóa
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
633 và trả về 1

Trong cả hai trường hợp, đẩy vào ngăn xếp giá trị cuối cùng được liên kết với

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
633 trong sổ đăng ký

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
26

Tạo một trạng thái Lua mới. Nó gọi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
815 bằng một bộ cấp phát dựa trên hàm C
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
813 tiêu chuẩn, sau đó đặt một hàm hoảng loạn [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
667] để in thông báo lỗi ra đầu ra lỗi tiêu chuẩn trong trường hợp xảy ra lỗi nghiêm trọng

Trả về trạng thái mới hoặc

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820 nếu có lỗi cấp phát bộ nhớ

[-0, +0, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
27

Mở tất cả các thư viện Lua tiêu chuẩn vào trạng thái nhất định

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
28

Nếu đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 là một số, trả về số này chuyển thành một số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
451. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
29

Nếu đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 là một số, trả về số này chuyển thành một số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
910. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
30

Nếu đối số của hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 là một số, trả về số này được chuyển thành một số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
611. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
31

If the function argument

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 is a string, returns this string. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
313 không phải là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, điền vào vị trí
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
615 với độ dài của kết quả

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
32

Nếu đối số hàm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 là một số, trả về số này. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
33

If the function argument

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
485 is a string, returns this string. Nếu đối số này vắng mặt hoặc không, trả về
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671. Mặt khác, gây ra lỗi

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
34

Trả về một địa chỉ cho một không gian có kích thước

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
687 nơi bạn có thể sao chép một chuỗi sẽ được thêm vào bộ đệm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
376]. Sau khi sao chép chuỗi vào không gian này, bạn phải gọi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
690 với kích thước của chuỗi để thực sự thêm nó vào bộ đệm

[-?, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
35

Kết thúc việc sử dụng bộ đệm

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
375 để lại chuỗi cuối cùng ở trên cùng của ngăn xếp

[-1, +0, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
36

Tạo và trả về một tham chiếu, trong bảng tại chỉ mục

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768, cho đối tượng ở đầu ngăn xếp [và bật đối tượng]

A reference is a unique integer key. Miễn là bạn không tự thêm các khóa số nguyên vào bảng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768, thì
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
694 đảm bảo tính duy nhất của khóa mà nó trả về. Bạn có thể truy xuất một đối tượng được gọi bằng tham chiếu
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
644 bằng cách gọi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
696. Hàm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
697 giải phóng một tham chiếu và đối tượng liên quan của nó

Nếu đối tượng ở trên cùng của ngăn xếp là không, thì

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
694 trả về hằng số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
699. Hằng số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
000 được đảm bảo khác với bất kỳ tham chiếu nào được trả về bởi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
694

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
37

Nhập các mảng chức năng được đăng ký bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
002.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 là tên hàm và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 là con trỏ tới hàm. Bất kỳ mảng nào của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
005 đều phải kết thúc bằng một mục nhập canh gác trong đó cả
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 đều là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820

[-[0. 1], +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
38

Mở một thư viện

Khi được gọi với

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009 bằng với
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
820, nó chỉ cần đăng ký tất cả các chức năng trong danh sách
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
313 [xem
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
005] vào bảng trên cùng của ngăn xếp

Khi được gọi với một giá trị khác null

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
002 tạo một bảng mới
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768, đặt nó làm giá trị của biến toàn cục
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009, đặt nó làm giá trị của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
017 và đăng ký tất cả các hàm trong danh sách
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
313 trên đó. Nếu có một bảng trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
017 hoặc trong biến
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009, hãy sử dụng lại bảng này thay vì tạo một bảng mới

Trong mọi trường hợp, hàm rời khỏi bảng trên đỉnh ngăn xếp

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
39

Returns the name of the type of the value at the given index

[-0, +0, v]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
40

Tạo lỗi với thông báo như sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
41

trong đó

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
021 được tạo bởi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
022,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
023 là tên của hàm hiện tại và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
024 là tên loại của đối số thực tế

[-0, +0, -]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
42

Phát hành tài liệu tham khảo

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
025 từ bảng tại chỉ mục
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
694]. Mục nhập được xóa khỏi bảng để có thể thu thập đối tượng được giới thiệu. Tài liệu tham khảo
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
025 cũng được giải phóng để sử dụng lại

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
025 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
000 hoặc
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
699, thì
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
697 không làm gì cả

[-0, +1, m]

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
43

Đẩy vào ngăn xếp một chuỗi xác định vị trí hiện tại của điều khiển ở cấp độ

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
033 trong ngăn xếp cuộc gọi. Thông thường chuỗi này có định dạng sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
44

Cấp 0 là chức năng đang chạy, cấp 1 là chức năng được gọi là chức năng đang chạy, v.v.

Chức năng này được sử dụng để tạo tiền tố cho các thông báo lỗi

Các thư viện Lua tiêu chuẩn cung cấp các chức năng hữu ích được triển khai trực tiếp thông qua C API. Some of these functions provide essential services to the language [e. g. ,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
96 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
715]; . g. , vào/ra]; . g. ,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
036]

Tất cả các thư viện đều được triển khai thông qua C API chính thức và được cung cấp dưới dạng các mô-đun C riêng biệt. Hiện tại Lua có các thư viện chuẩn sau

  • thư viện cơ bản, bao gồm thư viện con coroutine;
  • thư viện gói;
  • thao tác chuỗi;
  • table manipulation;
  • các hàm toán học [sin, log, v.v. ];
  • đầu vào và đầu ra;
  • điều hành hệ thống cơ sở vật chất;
  • cơ sở gỡ lỗi

Ngoại trừ các thư viện cơ bản và gói, mỗi thư viện cung cấp tất cả các chức năng của nó dưới dạng các trường của bảng toàn cục hoặc dưới dạng phương thức của các đối tượng của nó

Để có quyền truy cập vào các thư viện này, chương trình lưu trữ C phải gọi hàm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
037 để mở tất cả các thư viện tiêu chuẩn. Ngoài ra, nó có thể mở chúng riêng lẻ bằng cách gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
038 [đối với thư viện cơ bản],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
039 [đối với thư viện gói],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
040 [đối với thư viện chuỗi],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
041 [đối với thư viện bảng],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
042 [đối với thư viện toán học],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
043 . Các hàm này được khai báo trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
046 và không được gọi trực tiếp. bạn phải gọi chúng giống như bất kỳ hàm Lua C nào khác, e. g. , by using
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
840

The basic library provides some core functions to Lua. If you do not include this library in your application, you should check carefully whether you need to provide implementations for some of its facilities

Phát sinh lỗi khi giá trị đối số của nó là
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
734 sai [i. e. , không hoặc sai]; .
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
049 là một thông báo lỗi; . "

Chức năng này là một giao diện chung cho bộ thu gom rác. Nó thực hiện các chức năng khác nhau theo đối số đầu tiên của nó,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
050

  • "sưu tầm". thực hiện một chu kỳ thu gom rác đầy đủ. Đây là tùy chọn mặc định
  • "dừng lại". dừng bộ thu gom rác
  • "khởi động lại". khởi động lại bộ thu gom rác
  • "đếm". trả về tổng bộ nhớ đang được Lua sử dụng [tính bằng Kbyte]
  • "bước chân". thực hiện một bước thu gom rác. "Kích thước" của bước được kiểm soát bởi
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    051 [giá trị lớn hơn có nghĩa là nhiều bước hơn] theo cách không được chỉ định. Nếu bạn muốn kiểm soát kích thước bước, bạn phải điều chỉnh bằng thực nghiệm giá trị của
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    051. Returns true if the step finished a collection cycle
  • "setpause". đặt
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    051 làm giá trị mới cho việc tạm dừng bộ thu [xem §2. 10]. Trả về giá trị tạm dừng trước đó
  • "setstepmul". đặt
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    051 làm giá trị mới cho hệ số nhân bước của bộ thu [xem §2. 10]. Trả về giá trị trước đó cho bước
Mở tệp được đặt tên và thực thi nội dung của nó dưới dạng đoạn Lua. Khi được gọi mà không có đối số,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
055 thực thi nội dung của đầu vào tiêu chuẩn [
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
056]. Trả về tất cả các giá trị được trả về bởi chunk. Trong trường hợp có lỗi,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
055 sẽ truyền lỗi cho người gọi của nó [nghĩa là,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
055 không chạy ở chế độ được bảo vệ]Chấm dứt chức năng được bảo vệ cuối cùng được gọi và trả về
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
049 dưới dạng thông báo lỗi. Hàm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
711 không bao giờ trả về

Thông thường,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
711 thêm một số thông tin về vị trí lỗi ở đầu tin nhắn. Đối số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062 chỉ định cách lấy vị trí lỗi. Với cấp 1 [mặc định], vị trí lỗi là nơi hàm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
711 được gọi. Cấp 2 chỉ ra lỗi ở vị trí gọi hàm có tên là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
711; . Passing a level 0 avoids the addition of error position information to the message

Biến toàn cục [không phải hàm] chứa môi trường toàn cầu [tức là,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
065]. Bản thân Lua không sử dụng biến này; . [Sử dụng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705 để thay đổi môi trường. ]Trả về môi trường hiện tại đang được hàm sử dụng.
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 có thể là một hàm Lua hoặc một số chỉ định hàm ở cấp độ ngăn xếp đó. Cấp 1 là chức năng gọi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
704. Nếu hàm đã cho không phải là hàm Lua hoặc nếu
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 bằng 0, thì
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
704 trả về môi trường chung. Giá trị mặc định cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 là 1

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
072 không có metatable, trả về nil. Mặt khác, nếu metatable của đối tượng có trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
073, trả về giá trị được liên kết. Mặt khác, trả về metatable của đối tượng đã cho

Trả về ba giá trị. một hàm lặp, bảng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 và 0, để việc xây dựng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
45

sẽ lặp qua các cặp [

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
075], [
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
076], ···, cho đến khóa số nguyên đầu tiên không có trong bảng

Tải một đoạn sử dụng chức năng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 để lấy các phần của nó. Mỗi cuộc gọi đến
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 phải trả về một chuỗi nối với các kết quả trước đó. A return of an empty string, nil, or no value signals the end of the chunk

If there are no errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message. Môi trường của hàm trả về là môi trường toàn cầu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
404 được sử dụng làm tên đoạn cho thông báo lỗi và thông tin gỡ lỗi. Khi vắng mặt, nó mặc định là "______7080"

Tương tự như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
750, nhưng lấy đoạn từ tệp
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
651 hoặc từ đầu vào tiêu chuẩn, nếu không có tên tệp nào được cung cấp

Tương tự như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
750, nhưng lấy đoạn từ chuỗi đã cho

Để tải và chạy một chuỗi nhất định, hãy sử dụng thành ngữ

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
46

Khi vắng mặt,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
404 mặc định là chuỗi đã cho

Cho phép chương trình duyệt qua tất cả các trường của bảng. Đối số đầu tiên của nó là một bảng và đối số thứ hai của nó là một chỉ mục trong bảng này.

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085 trả về chỉ mục tiếp theo của bảng và giá trị được liên kết của nó. Khi được gọi với nil làm đối số thứ hai,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085 trả về một chỉ mục ban đầu và giá trị liên quan của nó. Khi được gọi với chỉ mục cuối cùng hoặc với nil trong một bảng trống,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085 trả về nil. Nếu đối số thứ hai vắng mặt, thì nó được hiểu là không. Đặc biệt, bạn có thể sử dụng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
088 để kiểm tra xem một bảng có trống không

Thứ tự mà các chỉ số được liệt kê không được chỉ định, ngay cả đối với các chỉ số số. [Để duyệt qua một bảng theo thứ tự số, hãy sử dụng một số cho hoặc hàm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
089. ]

The behavior of

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085 is undefined if, during the traversal, you assign any value to a non-existent field in the table. Tuy nhiên, bạn có thể sửa đổi các trường hiện có. Cụ thể, bạn có thể xóa các trường hiện có

Trả về ba giá trị. hàm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085, bảng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 và nil, do đó việc xây dựng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
47

sẽ lặp qua tất cả các cặp khóa-giá trị của bảng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768

Xem chức năng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
085 để biết trước việc sửa đổi bảng trong quá trình truyền tải

Gọi hàm

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 với các đối số đã cho ở chế độ được bảo vệ. Điều này có nghĩa là bất kỳ lỗi nào bên trong
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 đều không được lan truyền; . Kết quả đầu tiên của nó là mã trạng thái [boolean], điều này đúng nếu cuộc gọi thành công mà không có lỗi. Trong trường hợp như vậy,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
712 cũng trả về tất cả kết quả từ cuộc gọi, sau kết quả đầu tiên này. Trong trường hợp có bất kỳ lỗi nào,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
712 trả về false cộng với thông báo lỗi

Nhận bất kỳ số lượng đối số nào và in các giá trị của chúng thành
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
100, sử dụng hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
101 để chuyển đổi chúng thành chuỗi.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
102 không dành cho đầu ra được định dạng mà chỉ là một cách nhanh chóng để hiển thị một giá trị, thường là để gỡ lỗi. Đối với đầu ra được định dạng, hãy sử dụng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
98Kiểm tra xem
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
104 có bằng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
105 hay không mà không cần gọi bất kỳ siêu phương thức nào. Trả về một booleanNhận giá trị thực của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
106 mà không cần gọi bất kỳ siêu dữ liệu nào.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107 must be a table;
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903 may be any valueĐặt giá trị thực của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
106 thành
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
110 mà không cần gọi bất kỳ siêu dữ liệu nào.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107 phải là một bảng,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903 bất kỳ giá trị nào khác với nil và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
110 bất kỳ giá trị Lua nào

Hàm này trả về

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903 là một số, trả về tất cả các đối số sau số đối số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903. Mặt khác,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
903 phải là chuỗi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
118 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
119 trả về tổng số đối số bổ sung mà nó nhận được

Đặt môi trường được sử dụng bởi hàm đã cho.

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 có thể là một hàm Lua hoặc một số chỉ định hàm ở cấp độ ngăn xếp đó. Cấp 1 là chức năng gọi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705.
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705 trả về hàm đã cho

Trong trường hợp đặc biệt, khi

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 bằng 0 thì
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705 sẽ thay đổi môi trường của luồng đang chạy. Trong trường hợp này,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
705 không trả về giá trị nào

Đặt metatable cho bảng đã cho. [Bạn không thể thay đổi metatable của các loại khác từ Lua, chỉ từ C. ] Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
126 bằng 0, hãy xóa metatable của bảng đã cho. Nếu metatable ban đầu có trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
073, sẽ phát sinh lỗi

Hàm này trả về

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107

Cố gắng chuyển đổi đối số của nó thành một số. If the argument is already a number or a string convertible to a number, then
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
720 returns this number; otherwise, it returns nil

Một đối số tùy chọn chỉ định cơ sở để diễn giải số. Cơ sở có thể là bất kỳ số nguyên nào trong khoảng từ 2 đến 36, bao gồm cả. Trong các cơ sở trên 10, chữ cái '

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
130' [viết hoa hoặc viết thường] đại diện cho 10, '_______5375' đại diện cho 11, v.v., với '
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
132' đại diện cho 35. Trong cơ số 10 [mặc định], số có thể có phần thập phân, cũng như phần số mũ tùy chọn [xem §2. 1]. Trong các cơ sở khác, chỉ các số nguyên không dấu được chấp nhận

Nhận một đối số thuộc bất kỳ loại nào và chuyển đổi nó thành một chuỗi ở định dạng hợp lý. Để kiểm soát hoàn toàn cách các số được chuyển đổi, hãy sử dụng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
98

Nếu siêu dữ liệu của

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 có trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
135, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
101 gọi giá trị tương ứng với đối số là
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 và sử dụng kết quả của lệnh gọi làm kết quả

Trả về loại đối số duy nhất của nó, được mã hóa dưới dạng một chuỗi. Các kết quả có thể có của hàm này là "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
138" [một chuỗi, không phải giá trị nil], "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
139", "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
140", "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
141", "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107", "
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440", "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
144" và "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
145"Trả về các phần tử từ bảng đã cho. Hàm này tương đương với
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
48

ngoại trừ đoạn mã trên chỉ có thể được viết cho một số phần tử cố định. Theo mặc định,

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 là 1 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147 là độ dài của danh sách, như được xác định bởi toán tử độ dài [xem §2. 5. 5]

A global variable [not a function] that holds a string containing the current interpreter version. Nội dung hiện tại của biến này là "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
148"

Chức năng này tương tự như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
712, ngoại trừ việc bạn có thể đặt trình xử lý lỗi mới

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
150 gọi hàm
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 ở chế độ được bảo vệ, sử dụng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
152 làm trình xử lý lỗi. Bất kỳ lỗi nào bên trong
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 đều không được lan truyền; . Kết quả đầu tiên của nó là mã trạng thái [boolean], điều này đúng nếu cuộc gọi thành công mà không có lỗi. Trong trường hợp này,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
150 cũng trả về tất cả các kết quả từ cuộc gọi, sau kết quả đầu tiên này. Trong trường hợp có bất kỳ lỗi nào,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
150 trả về false cộng với kết quả từ
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
152

Các hoạt động liên quan đến coroutines bao gồm một thư viện con của thư viện cơ bản và nằm trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
159. Xem §2. 11 để biết mô tả chung về coroutines

Tạo một coroutine mới, với phần thân

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742.
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 phải là một hàm Lua. Trả về coroutine mới này, một đối tượng có loại
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
162

Bắt đầu hoặc tiếp tục thực thi quy trình đăng quang

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
163. Lần đầu tiên bạn tiếp tục một coroutine, nó sẽ bắt đầu chạy phần thân của nó. Các giá trị
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
164, ··· được truyền dưới dạng đối số cho hàm body. Nếu quy trình đăng ký đã mang lại kết quả,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165 sẽ khởi động lại nó;

Nếu coroutine chạy mà không có bất kỳ lỗi nào,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165 trả về true cộng với bất kỳ giá trị nào được chuyển đến
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
490 [nếu coroutine mang lại lợi nhuận] hoặc bất kỳ giá trị nào được trả về bởi hàm body [nếu coroutine kết thúc]. If there is any error,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165 returns false plus the error message

Trả về coroutine đang chạy hoặc nil khi được gọi bởi luồng chính

Trả về trạng thái của quy trình đăng ký

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
163, dưới dạng một chuỗi.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
171, nếu coroutine đang chạy [tức là, nó được gọi là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
172];

Tạo một coroutine mới, với phần thân

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742.
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742 phải là một hàm Lua. Trả về một chức năng tiếp tục coroutine mỗi khi nó được gọi. Bất kỳ đối số nào được chuyển đến hàm sẽ hoạt động như các đối số phụ cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165. Trả về các giá trị tương tự được trả về bởi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165, ngoại trừ giá trị boolean đầu tiên. Trong trường hợp có lỗi, lan truyền lỗi

Đình chỉ việc thực hiện cuộc gọi coroutine. Coroutine không được chạy hàm C, metamethod hoặc iterator. Bất kỳ đối số nào đối với

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
490 đều được chuyển dưới dạng kết quả bổ sung cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
165

Thư viện gói cung cấp các phương tiện cơ bản để tải và xây dựng các mô-đun trong Lua. Nó xuất hai chức năng của nó trực tiếp trong môi trường toàn cầu.

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 and
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184. Mọi thứ khác được xuất trong một bảng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
185

Tạo một mô-đun. Nếu có một bảng trong

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
186, thì bảng này là mô-đun. Otherwise, if there is a global table
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 with the given name, this table is the module. Otherwise creates a new table
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 and sets it as the value of the global
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 and the value of
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
186. Hàm này cũng khởi tạo
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
191 với tên đã cho,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
192 với mô-đun [chính
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768] và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
194 với tên gói [tên đầy đủ của mô-đun trừ đi thành phần cuối cùng; xem bên dưới]. Cuối cùng,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184 đặt
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768 làm môi trường mới của hàm hiện tại và giá trị mới của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
186, để
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 trả về
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 là một tên ghép [nghĩa là một tên có các thành phần được phân tách bằng dấu chấm], thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184 sẽ tạo [hoặc sử dụng lại, nếu chúng đã tồn tại] bảng cho từng thành phần. Chẳng hạn, nếu
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
888 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
203, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184 lưu bảng mô-đun trong trường
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
374 của trường
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
435 của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
87 toàn cầu

Chức năng này có thể nhận các tùy chọn tùy chọn sau tên mô-đun, trong đó mỗi tùy chọn là một chức năng được áp dụng trên mô-đun

Tải mô-đun đã cho. Hàm bắt đầu bằng cách xem bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
208 để xác định xem
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
209 đã được tải chưa. Nếu đúng như vậy, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 trả về giá trị được lưu trữ tại
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
211. Mặt khác, nó sẽ cố gắng tìm một trình tải cho mô-đun

Để tìm bộ tải,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 được hướng dẫn bởi mảng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
213. By changing this array, we can change how
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 looks for a module. Giải thích sau đây dựa trên cấu hình mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
213

Truy vấn

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 đầu tiên
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
217. Nếu nó có một giá trị, thì giá trị này [phải là một hàm] là trình tải. Mặt khác,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 tìm kiếm trình tải Lua bằng đường dẫn được lưu trữ trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
219. Nếu điều đó cũng không thành công, nó sẽ tìm kiếm trình tải C bằng đường dẫn được lưu trữ trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
220. Nếu điều đó cũng không thành công, nó sẽ thử trình tải tất cả trong một [xem
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
213]

Sau khi tìm thấy trình tải,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 gọi trình tải bằng một đối số duy nhất,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
209. Nếu bộ nạp trả về bất kỳ giá trị nào, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 sẽ gán giá trị được trả về cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
211. Nếu trình tải không trả về giá trị nào và chưa gán bất kỳ giá trị nào cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
211, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 sẽ gán true cho mục nhập này. Trong mọi trường hợp,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 trả về giá trị cuối cùng của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
211

Nếu có bất kỳ lỗi nào khi tải hoặc chạy mô-đun hoặc nếu nó không thể tìm thấy bất kỳ trình tải nào cho mô-đun, thì

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 báo hiệu lỗi

Đường dẫn được sử dụng bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 để tìm kiếm trình tải C

Lua khởi tạo đường dẫn C

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
220 giống như cách nó khởi tạo đường dẫn Lua
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
219, sử dụng biến môi trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
234 hoặc đường dẫn mặc định được xác định trong
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92

Một bảng được sử dụng bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 để kiểm soát những mô-đun nào đã được tải. Khi bạn yêu cầu một mô-đun
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
209 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
211 không sai,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 chỉ cần trả về giá trị được lưu trữ ở đó

Một bảng được sử dụng bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 để kiểm soát cách tải các mô-đun

Mỗi mục trong bảng này là một chức năng tìm kiếm. Khi tìm kiếm một mô-đun,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 gọi từng trình tìm kiếm này theo thứ tự tăng dần, với tên mô-đun [đối số được cung cấp cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183] làm tham số duy nhất của nó. The function can return another function [the module loader] or a string explaining why it did not find that module [or nil if it has nothing to say]. Lua khởi tạo bảng này với bốn chức năng

Người tìm kiếm đầu tiên chỉ cần tìm một trình tải trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
243

Người tìm kiếm thứ hai tìm kiếm trình tải dưới dạng thư viện Lua, sử dụng đường dẫn được lưu trữ tại

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
219. Đường dẫn là một chuỗi các mẫu được phân tách bằng dấu chấm phẩy. Đối với mỗi mẫu, người tìm kiếm sẽ thay đổi từng dấu hỏi trong mẫu bằng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
651, là tên mô-đun với mỗi dấu chấm được thay thế bằng "dấu phân cách thư mục" [chẳng hạn như "
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
749" trong Unix]; . Vì vậy, ví dụ, nếu đường dẫn Lua là chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
49

việc tìm kiếm tệp Lua cho mô-đun

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
247 sẽ cố gắng mở các tệp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
248,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
249 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
250 theo thứ tự đó

Người tìm kiếm thứ ba tìm kiếm trình tải dưới dạng thư viện C, sử dụng đường dẫn được cung cấp bởi biến

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
220. Chẳng hạn, nếu đường dẫn C là chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
50

người tìm kiếm mô-đun

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
247 sẽ cố mở các tệp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
253,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
254 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
255 theo thứ tự đó. Sau khi tìm thấy thư viện C, người tìm kiếm này trước tiên sử dụng tiện ích liên kết động để liên kết ứng dụng với thư viện. Sau đó, nó cố gắng tìm một hàm C bên trong thư viện để sử dụng làm trình tải. Tên của hàm C này là chuỗi "______7256" được nối với một bản sao của tên mô-đun trong đó mỗi dấu chấm được thay thế bằng dấu gạch dưới. Ngoài ra, nếu tên mô-đun có dấu gạch nối, tiền tố của nó cho đến [và bao gồm] dấu gạch nối đầu tiên sẽ bị xóa. Chẳng hạn, nếu tên mô-đun là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
257, tên hàm sẽ là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
258

Người tìm kiếm thứ tư thử trình tải tất cả trong một. It searches the C path for a library for the root name of the given module. Chẳng hạn, khi yêu cầu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
203, nó sẽ tìm kiếm thư viện C cho
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
87. Nếu tìm thấy, nó sẽ xem xét nó để tìm một chức năng mở cho mô hình con; . Với cơ sở này, một gói có thể đóng gói một số mô-đun con C vào một thư viện duy nhất, với mỗi mô-đun con giữ chức năng mở ban đầu của nó

Tự động liên kết chương trình máy chủ với thư viện C

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009. Trong thư viện này, hãy tìm hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
263 và trả về hàm này dưới dạng hàm C. [Vì vậy,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
263 phải tuân theo giao thức [xem
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
785]]

Đây là một chức năng cấp thấp. Nó hoàn toàn bỏ qua hệ thống gói và mô-đun. Không giống như

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183, nó không thực hiện bất kỳ tìm kiếm đường dẫn nào và không tự động thêm tiện ích mở rộng.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
009 phải là tên tệp hoàn chỉnh của thư viện C, bao gồm cả đường dẫn và phần mở rộng nếu cần.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
263 phải là tên chính xác được xuất bởi thư viện C [có thể phụ thuộc vào trình biên dịch C và trình liên kết được sử dụng]

Chức năng này không được hỗ trợ bởi ANSI C. Do đó, nó chỉ khả dụng trên một số nền tảng [Windows, Linux, Mac OS X, Solaris, BSD, cùng với các hệ thống Unix khác hỗ trợ tiêu chuẩn

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
269]

Đường dẫn được sử dụng bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183 để tìm kiếm trình tải Lua

Khi khởi động, Lua khởi tạo biến này với giá trị của biến môi trường

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
271 hoặc với đường dẫn mặc định được xác định trong
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92, nếu biến môi trường không được xác định. Bất kỳ "
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
711" nào trong giá trị của biến môi trường được thay thế bằng đường dẫn mặc định

Một bảng để lưu trữ các bộ tải cho các mô-đun cụ thể [xem

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
183]

Đặt một siêu dữ liệu cho

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184 với trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
276 của nó đề cập đến môi trường toàn cầu, để mô-đun này kế thừa các giá trị từ môi trường toàn cầu. To be used as an option to function
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
184

Thư viện này cung cấp các hàm chung để thao tác chuỗi, chẳng hạn như tìm và trích xuất các chuỗi con và so khớp mẫu. Khi lập chỉ mục một chuỗi trong Lua, ký tự đầu tiên ở vị trí 1 [không phải vị trí 0, như trong C]. Các chỉ số được phép âm và được hiểu là lập chỉ mục ngược, từ cuối chuỗi. Do đó, ký tự cuối cùng ở vị trí -1, v.v.

Thư viện chuỗi cung cấp tất cả các chức năng của nó bên trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
140. Nó cũng đặt một metatable cho các chuỗi trong đó trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
276 trỏ đến bảng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
140. Do đó, bạn có thể sử dụng các hàm chuỗi theo kiểu hướng đối tượng. Chẳng hạn,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
281 có thể được viết là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
282

Thư viện chuỗi giả định mã hóa ký tự một byte

Trả về mã số nội bộ của các ký tự
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
283,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
284, ···,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
285. Giá trị mặc định cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 là 1;

Lưu ý rằng mã số không nhất thiết phải di động trên các nền tảng

Nhận không hoặc nhiều số nguyên. Trả về một chuỗi có độ dài bằng với số đối số, trong đó mỗi ký tự có mã số bên trong bằng với đối số tương ứng của nó

Lưu ý rằng mã số không nhất thiết phải di động trên các nền tảng

Trả về một chuỗi chứa biểu diễn nhị phân của hàm đã cho, sao cho sau đó,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
749 trên chuỗi này sẽ trả về một bản sao của hàm.
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440 phải là một hàm Lua không có giá trị gia tăng

Looks for the first match of
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 in the string
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456. Nếu tìm thấy kết quả trùng khớp, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
293 trả về các chỉ số của 
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 nơi sự kiện này bắt đầu và kết thúc; . Đối số số thứ ba, tùy chọn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
295 chỉ định nơi bắt đầu tìm kiếm; . Giá trị true làm đối số thứ tư, tùy chọn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
296 sẽ tắt các tiện ích khớp mẫu, do đó, hàm thực hiện thao tác "tìm chuỗi con" đơn giản, không có ký tự nào trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 được coi là "phép thuật". Lưu ý rằng nếu cung cấp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
296 thì cũng phải cung cấp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
295

Nếu mẫu đã chụp, thì khi khớp thành công, các giá trị đã chụp cũng được trả về, sau hai chỉ số

Trả về phiên bản đã định dạng của số lượng đối số thay đổi theo mô tả được đưa ra trong đối số đầu tiên của nó [phải là một chuỗi]. Chuỗi định dạng tuân theo các quy tắc giống như họ hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
300 của C tiêu chuẩn. Sự khác biệt duy nhất là các tùy chọn/công cụ sửa đổi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
748,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
313,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
463,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
803 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
306 không được hỗ trợ và có một tùy chọn bổ sung,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
307. Tùy chọn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
307 định dạng một chuỗi ở dạng phù hợp để trình thông dịch Lua đọc lại một cách an toàn. chuỗi được viết giữa dấu ngoặc kép và tất cả dấu ngoặc kép, dòng mới, số 0 được nhúng và dấu gạch chéo ngược trong chuỗi được thoát chính xác khi được viết. Chẳng hạn, cuộc gọi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
51

sẽ tạo ra chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
52

Các tùy chọn

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
374,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
671,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
311,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
314,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
315,
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
802,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
315,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
319 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 đều mong đợi một số làm đối số, trong khi đó
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
307 và
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 mong đợi một chuỗi

Hàm này không chấp nhận các giá trị chuỗi chứa các số 0 được nhúng, ngoại trừ các đối số cho tùy chọn

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
307

Trả về một hàm lặp, mỗi lần nó được gọi, sẽ trả về các lần chụp tiếp theo từ
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 qua chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456. Nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 chỉ định không chụp, thì toàn bộ trận đấu được tạo ra trong mỗi cuộc gọi

Ví dụ, vòng lặp sau

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
53

will iterate over all the words from string

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456, printing one per line. Ví dụ tiếp theo thu thập tất cả các cặp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
328 từ chuỗi đã cho vào một bảng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
54

Đối với chức năng này, '

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
751' ở đầu mẫu không hoạt động như một điểm neo, vì điều này sẽ ngăn quá trình lặp lại

Trả về một bản sao của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 trong đó tất cả [hoặc
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 đầu tiên, nếu được cung cấp] của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 đã được thay thế bằng một chuỗi thay thế được chỉ định bởi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
333, có thể là một chuỗi, một bảng hoặc một hàm.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
334 cũng trả về, như giá trị thứ hai của nó, tổng số trận đấu đã xảy ra

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
333 là một chuỗi thì giá trị của nó được dùng để thay thế. Ký tự
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
750 hoạt động như một ký tự thoát. bất kỳ chuỗi nào trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
333 có dạng
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
338, với n nằm trong khoảng từ 1 đến 9, là viết tắt của giá trị của chuỗi con được bắt thứ n [xem bên dưới]. Dãy
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
339 là viết tắt của cả trận. Trình tự _______4444 là viết tắt của một ______2750

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
333 là một bảng, thì bảng được truy vấn cho mọi kết quả khớp, sử dụng lần chụp đầu tiên làm khóa;

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
333 là một hàm, thì hàm này được gọi mỗi khi khớp xảy ra, với tất cả các chuỗi con đã bắt được chuyển dưới dạng đối số, theo thứ tự;

Nếu giá trị được trả về bởi truy vấn bảng hoặc bởi lệnh gọi hàm là một chuỗi hoặc một số, thì giá trị đó được sử dụng làm chuỗi thay thế;

Dưới đây là một số ví dụ

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
55Nhận một chuỗi và trả về độ dài của nó. Chuỗi rỗng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
993 có độ dài 0. Các số 0 nhúng được tính, vì vậy
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
345 có độ dài 5Nhận một chuỗi và trả về một bản sao của chuỗi này với tất cả các chữ hoa được đổi thành chữ thường. All other characters are left unchanged. Định nghĩa về chữ hoa là gì tùy thuộc vào ngôn ngữ hiện tạiTìm kiếm trận đấu đầu tiên của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 trong chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456. Nếu tìm thấy, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
348 trả về các ảnh chụp được từ mẫu; . Nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
291 chỉ định không có ảnh chụp nào, thì toàn bộ kết quả khớp sẽ được trả về. Đối số số thứ ba, tùy chọn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
295 chỉ định nơi bắt đầu tìm kiếm; Trả về một chuỗi là nối của các bản sao của
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 của chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456Trả về một chuỗi là chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 bị đảo ngượcTrả về chuỗi con của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 bắt đầu từ
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 và tiếp tục cho đến
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147; . Nếu không có
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147, thì nó được coi là bằng -1 [bằng với độ dài chuỗi]. Cụ thể, cuộc gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
360 trả về tiền tố của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 với độ dài
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
363 trả về hậu tố của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
456 với độ dài
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715Nhận một chuỗi và trả về một bản sao của chuỗi này với tất cả các chữ thường được đổi thành chữ hoa. Tất cả các ký tự khác không thay đổi. Định nghĩa về chữ thường là gì tùy thuộc vào ngôn ngữ hiện tại

lớp nhân vật

A character class is used to represent a set of characters. Các kết hợp sau đây được phép mô tả một lớp nhân vật

  • x. [trong đó x không phải là một trong các ký tự ma thuật
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    366] đại diện cho chính ký tự x
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    367. [một dấu chấm] đại diện cho tất cả các ký tự
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    368. đại diện cho tất cả các chữ cái
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    452. đại diện cho tất cả các ký tự điều khiển
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    450. đại diện cho tất cả các chữ số
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    371. đại diện cho tất cả các chữ thường
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    449. đại diện cho tất cả các ký tự dấu câu
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    446. đại diện cho tất cả các ký tự khoảng trắng
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    374. đại diện cho tất cả các chữ hoa
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    375. đại diện cho tất cả các ký tự chữ và số
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    376. đại diện cho tất cả các chữ số thập lục phân
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    377. đại diện cho ký tự với đại diện 0
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    378. [trong đó x là bất kỳ ký tự không phải chữ và số nào] đại diện cho ký tự x. Đây là cách tiêu chuẩn để thoát khỏi các ký tự ma thuật. Bất kỳ ký tự dấu chấm câu nào [ngay cả ký tự không phải phép thuật] đều có thể đứng trước '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    750' khi được sử dụng để thể hiện chính nó trong một mẫu
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    380. đại diện cho lớp là sự kết hợp của tất cả các ký tự trong tập hợp. Một phạm vi ký tự có thể được chỉ định bằng cách tách các ký tự cuối của phạm vi bằng '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747'. Tất cả các lớp
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    750x được mô tả ở trên cũng có thể được sử dụng làm thành phần trong bộ. Tất cả các ký tự khác trong bộ đại diện cho chính họ. Ví dụ:
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    383 [hoặc
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    384] đại diện cho tất cả các ký tự chữ và số cộng với dấu gạch dưới,
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    385 đại diện cho các chữ số bát phân và
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    386 đại diện cho các chữ số bát phân cộng với các chữ cái viết thường cộng với ký tự '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747'

    Sự tương tác giữa các phạm vi và các lớp không được xác định. Therefore, patterns like

         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    388 or
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    389 have no meaning

  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    390. đại diện cho phần bù của tập hợp, trong đó tập hợp được hiểu như trên

Đối với tất cả các lớp được đại diện bởi các chữ cái đơn lẻ [______7368,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
452, v.v. ], chữ hoa tương ứng biểu thị phần bù của lớp. Chẳng hạn,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
393 đại diện cho tất cả các ký tự không phải khoảng trắng

Các định nghĩa về chữ cái, dấu cách và các nhóm ký tự khác phụ thuộc vào ngôn ngữ hiện tại. Đặc biệt, lớp

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
394 có thể không tương đương với
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
371

Mục mẫu

Một mục mẫu có thể được

  • một lớp ký tự đơn, khớp với bất kỳ ký tự đơn nào trong lớp;
  • một lớp ký tự duy nhất theo sau là '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    748', khớp với 0 hoặc nhiều ký tự lặp lại trong lớp. Các mục lặp lại này sẽ luôn khớp với chuỗi dài nhất có thể;
  • một lớp ký tự duy nhất theo sau là '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    746', khớp với 1 hoặc nhiều lần lặp lại ký tự trong lớp. Các mục lặp lại này sẽ luôn khớp với chuỗi dài nhất có thể;
  • một lớp ký tự duy nhất theo sau là '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747', cũng khớp với 0 hoặc nhiều ký tự lặp lại trong lớp. Không giống như '
         and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    748', các mục lặp lại này sẽ luôn khớp với trình tự ngắn nhất có thể;
  • một lớp ký tự duy nhất theo sau là '
         a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    807', khớp với 0 hoặc 1 lần xuất hiện của một ký tự trong lớp;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    338, cho n từ 1 đến 9;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    402, trong đó x và y là hai ký tự riêng biệt; . Điều này có nghĩa là, nếu một người đọc chuỗi từ trái sang phải, đếm +1 cho x và -1 cho y, thì y kết thúc là y đầu tiên mà số đếm tiến tới 0. Chẳng hạn, mục
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    403 khớp với các biểu thức có dấu ngoặc đơn cân đối

Mẫu

Một mẫu là một chuỗi các mục mẫu. A '

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
751' at the beginning of a pattern anchors the match at the beginning of the subject string. Một '
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
405' ở cuối mẫu neo kết quả khớp ở cuối chuỗi chủ đề. Ở các vị trí khác, '
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
751' và '______7405' không có ý nghĩa đặc biệt và tự đại diện

chụp

Một mẫu có thể chứa các mẫu con được đặt trong dấu ngoặc đơn; . Khi khớp thành công, các chuỗi con của chuỗi chủ đề khớp với ảnh chụp được lưu trữ [đã chụp] để sử dụng trong tương lai. Ảnh chụp được đánh số theo dấu ngoặc đơn bên trái của chúng. Chẳng hạn, trong mẫu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
408, một phần của chuỗi khớp với
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
409 được lưu trữ dưới dạng lần chụp đầu tiên [và do đó có số 1];

Trong trường hợp đặc biệt, bản ghi trống

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
412 ghi lại vị trí chuỗi hiện tại [một số]. Chẳng hạn, nếu chúng ta áp dụng mẫu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
413 trên chuỗi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
414, sẽ có hai lần chụp. 3 và 5

Một mẫu không thể chứa các số 0 được nhúng. Sử dụng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
377 để thay thế

Thư viện này cung cấp các chức năng chung cho thao tác bảng. Nó cung cấp tất cả các chức năng của nó bên trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107

Hầu hết các hàm trong thư viện bảng giả định rằng bảng đại diện cho một mảng hoặc một danh sách. Đối với các hàm này, khi chúng ta nói về "độ dài" của bảng, chúng ta muốn nói đến kết quả của toán tử độ dài

Given an array where all elements are strings or numbers, returns
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
417. Giá trị mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
418 là chuỗi rỗng, mặc định cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 là 1 và mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147 là độ dài của bảng. Nếu
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
715 lớn hơn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
147, trả về chuỗi rỗng

Chèn phần tử

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
110 vào vị trí
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
424 trong
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107, dịch chuyển các phần tử khác lên khoảng trống, nếu cần. Giá trị mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
424 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
427, trong đó
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 là độ dài của bảng [xem §2. 5. 5], sao cho lệnh gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
429 chèn
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 vào cuối bảng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768

Trả về chỉ số số dương lớn nhất của bảng đã cho hoặc 0 nếu bảng không có chỉ số số dương. [Để thực hiện công việc của mình, hàm này thực hiện duyệt tuyến tính toàn bộ bảng. ]

Xóa khỏi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107 phần tử ở vị trí
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
424, dịch chuyển các phần tử khác xuống để đóng khoảng trống, nếu cần. Trả về giá trị của phần tử đã loại bỏ. Giá trị mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
424 là
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769, trong đó
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 là độ dài của bảng, do đó lệnh gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
437 sẽ loại bỏ phần tử cuối cùng của bảng
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
768

Sắp xếp các phần tử của bảng theo thứ tự nhất định, tại chỗ, từ
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
439 đến
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
440, trong đó
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769 là độ dài của bảng. Nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
442 được đưa ra, thì đó phải là một hàm nhận hai phần tử bảng và trả về giá trị true khi phần tử đầu tiên nhỏ hơn phần tử thứ hai [do đó,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
443 sẽ là true sau khi sắp xếp]. Nếu không cung cấp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
442, thì toán tử Lua tiêu chuẩn
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
738 sẽ được sử dụng để thay thế

Thuật toán sắp xếp không ổn định;

Thư viện này là giao diện của thư viện C math tiêu chuẩn. Nó cung cấp tất cả các chức năng của nó bên trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
446

Returns the absolute value of

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về cung cosin của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [tính bằng radian]

Trả về cung sin của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [tính bằng radian]

Trả về tang cung của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [tính bằng radian]

Trả về tang cung của

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
451 [tính bằng radian], nhưng sử dụng dấu của cả hai tham số để tìm góc tọa độ của kết quả. [Nó cũng xử lý chính xác trường hợp
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 bằng 0. ]

Trả về số nguyên nhỏ nhất lớn hơn hoặc bằng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về cosin của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [được cho là tính bằng radian]

Trả về cosin hyperbol của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về góc

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [tính bằng radian] theo độ

Trả về giá trị cũ

Trả về số nguyên lớn nhất nhỏ hơn hoặc bằng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về phần còn lại của phép chia của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 cho
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
718 làm tròn thương số về 0

Returns

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
810 and
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 such that x = m2e,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 is an integer and the absolute value of
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
810 is in the range [0. 5, 1] [hoặc 0 khi
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 bằng 0]

Giá trị

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
465, một giá trị lớn hơn hoặc bằng bất kỳ giá trị số nào khác

Trả về m2e [

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
811 phải là số nguyên]

Trả về logarit tự nhiên của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về logarit cơ số 10 của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về giá trị lớn nhất trong số các đối số của nó

Trả về giá trị nhỏ nhất trong số các đối số của nó

Trả về hai số, phần nguyên của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 và phần phân số của
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

giá trị của pi

Trả về xy. [Bạn cũng có thể sử dụng biểu thức

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
471 để tính giá trị này. ]

Trả về góc

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [tính theo độ] tính bằng radian

Hàm này là giao diện của hàm tạo giả ngẫu nhiên đơn giản

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
473 do ANSI C cung cấp. [Không thể đảm bảo cho các thuộc tính thống kê của nó. ]

Khi được gọi mà không có đối số, trả về một số thực giả ngẫu nhiên thống nhất trong phạm vi [0,1]. Khi được gọi với một số nguyên

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
810,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
475 trả về một số nguyên giả ngẫu nhiên thống nhất trong phạm vi [1, m]. Khi được gọi với hai số nguyên
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
810 và
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
769,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
475 trả về một số nguyên giả ngẫu nhiên thống nhất trong phạm vi [m, n]

Đặt

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 làm "hạt giống" cho trình tạo giả ngẫu nhiên. equal seeds produce equal sequences of numbers

Trả về sin của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [được cho là tính bằng radian]

Trả về sin hyperbol của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Trả về căn bậc hai của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706. [Bạn cũng có thể sử dụng biểu thức
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
483 để tính giá trị này. ]

Trả về tang của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706 [được cho là tính bằng radian]

Trả về tang hyperbol của

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
706

Thư viện I/O cung cấp hai kiểu khác nhau để thao tác tệp. Cái đầu tiên sử dụng bộ mô tả tệp ẩn; . Kiểu thứ hai sử dụng các bộ mô tả tệp rõ ràng

Khi sử dụng bộ mô tả tệp ẩn, tất cả các hoạt động được cung cấp bởi bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
486. Khi sử dụng bộ mô tả tệp rõ ràng, hoạt động
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
487 trả về một bộ mô tả tệp và sau đó tất cả các hoạt động được cung cấp dưới dạng phương thức của bộ mô tả tệp

Bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
486 cũng cung cấp ba bộ mô tả tệp được xác định trước với ý nghĩa thông thường của chúng từ C.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
489,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
490 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
491. Thư viện I/O không bao giờ đóng các tệp này

Trừ khi có quy định khác, tất cả các chức năng I/O đều trả về 0 khi thất bại [cộng với thông báo lỗi ở kết quả thứ hai và mã lỗi phụ thuộc vào hệ thống ở kết quả thứ ba] và một số giá trị khác với 0 khi thành công

Tương đương với

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
492. Không có
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
493, hãy đóng tệp đầu ra mặc định

Tương đương với

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
494 trên tệp đầu ra mặc định

Khi được gọi với tên tệp, nó sẽ mở tệp được đặt tên [ở chế độ văn bản] và đặt tay cầm của nó làm tệp đầu vào mặc định. When called with a file handle, it simply sets this file handle as the default input file. Khi được gọi mà không có tham số, nó sẽ trả về tệp đầu vào mặc định hiện tại

Trong trường hợp có lỗi, chức năng này sẽ báo lỗi thay vì trả về mã lỗi

Mở tên tệp đã cho ở chế độ đọc và trả về một hàm lặp, mỗi khi được gọi, nó sẽ trả về một dòng mới từ tệp. Vì vậy, việc xây dựng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
56

sẽ lặp lại trên tất cả các dòng của tệp. Khi hàm iterator phát hiện kết thúc tệp, nó trả về nil [để kết thúc vòng lặp] và tự động đóng tệp

Cuộc gọi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
495 [không có tên tệp] tương đương với
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
496; . Trong trường hợp này, nó không đóng tệp khi vòng lặp kết thúc

Hàm này mở một tệp, ở chế độ được chỉ định trong chuỗi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
497. Nó trả về một xử lý tệp mới hoặc, trong trường hợp có lỗi, không cộng với một thông báo lỗi

Chuỗi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
497 có thể là bất kỳ chuỗi nào sau đây

  • "r". chế độ đọc [mặc định];
  • "w". chế độ viết;
  • "một". append mode;
  • "r+". chế độ cập nhật, tất cả dữ liệu trước đó được giữ nguyên;
  • "w+". chế độ cập nhật, tất cả dữ liệu trước đó sẽ bị xóa;
  • "a+". chế độ cập nhật nối thêm, dữ liệu trước đó được giữ nguyên, chỉ được phép ghi ở cuối tệp

Chuỗi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
497 cũng có thể có '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
435' ở cuối, cần thiết trong một số hệ thống để mở tệp ở chế độ nhị phân. Chuỗi này chính xác là chuỗi được sử dụng trong hàm C tiêu chuẩn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
501

Tương tự như

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
502, nhưng hoạt động trên tệp đầu ra mặc định

Bắt đầu chương trình

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
503 trong một quy trình riêng biệt và trả về một điều khiển tệp mà bạn có thể sử dụng để đọc dữ liệu từ chương trình này [nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
497 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
505, mặc định] hoặc để ghi dữ liệu vào chương trình này [nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
497 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
507]

Chức năng này phụ thuộc vào hệ thống và không khả dụng trên tất cả các nền tảng

Tương đương với

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
508

Trả về một điều khiển cho một tập tin tạm thời. Tệp này được mở ở chế độ cập nhật và nó sẽ tự động bị xóa khi chương trình kết thúc

Kiểm tra xem

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603 có phải là một tệp xử lý hợp lệ không. Returns the string
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
510 if
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603 is an open file handle,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
512 if
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603 is a closed file handle, or nil if
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
603 is not a file handle

Equivalent to

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
515

Đóng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
493. Lưu ý rằng các tệp sẽ tự động đóng khi phần xử lý của chúng được thu gom rác, nhưng điều đó sẽ mất một khoảng thời gian không thể đoán trước để xảy ra

Lưu mọi dữ liệu bằng văn bản vào

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
493

Trả về một hàm lặp mà mỗi khi nó được gọi, nó sẽ trả về một dòng mới từ tệp. Vì vậy, việc xây dựng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
57

sẽ lặp lại trên tất cả các dòng của tệp. [Không giống như

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
518, chức năng này không đóng tệp khi vòng lặp kết thúc. ]

Đọc tệp

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
493, theo các định dạng đã cho, chỉ định nội dung cần đọc. Đối với mỗi định dạng, hàm trả về một chuỗi [hoặc một số] với các ký tự được đọc hoặc nil nếu nó không thể đọc dữ liệu với định dạng được chỉ định. Khi được gọi mà không có định dạng, nó sử dụng định dạng mặc định để đọc toàn bộ dòng tiếp theo [xem bên dưới]

Các định dạng có sẵn là

  • "*N". đọc một số;
  • "*một". đọc toàn bộ tập tin, bắt đầu từ vị trí hiện tại. Ở cuối tệp, nó trả về chuỗi rỗng
  • "*l". reads the next line [skipping the end of line], returning nil on end of file. Đây là định dạng mặc định
  • con số. đọc một chuỗi có tối đa số ký tự này, trả về nil ở cuối tệp. Nếu số bằng 0, nó không đọc gì và trả về một chuỗi trống hoặc nil ở cuối tệp

Đặt và nhận vị trí tệp, được đo từ đầu tệp, đến vị trí được cung cấp bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
520 cộng với một cơ sở được chỉ định bởi chuỗi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
521, như sau

  • "bộ". cơ sở là vị trí 0 [đầu tệp];
  • "hay gây". cơ sở là vị trí hiện tại;
  • "chấm dứt". cơ sở là cuối tập tin;

Trong trường hợp thành công, hàm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
522 trả về vị trí tệp cuối cùng, được đo bằng byte từ đầu tệp. Nếu chức năng này không thành công, nó sẽ trả về con số không, cộng với một chuỗi mô tả lỗi

Giá trị mặc định cho

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
521 là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
524 và cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
520 là 0. Do đó, cuộc gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
526 trả về vị trí tệp hiện tại mà không thay đổi nó;

Đặt chế độ đệm cho tệp đầu ra. Có ba chế độ có sẵn

  • "không". không đệm;
  • "đầy". đệm đầy đủ;
  • "dòng". đệm dòng;

Đối với hai trường hợp cuối cùng,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
478 chỉ định kích thước của bộ đệm, tính bằng byte. The default is an appropriate size

Writes the value of each of its arguments to the

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
493. The arguments must be strings or numbers. To write other values, use
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
101 or
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
98 before
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
535

This library is implemented through table

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
536

Returns an approximation of the amount in seconds of CPU time used by the program

Returns a string or a table containing date and time, formatted according to the given string

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97

If the

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
538 argument is present, this is the time to be formatted [see the
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
539 function for a description of this value]. Otherwise,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
540 formats the current time

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97 bắt đầu bằng '
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
542', thì ngày được định dạng theo Giờ Phối hợp Quốc tế. Sau ký tự tùy chọn này, nếu
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97 là chuỗi "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
544", thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
540 trả về một bảng có các trường sau.
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
546 [bốn chữ số],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
547 [1--12],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
548 [1--31],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
549 [0--23],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
550 [0--59],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
551 [0--61],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
552 [ngày trong tuần,

Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
97 không phải là "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
544", thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
540 trả về ngày ở dạng chuỗi, được định dạng theo cùng quy tắc như hàm C _______7558

Khi được gọi mà không có đối số,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
540 trả về biểu diễn ngày và giờ hợp lý tùy thuộc vào hệ thống máy chủ và ngôn ngữ hiện tại [nghĩa là,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
560 tương đương với
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
561]

Trả về số giây từ thời điểm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
562 đến thời điểm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
563. Trong POSIX, Windows và một số hệ thống khác, giá trị này chính xác là ____7563-
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
562

Chức năng này tương đương với chức năng C

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
566. Nó vượt qua
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
567 để được thực thi bởi hệ điều hành Shell. It returns a status code, which is system-dependent. Nếu không có
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
567, thì nó trả về giá trị khác 0 nếu có shell và 0 nếu không có

Gọi hàm C

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
569, với một tùy chọn
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
570, để kết thúc chương trình máy chủ. Giá trị mặc định cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
570 là mã thành công

Trả về giá trị của biến môi trường quy trình

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
572 hoặc nil nếu biến không được xác định

Xóa tệp hoặc thư mục với tên đã cho. Thư mục phải trống để được gỡ bỏ. Nếu chức năng này không thành công, nó sẽ trả về con số không, cộng với một chuỗi mô tả lỗi

Đổi tên tệp hoặc thư mục có tên

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
573 thành
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
574. Nếu chức năng này không thành công, nó sẽ trả về con số không, cộng với một chuỗi mô tả lỗi

Đặt ngôn ngữ hiện tại của chương trình.

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
575 là một chuỗi chỉ định ngôn ngữ; .
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
577,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
578,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
579,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
580,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
581 hoặc
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
582; . Hàm trả về tên của ngôn ngữ mới hoặc nil nếu yêu cầu không thể được thực hiện

Nếu

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
575 là chuỗi trống, ngôn ngữ hiện tại được đặt thành ngôn ngữ gốc do triển khai xác định. Nếu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
575 là chuỗi "
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
586", ngôn ngữ hiện tại được đặt thành ngôn ngữ C tiêu chuẩn

Khi được gọi với nil làm đối số đầu tiên, hàm này chỉ trả về tên của ngôn ngữ hiện tại cho danh mục đã cho

Trả về thời gian hiện tại khi được gọi mà không có đối số hoặc thời gian biểu thị ngày và giờ được chỉ định bởi bảng đã cho. Bảng này phải có các trường

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
546,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
547 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
548 và có thể có các trường
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
549,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
550,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
551 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
554 [để biết mô tả về các trường này, hãy xem hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
594]

The returned value is a number, whose meaning depends on your system. Trong POSIX, Windows và một số hệ thống khác, con số này đếm số giây kể từ thời điểm bắt đầu nhất định ["kỷ nguyên"]. Trong các hệ thống khác, ý nghĩa không được chỉ định và số được trả về bởi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
538 chỉ có thể được sử dụng làm đối số cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
540 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
597

Trả về một chuỗi có tên tệp có thể được sử dụng cho tệp tạm thời. Tệp phải được mở rõ ràng trước khi sử dụng và xóa rõ ràng khi không còn cần thiết

Trên một số hệ thống [POSIX], chức năng này cũng tạo một tệp có tên đó, để tránh rủi ro bảo mật. [Người khác có thể tạo tệp với quyền sai trong khoảng thời gian từ khi nhận tên đến khi tạo tệp. ] Bạn vẫn phải mở file để sử dụng và gỡ bỏ nó [ngay cả khi bạn không sử dụng nó]

Khi có thể, bạn có thể sử dụng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
598 để tự động xóa tệp khi chương trình kết thúc

Thư viện này cung cấp chức năng của giao diện gỡ lỗi cho các chương trình Lua. Bạn nên hết sức cẩn thận khi sử dụng thư viện này. Các chức năng được cung cấp ở đây chỉ nên được sử dụng để gỡ lỗi và các tác vụ tương tự, chẳng hạn như lập hồ sơ. Hãy chống lại sự cám dỗ để sử dụng chúng như một công cụ lập trình thông thường. chúng có thể rất chậm. Hơn nữa, một số chức năng này vi phạm một số giả định về mã Lua [e. g. , các biến cục bộ của một hàm không thể được truy cập từ bên ngoài hoặc các bảng siêu dữ liệu người dùng không thể thay đổi bằng mã Lua] và do đó có thể ảnh hưởng đến mã bảo mật

Tất cả các chức năng trong thư viện này được cung cấp bên trong bảng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
599. Tất cả các chức năng hoạt động trên một luồng có một đối số đầu tiên tùy chọn là luồng sẽ hoạt động trên. Mặc định luôn là chủ đề hiện tại

Vào chế độ tương tác với người dùng, chạy từng chuỗi mà người dùng nhập. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. Một dòng chỉ chứa từ

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
600 kết thúc chức năng này để người gọi tiếp tục thực hiện

Lưu ý rằng các lệnh cho

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
601 không được lồng vào nhau về mặt từ vựng trong bất kỳ chức năng nào và do đó không có quyền truy cập trực tiếp vào các biến cục bộ

Trả về môi trường của đối tượng
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
802

Trả về cài đặt hook hiện tại của luồng, dưới dạng ba giá trị. hàm móc hiện tại, mặt nạ móc hiện tại và số lượng móc hiện tại [như được đặt bởi hàm

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
603]

Trả về một bảng có thông tin về một chức năng. Bạn có thể cung cấp chức năng trực tiếp hoặc bạn có thể cung cấp một số dưới dạng giá trị của

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440, có nghĩa là chức năng chạy ở cấp độ
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440 của ngăn xếp cuộc gọi của chuỗi đã cho. cấp 0 là chức năng hiện tại [chính ____7606]; . Nếu
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
440 là một số lớn hơn số hàm đang hoạt động, thì
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
606 trả về nil

Bảng được trả về có thể chứa tất cả các trường được trả về bởi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
964, với chuỗi
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869 mô tả các trường cần điền vào. Mặc định cho
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
869 là lấy tất cả thông tin có sẵn, ngoại trừ bảng các dòng hợp lệ. Nếu có, tùy chọn '
     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
742' sẽ thêm trường có tên
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852 với chính chức năng đó. Nếu có, tùy chọn '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
463' sẽ thêm trường có tên
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
616 với bảng các dòng hợp lệ

Chẳng hạn, biểu thức

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
617 trả về một bảng có tên cho hàm hiện tại, nếu có thể tìm thấy một tên hợp lý và biểu thức
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
618 trả về một bảng có tất cả thông tin có sẵn về hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
102

Hàm này trả về tên và giá trị của biến cục bộ có chỉ số

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
620 của hàm ở mức
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062 của ngăn xếp. [Thông số đầu tiên hoặc biến cục bộ có chỉ số 1, v.v. cho đến biến cục bộ hoạt động cuối cùng. ] Hàm trả về nil nếu không có biến cục bộ với chỉ mục đã cho và gây ra lỗi khi được gọi với một giá trị nằm ngoài phạm vi của
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062. [Bạn có thể gọi cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
623 để kiểm tra xem cấp độ có hợp lệ không. ]

Variable names starting with '

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
797' [open parentheses] represent internal variables [loop control variables, temporaries, and C function locals]

Returns the metatable of the given

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
072 or nil if it does not have a metatable

Returns the registry table [see §3. 5]

Hàm này trả về tên và giá trị của giá trị tăng với chỉ số

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
626 của hàm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852. Hàm trả về nil nếu không có giá trị tăng với chỉ mục đã cho

Đặt môi trường của

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
072 đã cho thành
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107 đã cho. Trả về
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
072

Đặt hàm đã cho dưới dạng hook. Chuỗi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
349 và số
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
354 mô tả thời điểm hook sẽ được gọi. Mặt nạ chuỗi có thể có các ký tự sau, với ý nghĩa đã cho

  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    633. hook được gọi mỗi khi Lua gọi một hàm;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    505. cái móc được gọi mỗi khi Lua trở về từ một hàm;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    635. móc được gọi mỗi khi Lua nhập một dòng mã mới

Với một

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
354 khác 0, hook được gọi sau mỗi lệnh của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
354

Khi được gọi mà không có đối số,

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
603 sẽ tắt hook

Khi hook được gọi, tham số đầu tiên của nó là một chuỗi mô tả sự kiện đã kích hoạt cuộc gọi của nó.

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
639,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
640 [hoặc
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
641, khi mô phỏng quay lại từ cuộc gọi đuôi],
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
642 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
643. Đối với các sự kiện dòng, hook cũng lấy số dòng mới làm tham số thứ hai. Bên trong hook, bạn có thể gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
606 với cấp độ 2 để biết thêm thông tin về hàm đang chạy [cấp độ 0 là hàm
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
606 và cấp độ 1 là hàm hook], trừ khi sự kiện là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
641. Trong trường hợp này, Lua chỉ mô phỏng trả về và lệnh gọi tới ____7606 sẽ trả về dữ liệu không hợp lệ

Hàm này gán giá trị

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
110 cho biến cục bộ có chỉ số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
620 của hàm ở mức
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062 của ngăn xếp. Hàm trả về nil nếu không có biến cục bộ với chỉ mục đã cho và phát sinh lỗi khi được gọi với giá trị ngoài phạm vi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062. [Bạn có thể gọi tới
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
606 để kiểm tra xem mức độ có hợp lệ không. ] Ngược lại, nó trả về tên của biến cục bộ

Đặt metatable cho

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
072 đã cho thành
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
107 đã cho [có thể là không]

Hàm này gán giá trị

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
110 cho giá trị tăng với chỉ số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
626 của hàm
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
852. Hàm trả về nil nếu không có giá trị tăng với chỉ mục đã cho. Mặt khác, nó trả về tên của giá trị tăng

Trả về một chuỗi có dấu vết của ngăn xếp cuộc gọi. Một chuỗi

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
049 tùy chọn được thêm vào đầu truy nguyên. Một số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
062 tùy chọn cho biết mức bắt đầu truy nguyên [mặc định là 1, chức năng gọi
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
660]

Mặc dù Lua đã được thiết kế như một ngôn ngữ mở rộng, được nhúng trong chương trình máy chủ C, nhưng nó cũng thường được sử dụng như một ngôn ngữ độc lập. Một trình thông dịch cho Lua như một ngôn ngữ độc lập, được gọi đơn giản là

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66, được cung cấp cùng với bản phân phối tiêu chuẩn. Trình thông dịch độc lập bao gồm tất cả các thư viện tiêu chuẩn, bao gồm cả thư viện gỡ lỗi. cách sử dụng của nó là

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
58

Các tùy chọn là

  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    662. thực thi chuỗi stat;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    663. "yêu cầu" chế độ;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    664. vào chế độ tương tác sau khi chạy tập lệnh;
  •      +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    665. in thông tin phiên bản;
  •      a = 'alo\n123"'
         a = "alo\n123\""
         a = '\97lo\10\04923"'
         a = [[alo
         123"]]
         a = [==[
         alo
         123"]==]
    
    90. dừng xử lý tùy chọn;
  •      and       break     do        else      elseif
         end       false     for       function  if
         in        local     nil       not       or
         repeat    return    then      true      until     while
    
    747. thực thi
         +     -     *     /     %     ^     #
         ==    ~=    =    <     >     =
         [     ]     {     }     [     ]
         ;     :     ,     .     .    ...
    
    056 dưới dạng tệp và dừng xử lý các tùy chọn

Sau khi xử lý các tùy chọn của nó,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 chạy tập lệnh đã cho, chuyển cho nó các đối số đã cho dưới dạng đối số chuỗi. Khi được gọi mà không có đối số,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 hoạt động như
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
671 khi đầu vào tiêu chuẩn [
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
056] là một thiết bị đầu cuối và như
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
673 nếu không

Trước khi chạy bất kỳ đối số nào, trình thông dịch sẽ kiểm tra biến môi trường

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
674. Nếu định dạng của nó là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
675, thì
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 sẽ thực thi tệp. Mặt khác,
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 tự thực thi chuỗi

Tất cả các tùy chọn được xử lý theo thứ tự, ngoại trừ

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
664. Chẳng hạn, một lời gọi như

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
59

trước tiên sẽ đặt

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
87 thành 1, sau đó in giá trị của
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
87 [là '
     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
88'] và cuối cùng chạy tệp
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
682 mà không có đối số. [Ở đây
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
405 là dấu nhắc trình bao. Lời nhắc của bạn có thể khác. ]

Trước khi bắt đầu chạy tập lệnh,

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 thu thập tất cả các đối số trong dòng lệnh trong một bảng chung có tên là
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
051. Tên tập lệnh được lưu trữ ở chỉ mục 0, đối số đầu tiên sau tên tập lệnh chuyển sang chỉ mục 1, v.v. Bất kỳ đối số nào trước tên tập lệnh [nghĩa là tên trình thông dịch cộng với các tùy chọn] đều chuyển đến các chỉ số phủ định. Ví dụ, trong cuộc gọi

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
60

đầu tiên trình thông dịch chạy tệp

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
686, sau đó tạo một bảng

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
61

và cuối cùng chạy tệp

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
687. Tập lệnh được gọi với
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
688,
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
689, ··· làm đối số;

Trong chế độ tương tác, nếu bạn viết một câu lệnh chưa hoàn chỉnh, trình thông dịch sẽ đợi nó hoàn thành bằng cách đưa ra một lời nhắc khác

Nếu biến toàn cục

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
691 chứa một chuỗi thì giá trị của nó được sử dụng làm lời nhắc. Tương tự, nếu biến toàn cục
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
692 chứa một chuỗi, thì giá trị của nó được sử dụng làm lời nhắc phụ [được đưa ra trong các câu lệnh không đầy đủ]. Do đó, cả hai lời nhắc có thể được thay đổi trực tiếp trên dòng lệnh hoặc trong bất kỳ chương trình Lua nào bằng cách gán cho
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
691. Xem ví dụ tiếp theo

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
62

[Cặp trích dẫn bên ngoài dành cho Shell, cặp bên trong dành cho Lua. ] Lưu ý việc sử dụng

     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
664 để vào chế độ tương tác;

Để cho phép sử dụng Lua làm trình thông dịch tập lệnh trong các hệ thống Unix, trình thông dịch độc lập sẽ bỏ qua dòng đầu tiên của đoạn nếu nó bắt đầu bằng

     and       break     do        else      elseif
     end       false     for       function  if
     in        local     nil       not       or
     repeat    return    then      true      until     while
767. Do đó, các tập lệnh Lua có thể được tạo thành các chương trình thực thi bằng cách sử dụng biểu mẫu
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
697 và
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
698, như trong

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
63

[Tất nhiên, vị trí của trình thông dịch Lua có thể khác trong máy của bạn. Nếu

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
66 nằm trong số
     +     -     *     /     %     ^     #
     ==    ~=    =    <     >     =
     [     ]     {     }     [     ]
     ;     :     ,     .     .    ...
700 của bạn, thì

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
64

là một giải pháp di động hơn. ]

Ở đây chúng tôi liệt kê những điểm không tương thích mà bạn có thể tìm thấy khi di chuyển một chương trình từ Lua 5. 0 đến Lua 5. 1. Bạn có thể tránh hầu hết sự không tương thích khi biên dịch Lua với các tùy chọn thích hợp [xem tệp

     a = 'alo\n123"'
     a = "alo\n123\""
     a = '\97lo\10\04923"'
     a = [[alo
     123"]]
     a = [==[
     alo
     123"]==]
92]. Tuy nhiên, tất cả các tùy chọn tương thích này sẽ bị loại bỏ trong phiên bản tiếp theo của Lua

Chủ Đề