Changes for page 01 Lua Functions

Last modified by Theodore Xu on 2023/10/26 10:51

From version 5.7
edited by Stone Wu
on 2022/07/12 09:20
Change comment: (Autosaved)
To version 5.4
edited by Leo
on 2022/06/16 17:20
Change comment: Update document after refactoring.

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Stone
1 +XWiki.Leo
Content
... ... @@ -1,66 +1,70 @@
1 -= **1 Interface description** =
1 += **1 Interface Description** =
2 2  
3 -== **Data type definition** ==
3 +== **1.1 Data type definition** ==
4 4  
5 +
5 5  |=**Type**|=**Description**
6 6  |=nil|Null
7 -|=boolean|Boolean (the value is true or false)
8 -|=number|Integer or floating point (signed or unsigned)
8 +|=boolean|Boolean, the value is true or false
9 +|=number|Integer or floating point, signed or unsigned
9 9  |=string|String
10 10  |=table|Table
11 11  |=function|Functions
12 12  
13 -== **Built-in function library clipping** ==
14 +== **1.2 Built-in function library clipping** ==
14 14  
15 15  Full features supported: coroutine/debug/ math/ package/ string/ table/ utf8
16 16  
17 -//Some features supported (available in []):** **os[clock/ date/ difftime/ time]//
18 +//,,Some features supported (available in []):** **os[clock/ date/ difftime/ time],,//
18 18  
19 -//Not supported: io/ file//
20 +//,,Not supported: io/ file,,//
20 20  
21 -== **Return value description** ==
22 +== **1.3 Return value description** ==
22 22  
23 23  The function return type multi means multiple return values (at least 2), usually:
24 24  
25 -//1st: nil//
26 +//,,1st: nil;,,//
26 26  
27 -//2nd: the error message//
28 +//,,2nd: the error message;,,//
28 28  
29 29  (((
30 -== **Function parameter description** ==
31 +== **1.4 Function parameter description** ==
31 31  )))
32 32  
33 -Suppose a function prototype is defined:
34 +**Assume the function prototype:**
34 34  
35 -{{code language="LUA"}}
36 -student(string name, number age[, number class])
36 +|(((
37 +//student(string name, number age[, number class])//
37 37  
38 -Function:
39 +**Function:**
39 39  
40 40  Register a student
41 41  
42 -Parameters:
43 +**Parameters:**
43 43  
44 -name: student name
45 +//name//: student name
45 45  
46 -age: student age
47 +//age//: student age
47 47  
48 -[class=1]: Student class
49 +//[class=1]//: Student class
49 49  
50 -Return:
51 +**Return:**
51 51  
52 52  Succeed: true
53 53  
54 54  Failed: multi
55 -{{/code}}
56 +)))
56 56  
57 -**Explanation**
58 +**Comment**
58 58  
59 -1. string name indicates that the first parameter name is a string
60 -1. number age indicates that the second parameter age is numeric
61 -1. [, number class] indicates that the third parameter class is a numeric value, and it is optional. Specify the default class in class 1 in the parameter description.
62 -1. **Any parameter in the [] is considered to be an optional parameter, and may not be transmitted when called. The default value will be given in the parameter description.**
60 +1.string name indicates that the first parameter name is a string
63 63  
62 +2.number age indicates that the second parameter age is numeric
63 +
64 +3. [, number class] indicates that the third parameter class is a numeric value, and it is optional. Specify the default class in class 1 in the parameter description.
65 +
66 +4. Any parameter in the brackets of [] is considered to be an optional parameter, and may not be transmitted when called. The default value will be given in the parameter description.
67 +
64 64  **Call example**
65 65  
66 66  |(((
... ... @@ -89,23 +89,26 @@
89 89  
90 90  **Comment**
91 91  
92 -1. From the print result, the first line and the second line are successfully called and returns true; the third line fails the call, the error message is translated as: the bar student has been registered, and there is indeed an error in the code.
93 -1. The fourth line of code uses two variables to receive the return value. The call failed, the first variable stat is nil, and the second variable err stores the error message. Then print it out using print, which is the output of the third line. This example shows how to capture and view the error message.
96 +1.From the print result, the second line of the first line is successfully called and returns true; the third line fails the call, the error message is translated as: the bar student has been registered, and there is indeed an error in the code.
94 94  
95 -== **Modification of print function** ==
98 +2.The fourth line of code uses two variables to receive the return value. The call failed, the first variable stat is nil, and the second variable err stores the error message. Then print it out using print, which is the output of the third line. This example shows how to capture and view the error message.
96 96  
97 -For the convenience of remote development, the print data is sent to the front end (web page) by means of network transmission, and the user can see the result of the debug output, because it consumes certain data and occupies the bandwidth of the server (or occupies server resources). So the following restrictions are made.
100 +== **1.5 Modification of the Print Function** ==
98 98  
99 -1. **Interval limit: **When debugging, transfer once every 2~~3 seconds;
100 -1. **Data limit: **The transfer data cannot be larger than 1.5KB in a single transmission, otherwise the extra part will be ignored;
101 -1. **Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission;
102 +For the convenience of remote development, the print data is sent to the front end (web page) by means of network transmission, and the user can see the result of the debug output, because it consumes certain data and occupies the bandwidth of the server (or occupies server resources). So make the following restrictions:
102 102  
104 +**1.Interval limit: **When debugging, transfer once every 2~~3 seconds;
105 +
106 +**2.Data limit: **The transfer data cannot be larger than 1.5KB, and the extra part will be ignored;
107 +
108 +**3.Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission;
109 +
103 103  Users should pay attention to avoid printing a lot of useless information, should minimize the debug output
104 104  
105 105  In addition, please refer to the front-end documentation for how to use view debugging.
106 106  
107 107  (((
108 -= **2 Address operation** =
115 += **2 Address Operation** =
109 109  
110 110  
111 111  )))