lua:introduction_to_lua_programming
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
introduction_to_lua_programming [2019/01/09 10:07] – akuzmuk | lua:introduction_to_lua_programming [2021/08/05 13:32] – emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{ :: | ||
====== Introduction to Lua programming ====== | ====== Introduction to Lua programming ====== | ||
WebHMI allows you to create custom programs (scripts) in [[https:// | WebHMI allows you to create custom programs (scripts) in [[https:// | ||
Line 44: | Line 45: | ||
WebHMI imposes the following restrictions on standard Lua functions and libraries: | WebHMI imposes the following restrictions on standard Lua functions and libraries: | ||
- | *such functions and tables are __not available__: | + | * such functions and tables are __not available__: |
- | *libraries are __not available__: | + | * libraries are __not available__: |
- | In addition to the standard Lua functions, WebHMI also defines additional functions which are decsribed | + | In addition to the standard Lua functions, WebHMI also defines additional functions which are described |
- | For the convenience of working with registers from Lua programs, each register can be assigned a symbolic name and be accessed from Lua already | + | For the convenience of working with registers from Lua programs, each register can be assigned a symbolic name and be accessed from Lua with this name. This name is specified in the register settings in the **Script alias** field: |
{{ : | {{ : | ||
- | In the example above, | + | In the example above, |
An example of a simple script that shows the calls of some WebHMI functions: | An example of a simple script that shows the calls of some WebHMI functions: | ||
Line 75: | Line 76: | ||
</ | </ | ||
- | Despite the fact that the built-in editor checks the syntax of the program, it is not able to detect all the errors that can occur during the execution of the script. | + | Despite the fact that the built-in editor checks the syntax of the program, it is not able to detect all the errors that can occur during the execution of the script. |
- | For example, once this script will be executed, an error will occur because variable **random** | + | For example, once this script will be executed, an error will occur because variable **random** |
<code lua> | <code lua> | ||
Line 83: | Line 84: | ||
| | ||
local v1 = GetReg(" | local v1 = GetReg(" | ||
- | v1 = v1+random; -- error is here, without random everything is ok | + | v1 = v1 + random; -- error is here, without random everything is ok |
| | ||
SetReg(" | SetReg(" | ||
Line 100: | Line 101: | ||
</ | </ | ||
- | Here we see that the error occurred while trying to perform an arithmetic operation with an undefined variable (value is **nil**). The error occurred in script | + | Here we see that the error occurred while trying to perform an arithmetic operation with an undefined variable (value is **nil**). The error occurred in script |
- | Thus, using this log you can find all runtime errors in your scripts. Also for debugging you can use watch console window, which is available in script editor. | + | Thus, using this log you can find all runtime errors in your scripts. Also for debugging you can use watch console window, which is available in [[lua: |
lua/introduction_to_lua_programming.txt · Last modified: 2022/01/17 20:58 by 127.0.0.1