Changes for page 09 Lua Editor

Last modified by Nhu Nguyen on 2025/03/09 17:22

From version 3.1
edited by Hunter
on 2022/07/09 09:56
Change comment: There is no comment for this version
To version 2.1
edited by Joey
on 2022/06/16 15:07
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Hunter
1 +XWiki.Joey
Content
... ... @@ -1,5 +1,35 @@
1 -Lua script is only supported on HMI+, i series, ie series, ig series or models whose upgrade OS version to HMI V2.0 and above;
1 +**[[1 Lua Editor>>path:#_Toc42782932]]**
2 2  
3 +**[[1.1 Script File Area>>path:#_Toc42782933]]**
4 +
5 +**[[1.1.1 Lua Node>>path:#_Toc42782934]]**
6 +
7 +**[[1.1.2 Lua Child Node>>path:#_Toc42782936]]**
8 +
9 +**[[1.2 Script Editor>>path:#_Toc42782937]]**
10 +
11 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**1.2.1 Tool bar**__ 5>>path:#_Toc42782938]]
12 +
13 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**1.2.2 Editor area**__ 5>>path:#_Toc42782939]]
14 +
15 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**1.2.3 Output area**__ 5>>path:#_Toc42782940]]
16 +
17 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**2 Lua object**__ 6>>path:#_Toc42782941]]
18 +
19 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**2.1 How to use LuaScrip object**__ 6>>path:#_Toc42782942]]
20 +
21 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**3 Platform**__ 7>>path:#_Toc42782943]]
22 +
23 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**3.1 File header identification**__ 7>>path:#_Toc42782944]]
24 +
25 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**3.2 Special script file**__ 8>>path:#_Toc42782945]]
26 +
27 +[[(% class="wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink wikiinternallink" %)__**3.3** **Script type (operating mechanism)**__ 9>>path:#_Toc42782946]]
28 +
29 +Lua script is currently only available in PI+ or models ending with i(like PI3070i). Only these two types of HMI can use the Lua editor and object to develop lua scripts. The following operations are based on PI3070i project.
30 +
31 +This article only introduces the use of lua object in PIStudio.
32 +
3 3  (% style="text-align:center" %)
4 4  [[image:HMI Lua Editor user manual_html_90c08e4cdcf4210c.png||height="484" width="500" class="img-thumbnail"]]
5 5  
... ... @@ -7,18 +7,20 @@
7 7  (% style="text-align:center" %)
8 8  [[image:HMI Lua Editor user manual_html_674bb6778b0f003.png||height="487" width="500" class="img-thumbnail"]]
9 9  
10 -= **Lua Editor** =
40 +{{id name="_Toc42782932"/}}
11 11  
42 +{{id name="_Toc6870"/}}{{id name="_Toc27091"/}}**1 Lua editor**
43 +
12 12  The editor is divided into two areas, one is the script file area, and the other is the script editing area.
13 13  
14 14  (% style="text-align:center" %)
15 15  [[image:HMI Lua Editor user manual_html_34da990820a7a4e5.png||height="208" width="400" class="img-thumbnail"]]
16 16  
17 -== **Script File Area** ==
49 +{{id name="_Toc42782933"/}}{{id name="_Toc14144"/}}{{id name="_Toc22413"/}}**1.1 Script file area**
18 18  
19 19  The script file area is located on the left side, named after the Lua, It will be referred to as the Lua node hereinafter.
20 20  
21 -**Lua Node**
53 +**1.1.1 {{id name="_Toc42782934"/}}{{id name="_Toc2961"/}}Lua node**
22 22  
23 23  ~1. Create new file: right-click the Lua node to select new file, and enter a name in pop-up window, (the name starts with an underscore or letter);
24 24  
... ... @@ -30,9 +30,9 @@
30 30  
31 31  Script_Screen.lua: is a screen script file, and each screen can have initialization, timing, and close functions
32 32  
33 -At any time, as long as there is a new operation, the software will judge whether the above two files exist, and which one is missing will be automatically filled.
65 +{{id name="_Toc5597"/}}{{id name="_Toc42782551"/}}{{id name="_Toc42782582"/}}{{id name="_Toc42782935"/}}{{id name="_GoBack"/}}At any time, as long as there is a new operation, the software will judge whether the above two files exist, and which one is missing will be automatically filled.
34 34  
35 -**Lua Child Node**
67 +**{{id name="_Toc42782936"/}}1.1.2 Lua child node**
36 36  
37 37  After creating a new file, expand the Lua node to display several script files. The following is referred to as child nodes.
38 38  
... ... @@ -63,11 +63,11 @@
63 63  
64 64  **✎Note: **If user forgets the password, the script file can never be recovered, the software will not storage any passwords, developers need to keep the password by themselves carefully.
65 65  
66 -== **Script Editor** ==
98 +{{id name="_Toc42782937"/}}{{id name="_Toc5485"/}}{{id name="_Toc31584"/}}**1.2 Script editor**
67 67  
68 68  The script editor is divided into three blocks: the upper part is the toolbar, the middle part is the editing area, and the lower part is the output area.
69 69  
70 -**Tool Bar**
102 +{{id name="_Toc42782938"/}}{{id name="_Toc24279"/}}**1.2.1 Tool bar**
71 71  
72 72  Open any script file, the toolbar is as follows:
73 73  
... ... @@ -78,7 +78,7 @@
78 78  
79 79  Find and replace, undo and redo and more functions see shortcut keys manual.
80 80  
81 -**Editor Area**
113 +{{id name="_Toc42782939"/}}{{id name="_Toc32765"/}}**1.2.2 Editor area**
82 82  
83 83  **(1) Highlight color:** Lua's built-in keywords has a different color with the Lua interface functions. The functions written by users will not be highlighted
84 84  
... ... @@ -94,11 +94,11 @@
94 94  
95 95  **(7)** **Interface document: **The scripts listed in the interface document will be distinguished by the highlighted color in the editing area. You can check whether the interface is called incorrectly by judging the color change. Detailed description: Lua interface manual.
96 96  
97 -**Output Area**
129 +{{id name="_Toc42782940"/}}{{id name="_Toc25425"/}}**1.2.3 Output area**
98 98  
99 99  Click the syntax button in the toolbar to perform a grammar check. If the script is written incorrectly, it will be displayed in the window. Double-click the prompt to locate the "near" line of the error.
100 100  
101 -= **Lua Object** =
133 +{{id name="_Toc42782941"/}}{{id name="_Toc27350"/}}{{id name="_Toc26670"/}}**2 Lua object**
102 102  
103 103  Lua objects are mainly used to call functions and complete user interface interactions. Normally, functions should not be written in objects. Next, we will explain how to use the objects.
104 104  
... ... @@ -105,7 +105,7 @@
105 105  (% style="text-align:center" %)
106 106  [[image:HMI Lua Editor user manual_html_a9a41fb25f413fec.png||height="317" width="150" class="img-thumbnail"]]
107 107  
108 -== **How to Use Lua Button** ==
140 +{{id name="_Toc42782942"/}}{{id name="_Toc888"/}}{{id name="_Toc26065"/}}**2.1 How to use LuaScrip object**
109 109  
110 110  Find the custom part->LuaScript on the right side, drag and draw to generate a part. Double-click the part to pop up a dialog box.
111 111  
... ... @@ -124,9 +124,9 @@
124 124  
125 125  **Warning:** It is not allowed to write endless loops or call functions that will loop enlessly in the widget. Once used, the entire screen will be stuck, and any buttons will no longer be used. We have to restart the screen to restore.
126 126  
127 -= **Platform** =
159 +{{id name="_Toc42782943"/}}{{id name="_Toc16937"/}}{{id name="_Toc18999"/}}**3 Platform**
128 128  
129 -== **File Header Identification** ==
161 +{{id name="_Toc17954"/}}{{id name="_Toc18609"/}}{{id name="_Toc42782944"/}}**3.1 File header identification**
130 130  
131 131  Any new file will automatically generate a line of code, as shown below:
132 132  
... ... @@ -150,11 +150,11 @@
150 150  
151 151  **✎Note: **If you rename the file manually, you must modify the limits in the file accordingly, otherwise the script file will not take effect.
152 152  
153 -== **Built-In Script File** ==
185 +**{{id name="_Toc42782945"/}}3.2 Special script file**
154 154  
155 155  As mentioned above, the first new build will automatically generate two script files. These two files cannot be deleted and renamed, which will be explained in detail here.
156 156  
157 -~1. **Script_BG.lua** is a global background script file, which includes initialization and polling functions
189 +~1. Script_BG.lua is a global background script file, which includes initialization and polling functions
158 158  
159 159  (% style="text-align:center" %)
160 160  [[image:HMI Lua Editor user manual_html_5eb1ad5776f18955.png||height="148" width="200" class="img-thumbnail"]]
... ... @@ -163,7 +163,7 @@
163 163  
164 164  we_bg_poll():Global polling, that is, the cycle is repeated after power on.
165 165  
166 -Script_Screen.lua is a screen script file, and each screen has an initialization, polling, and closing functions
198 +1. Script_Screen.lua is a screen script file, and each screen has an initialization, polling, and closing functions
167 167  
168 168  (% style="text-align:center" %)
169 169  [[image:HMI Lua Editor user manual_html_e6807eb0da0eedd4.png||height="231" width="300" class="img-thumbnail"]]
... ... @@ -180,7 +180,7 @@
180 180  
181 181  Example: After the screen 0 initialization function is changed to we_scR_init_0(), the script will not be executed when screen 0 is initialized, and then no script will be executed, and nothing will be done because the "we_scr_init_0" function cannot be found.
182 182  
183 -== **Script Type (Operating Mechanism)** ==
215 +{{id name="_Toc42782946"/}}{{id name="_Toc21777"/}}{{id name="_Toc1844"/}}**3.2** **Script type (operating mechanism)**
184 184  
185 185  There are two types of scripts:
186 186