Changes for page 09 Lua Editor

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

From version 5.1
edited by Stone Wu
on 2022/08/08 10:34
Change comment: There is no comment for this version
To version 4.10
edited by Hunter
on 2022/07/29 15:01
Change comment: Update document after refactoring.

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Stone
1 +XWiki.Hunter
Content
... ... @@ -14,22 +14,24 @@
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 ==
17 +== **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 21  **Lua Node**
22 22  
23 -* 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 -* Refresh list: the file edited (new/deleted/renamed) by the user externally, the configuration is not refreshed. In this case this function needs to be used to synchronize changes;
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);
25 25  
26 -**✎Note: **
25 +2.Refresh list: the file edited (new/deleted/renamed) by the user externally, the configuration is not refreshed. In this case this function needs to be used to synchronize changes;
27 27  
28 -* There is no script file for the newly created project. Following two new files will automatically generate.
29 -* Script_BG.lua: is the global background script file, which includes initialization and timing functions
30 -* Script_Screen.lua: is a screen script file, and each screen can have initialization, timing, and close functions
31 -* 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.
27 +**✎Note: **There is no script file for the newly created project. Following two new files will automatically generate.
32 32  
29 +Script_BG.lua: is the global background script file, which includes initialization and timing functions
30 +
31 +Script_Screen.lua: is a screen script file, and each screen can have initialization, timing, and close functions
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.
34 +
33 33  **Lua Child Node**
34 34  
35 35  After creating a new file, expand the Lua node to display several script files. The following is referred to as child nodes.
... ... @@ -37,26 +37,31 @@
37 37  (% style="text-align:center" %)
38 38  [[image:HMI Lua Editor user manual_html_fc10128583a230da.png||height="143" width="200" class="img-thumbnail"]]
39 39  
40 -* Child node color description:
41 -* Red: encrypted file
42 -* Yellow: read-only file
43 -* Green: existed file or refresh the list to turn white to green
44 -* White: The newly created file, and the project will turn green after refreshing, protecting or reopening the project
42 +Child node color description:
45 45  
46 -**Delete:** right-click the child node to delete. The deleted node will be placed in the recycle bin.
44 +Red: encrypted file
47 47  
48 -**Rename: **right-click child node to rename.
46 +Yellow: read-only file
49 49  
50 -**Encryption:** right-click the child node, select encryption. Each file can be set with an independent password(length 1-6, only uppercase/lowercase letters and numbers are accepted).
48 +Green: existed file or refresh the list to turn white to green
51 51  
52 -* Encryption mode: When this mode is turned on, you need to verify the password to view and edit.
53 -* Read-only mode: This mode is opened without verifying the password, if you want to edit, you must first release the protection
50 +White: The newly created file, and the project will turn green after refreshing, protecting or reopening the project
54 54  
55 -**Unprotect:** Right-click on the child node, select Unprotect, enter the password to release.
52 +**(1) Delete:** right-click the child node to delete. The deleted node will be placed in the recycle bin.
56 56  
54 +**(2)** **Rename: **right-click child node to rename.
55 +
56 +**(3) Encryption:** right-click the child node, select encryption. Each file can be set with an independent password(length 1-6, only uppercase/lowercase letters and numbers are accepted).
57 +
58 +Encryption mode: When this mode is turned on, you need to verify the password to view and edit.
59 +
60 +Read-only mode: This mode is opened without verifying the password, if you want to edit, you must first release the protection
61 +
62 +**(4) Unprotect:** Right-click on the child node, select Unprotect, enter the password to release.
63 +
57 57  **✎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.
58 58  
59 -== Script editor ==
66 +== **Script Editor** ==
60 60  
61 61  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.
62 62  
... ... @@ -73,14 +73,20 @@
73 73  
74 74  **Editor Area**
75 75  
76 -* **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
77 -* **Auto-complete:** Lua function auto-complete prompts, Lua chunk auto-complete (such as if xx then end), also supports the completion of all the words in this script file. Use the Enter key to select candidates words, use the Tab key to turn off automatic completion.
78 -* **Automatic indentation: **The tab key can add 4 spaces
79 -* **Calling prompt:** only available for Lua interface functions
80 -* **Hovering hint:** for example the mouse stays near the o letter position of demo() , it will display the prototype of the function
81 -* **(6)** **Shortcut keys:** In order to facilitate users, various shortcut keys have been added. Detailed description: Configure Lua shortcut keys.doc
82 -* **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.
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
83 83  
85 +**(2)** **Auto-complete:** Lua function auto-complete prompts, Lua chunk auto-complete (such as if xx then end), also supports the completion of all the words in this script file. Use the Enter key to select candidates words, use the Tab key to turn off automatic completion.
86 +
87 +**(3) Automatic indentation: **The tab key can add 4 spaces
88 +
89 +**(4) Calling prompt:** only available for Lua interface functions
90 +
91 +**(5) Hovering hint:** for example the mouse stays near the o letter position of demo() , it will display the prototype of the function
92 +
93 +**(6)** **Shortcut keys:** In order to facilitate users, various shortcut keys have been added. Detailed description: Configure Lua shortcut keys.doc
94 +
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 +
84 84  **Output Area**
85 85  
86 86  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.
... ... @@ -92,7 +92,7 @@
92 92  (% style="text-align:center" %)
93 93  [[image:HMI Lua Editor user manual_html_a9a41fb25f413fec.png||height="317" width="150" class="img-thumbnail"]]
94 94  
95 -== How to use Lua button ==
108 +== **How to Use Lua Button** ==
96 96  
97 97  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.
98 98  
... ... @@ -101,18 +101,19 @@
101 101  
102 102  Click Lua object will trigger two actions, that is, rising and falling scripts;
103 103  
104 -* **Falling script**: after the button is pressed, the code chunk of the area is executed;
105 -* **Rising script**: after the button is raised, the code chunk in the area is executed;
106 -* **Timing script**: periodically execute the code.
117 +**(1)** **Falling script**: after the button is pressed, the code chunk of the area is executed;
107 107  
108 -**✎Note: **
119 +**(2) Rising script**: after the button is raised, the code chunk in the area is executed;
109 109  
110 -* The timing script is not commonly used because it is similar to the screen background script function. It is not recommended to write and call function here. It should be written in Script_Screen.lua, which is convenient for editing, searching, and replacing operations.
111 -* 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.
121 +**(3)** **Timing script**: periodically execute the code.
112 112  
123 +**✎Note: **The timing script is not commonly used because it is similar to the screen background script function. It is not recommended to write and call function here. It should be written in Script_Screen.lua, which is convenient for editing, searching, and replacing operations.
124 +
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 +
113 113  = **Platform** =
114 114  
115 -== File header identification ==
129 +== **File Header Identification** ==
116 116  
117 117  Any new file will automatically generate a line of code, as shown below:
118 118  
... ... @@ -126,52 +126,62 @@
126 126  (% style="text-align:center" %)
127 127  [[image:HMI Lua Editor user manual_html_52fb935bcc76d7ad.png||height="113" width="203" class="img-thumbnail"]]
128 128  
129 -* **_limits: **Fixed format, cannot be modified
130 -* **Description**:
131 -* **Tens digit=1**: indicates that the function or global variable defined in this file can be used in the background code file (Script_BG.lua). If it is 0, it is not available.
132 -* **Ones digit=1**: indicates that the functions or global variables defined in this file can be used in the screen code file (Script_Screen.lua) or LuaScript components. If it is 0, it is not available.
143 +**_limits**:Fixed format, cannot be modified
133 133  
145 +**Description**:
146 +
147 +**Tens digit=1**:indicates that the function or global variable defined in this file can be used in the background code file (Script_BG.lua). If it is 0, it is not available.
148 +
149 +**Ones digit=1**:indicates that the functions or global variables defined in this file can be used in the screen code file (Script_Screen.lua) or LuaScript components. If it is 0, it is not available.
150 +
134 134  **✎Note: **If you rename the file manually, you must modify the limits in the file accordingly, otherwise the script file will not take effect.
135 135  
136 -== Built-In script file ==
153 +== **Built-In Script File** ==
137 137  
138 138  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.
139 139  
140 -**Script_BG.lua** is a global background script file, which includes initialization and polling functions
157 +~1. **Script_BG.lua** is a global background script file, which includes initialization and polling functions
141 141  
142 142  (% style="text-align:center" %)
143 143  [[image:HMI Lua Editor user manual_html_5eb1ad5776f18955.png||height="148" width="200" class="img-thumbnail"]]
144 144  
145 -* we_bg_init(): global initialization, that is, execute once when power on.
146 -* we_bg_poll(): Global polling, that is, the cycle is repeated after power on.
162 +we_bg_init(): global initialization, that is, execute once when power on.
147 147  
164 +we_bg_poll():Global polling, that is, the cycle is repeated after power on.
165 +
148 148  Script_Screen.lua is a screen script file, and each screen has an initialization, polling, and closing functions
149 149  
150 150  (% style="text-align:center" %)
151 151  [[image:HMI Lua Editor user manual_html_e6807eb0da0eedd4.png||height="231" width="300" class="img-thumbnail"]]
152 152  
153 -* we_scr_init_0(): execute this function when screen 0 is initialized
154 -* we_scr_poll_0(): when in picture 0, the function is executed repeatedly
155 -* we_scr_close_0(): execute this function when screen 0 is closed
171 +we_scr_init_0(): execute this function when screen 0 is initialized
156 156  
173 +we_scr_poll_0(): when in picture 0, the function is executed repeatedly
174 +
175 +we_scr_close_0(): execute this function when screen 0 is closed
176 +
157 157  The above is the initialization function of screen 0. For screen 100, you can replace 0 with 100. You can add your own function: function we_scr_init_100() end
158 158  
159 159  **✎Note: **The above function has a fixed name. If it is modified, it will not cause crash, but the function can be found.
160 160  
161 -**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.
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.
162 162  
163 -== Script type (operating mechanism) ==
183 +== **Script Type (Operating Mechanism)** ==
164 164  
165 165  There are two types of scripts:
166 166  
167 -* Active: script automatically executed by HMI
168 -* Passive: Script executed only after user trigger
187 +Active: script automatically executed by HMI
169 169  
189 +Passive: Script executed only after user trigger
190 +
170 170  The active types includes:
171 171  
172 -* Global _bg_ related functions in Script_BG.lua
173 -* Screen _scr_ related functions in Script_Screen.lua
193 +Global _bg_ related functions in Script_BG.lua
174 174  
195 +Screen _scr_ related functions in Script_Screen.lua
196 +
175 175  Polling script in Lua object
176 176  
177 -The passive type scripts include: The rising and falling script in Lua object.
199 +The passive type scripts include:
200 +
201 +The rising and falling script in Lua object.