# 9.6 Lua Script Interfaces

**1.Data format**

void //void

double //floating number

int //signed integer

uint //unsinged integer

string //string

table //table

bool //false or true

multi // Multiple return values (see the description of "Return" for details)

**2.Lua built-in function library**

The built-in functions mentioned below could be used, the rest cannot be used

All available:

Mathematics, string, table, file io, UTF8, etc.

Partially available:

System type os (only includes clock, date, difftime, remove, rename, time)

**3.File IO**

&#x20;As long as the file is not closed during the use of the write function, what is written is temporarily stored in the RAM space. If the cumulative number of written bytes is about 60% of the RAM size, the program will be crashed. For example, the HMI memory size is 128M, and written byte is about 70M. The operating memory space required by the system itself, then a total of 90% of the total memory is occupied, the program will be killed (that is, the screen will freeze).

&#x20;The space of the internal Flash is limited. Once the internal space is full, files cannot be written. If you need to operate large files, they must be handled separately, you can read and write files through an external U disk.

**4.Table**

&#x20;Lua tables can implement various data structures, such as stacks, queues, and trees. The size of the table needs to be controlled during use, because the RAM size of the HMI is limited. Using a loop to create a table array with nearly endless elements results in excessive memory usage, thus the program wil be killed (that is, the screen freezes) . Below is an example.

&#x20;local t = {}

&#x20;for i=1, math.maxinteger do

&#x20;table.insert(t, math.random(100000, 9999999))

&#x20;end

**5.Lua supports bit operation**

&#x20;**&**: Bitwise and

&#x20;**|**: Bitwise or

&#x20;**\~**: Bitwise XOR

&#x20;**>>**: right shift

&#x20;**<<**: left shift

&#x20;**\~**: bitwise not

## Chapter 1 Public function

&#x20;A large number of operations to read and write external addresses will slow down the running speed of the script, such as calling we\_bas\_setword("xx", 1) 100 times, it may take a few seconds to run.

### we\_atu8

string we\_atu&#x38;**(**&#x73;tring st&#x72;**)**

/\*

&#x20;\*Function：Convert ANSI character set string to utf8 character set string

&#x20;\*Parameter：

&#x20;\* str String of ANSI character set

&#x20;\*Return：String of Utf-8 character set

&#x20;\*/

### we\_u8ta

string we\_u8t&#x61;**(**&#x73;tring st&#x72;**)**

/\*

&#x20;\*Function：Convert utf8 character set string to ANSI character set string，

&#x20;\*Parameter：

&#x20;\* str String of Utf-8 character set

&#x20;\*Return：String of ANSI character set

&#x20;\*/

### we\_bas\_getshort

multi we\_bas\_getshort(string address, int type)

/\*

&#x20;\*Function：Read single word signed decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = 1 means read thorough)

&#x20;\*Return：single word signed decimal value Read correctly

&#x20;\* multi Return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setshort

multi we\_bas\_setshort(string address, int value, int type)

/\*

&#x20;\*Function：Write value to a single word signed decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = 1 means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi Return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getword

multi we\_bas\_getword(string address, int type)

/\*

&#x20;\*Function：Read single word unsigned decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：Word unsigned decimal value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setword

multi we\_bas\_setword(string address, uint value, int type)

/\*

&#x20;\*Function：Write a single word unsigned decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getint

multi we\_bas\_getint(string address, int type)

/\*

&#x20;\*Function：Read double word signed decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：Double word signed decimal value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setint

multi we\_bas\_setint(string address, int value, int type)

/\*

&#x20;\*Function：Write double-word signed decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getdword

multi we\_bas\_getdword(string address, int type)

/\*

&#x20;\*Function：Read double word unsigned decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：Double word unsigned decimal value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setdword

multi we\_bas\_setdword(string address, uint value, int type)

/\*

&#x20;\*Function：Write double word unsigned decimal address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getbit

multi we\_bas\_getbit(string address, int type)

/\*

&#x20;\*Function：Read a bit of the register address

&#x20;\*Parameter：

&#x20;\* address internal bit address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：bit address value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setbit

multi we\_bas\_setbit(string address, uint value, int type)

/\*

&#x20;\*Function：Write a bit of the register address

&#x20;\*Parameter：

&#x20;\* address internal bit address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getfloat

multi we\_bas\_getfloat(string address, int type)

/\*

&#x20;\*Function：Read 32-bit floating point address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：32-bit floating point value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setfloat

multi we\_bas\_setfloat(string address, double value, int type)

/\*

&#x20;\*Function：Write 32-bit floating point address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getdouble

multi we\_bas\_getdouble(string address, int type)

/\*

&#x20;\*Function：Read 64-bit floating point address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：64-bit floating point value read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setdouble

multi we\_bas\_setdouble(string address, double value, int type)

/\*

&#x20;\*Function：Write 64-bit floating point address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* type type(no need to set，type = means read thorough)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getstring

multi we\_bas\_getstring(string address, uint len)

/\*

&#x20;\*Function：Read the specified length string \*Parameter：

&#x20;\* address address

&#x20;\* len length（unit：byte）

&#x20;\*Return：Specify length string read correctly

&#x20;\* multi return values（nil and error message） read error

&#x20;\*/

### we\_bas\_setstring

multi we\_bas\_setstring(string address, string str, uint len)

/\*

&#x20;\*Function：write string

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* str string

&#x20;\* len length(no need to set，the default setting is the number of bytes in the string)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_gettickcount

uint we\_bas\_gettickcount()

/\*

&#x20;\*Function：Get the time(millisecond) it takes to start the OS

&#x20;\*Parameter：

&#x20;\* none

&#x20;\*Return：Return the time it takes to start the OS

&#x20;\*/

### we\_bas\_sleep

void we\_bas\_sleep(uint millisecond)

/\*

&#x20;\*Function：sleep

&#x20;\*Parameter：

&#x20;\* millisecond Sleep milliseconds

&#x20;\*Return：none

&#x20;\*/

### we\_bas\_bmov

multi we\_bas\_bmov(string desAddress, string srcAddress, uint len)

/\*

&#x20;\*Function：Copy data with specified length from source address to destination address

&#x20;\*Parameter：

&#x20;\* desAddress target address

&#x20;\* srcAddress source address

&#x20;\* len Specified length (unit: word)

&#x20;\*Return：TRUE copy successfully

&#x20;\* multi return values（nil and error message） copy error

&#x20;\*/

### print

void print(constchar \*format, \[argument])

/\*

&#x20;\*Function：Print debugging information in the debugging window

&#x20;\*Parameter：

&#x20;\* format，\[argument] print Parameter format

&#x20;\*Return：none

&#x20;\*/

### we\_bas\_fill

multi we\_bas\_fill(string address, int value, uint len)

/\*

&#x20;\*Function：Assign the same value to consecutive addresses

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* value value

&#x20;\* len Continuous length (unit: words)

&#x20;\*Return：TRUE set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_beep

void we\_bas\_beep()

&#x20;/\*

&#x20;\*Function：beep

&#x20;\*Parameter：

&#x20;\* none

&#x20;\*Return：none

&#x20;\*/

### we\_bas\_newnoaddr

multi we\_bas\_newnoaddr(string address, uint len)

/\*

&#x20;\*Function：offset address

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* len length

&#x20;\*Return：the address after offset set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_newstataddr

multi we\_bas\_newstataddr(string address， uint len)

/\*

&#x20;\*Function：offset station number

&#x20;\*Parameter：

&#x20;\* address address

&#x20;\* len length

&#x20;\*Return：the address after offset set correctly

&#x20;\* multi return values（nil and error message） set error

&#x20;\*/

### we\_bas\_getscriptpath

multi we\_bas\_getscriptpath()

/\*

&#x20;\*Function：get script path

&#x20;\*Parameter： none

&#x20;\*Return：script path get successfully

&#x20;\* multi return values（nil and error message） get error

&#x20;\*/

### we\_bas\_getcustompath

string we\_bas\_getcustompath()

/\*

&#x20;\*Function：Get user-defined folder path

&#x20;\*Parameter： none

&#x20;\*Return：data path

&#x20;\*/

### we\_bas\_getusbpath

multi we\_bas\_getusbpath()

/\*

&#x20;\*Function：get u disk path

&#x20;\*Parameter： none

&#x20;\*Return：U disk path get successfully

&#x20;\* multi return values（nil and error message） get error

&#x20;\*/

### we\_bas\_getsdpath

multi we\_bas\_getsdpath()

/\*

&#x20;\*Function：get SD card path

&#x20;\*Parameter： none

&#x20;\*Return：SD card path get successfully

&#x20;\* multi return values（nil and error message） get error

&#x20;\*/

### we\_bas\_file\_exist

bool we\_bas\_file\_exist(string path)

/\*

&#x20;\*Function: judge whether there is a file

&#x20;\*Parameter： path file path

&#x20;\*Return：true exist

&#x20;\* false not exist

&#x20;\*/

### we\_bas\_path\_exist

bool we\_bas\_path\_exist(string path)

/\*

&#x20;\*Function：judge whether there is a folder

&#x20;\*Parameter： path folder path

&#x20;\*Return：true exist

&#x20;\* false not exist

&#x20;\*/

### we\_bas\_jumpscreen

bool we\_bas\_jumpscreen(uint id)

/\*

&#x20;\*Function：main screen jump

&#x20;\*Parameter：id screen id

&#x20;\*Return：true jump successfully

&#x20;\* false jump error

&#x20;\*/

### we\_bas\_popscreen

bool we\_bas\_popscreen **(**&#x69;nt scrn&#x6F;**,**&#x69;nt &#x78;**,** int &#x79;**)**

/\*

&#x20;\*Function：Sub-screen pops up, if the built-in screen like keyboard pops up, the screen cannot be used

&#x20;\*Parameter：

&#x20;\* scrno Screen number of the sub screen

&#x20;\* x The x coordinate

&#x20;\* y The y coordinate

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

### we\_bas\_closescreen

bool we\_bas\_closescreen **(**&#x69;nt scrn&#x6F;**)**

/\*

&#x20;\*Function：close subscreen

&#x20;\*Parameter：

&#x20;\* scrno Screen number of the sub screen

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

&#x20;\*

## Chapter 2 Object operation function

### 2.1 we\_part\_setstate

bool we\_part\_setstat&#x65;**(**&#x73;tring partNam&#x65;**,** string valu&#x65;**)**

/\*

&#x20;\*Function：Set the state of the object according to the object name (for bit lamp, bit switch, word switch, LUA script object)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\* value the set value

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：If object has an address, then the operation address is the monitoring address;

&#x20;\* If object doesn’t have an address, then the operation address is the internal address;

&#x20;\* The “parameter value” should be the original data

&#x20;\*/

### 2.2 we\_part\_getstate

string we\_part\_getstat&#x65;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：get the value of object（for bit lamp, bit switch, word switch, lua script object）

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* objet value success

&#x20;\* nill failure

\*Note：If object has an address, then the operation address is the monitoring address;

&#x20;\* If object doesn’t have an address, then the operation address is the internal address;

&#x20;\* The “parameter value” must be the original data

\*/

### 2.3 we\_part\_settchenable

bool we\_part\_settchenabl&#x65;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Set to allow parts to be clicked (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

\*/

### 2.4 we\_part\_settchunable

bool we\_part\_settchunabl&#x65;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Set to not allow parts to be clicked (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

\*/

### 2.5 we\_part\_gettchstate

bool we\_part\_gettchstat&#x65;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Get whether the part is allowed to be clicked (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true allowed

&#x20;\* false not allowed

&#x20;\* nill failure

&#x20;\*Note：

&#x20;\*/

### 2.6 we\_part\_sethidestate

bool we\_part\_sethidestat&#x65;**(**&#x73;tring partNam&#x65;**,** int valu&#x65;**)**

/\*

&#x20;\*Function：Set part hidden attribute (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\* value the set value

&#x20;\* 0：Dispaly or hide according to part control address

&#x20;\* 1：Just display and not affected by the control address

&#x20;\* 2：Just hide and affected by the control address

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

### 2.7 we\_part\_gethidestate

bool we\_part\_gethidestat&#x65;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Get hidden attributes of parts (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true hidden

&#x20;\* false display

&#x20;\* nill failure

&#x20;\*Note：

&#x20;\*/

### 2.8 we\_part\_clickdown

bool we\_part\_clickdow&#x6E;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Send click-down command messages to specified parts (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

### 2.9 we\_part\_clickup

bool we\_part\_clicku&#x70;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Send click-up command messages to specified parts (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

### 2.10 we\_part\_setcurrc

bool we\_part\_setcurr&#x63;**(**&#x73;tring partNam&#x65;**,** int Lef&#x74;**,** int To&#x70;**,** int Righ&#x74;**,** int Botto&#x6D;**)**

/\*

&#x20;\*Function：Set the contour information of the part (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\* Left coordinate of the left side of the part

&#x20;\* Top coordinate of the top side of the part

&#x20;\* Right Coordinates of the right side of the part

&#x20;\* Bottom coordinate of the bottom side of the part

&#x20;\*Return：

&#x20;\* true success

&#x20;\* false failure

&#x20;\*Note：

&#x20;\*/

### 2.11 we\_part\_getcurrc

multi we\_part\_getcurr&#x63;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Get the outline information of the part (for all parts have this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* Left nill: Execution error

&#x20;\* not nill(int):coordinate of the left side of the part

&#x20;\* Top nill: Execution error

&#x20;\* not nill(int):coordinate of the top side of the part

&#x20;\* Right nill: Execution error

&#x20;\* not nill(int):Coordinates of the right side of the part

&#x20;\* Bottom nill: Execution error

&#x20;\* not nill(int):coordinate of the bottom side of the part

&#x20;\*Note：

&#x20;\*/

### 2.12 we\_part\_getoriginalrc

multi we\_part\_getoriginalr&#x63;**(**&#x73;tring partNam&#x65;**)**

/\*

&#x20;\*Function：Get contour information of the part (for all parts with this attribute)

&#x20;\*Parameter：

&#x20;\* partName object name

&#x20;\*Return：

&#x20;\* Left nill: Execution error

&#x20;\* not nill(int):Coordinates of the left side of the part

&#x20;\* Top nill: Execution error

&#x20;\* not nill(int):coordinate of the top side of the part

&#x20;\* Right nill: Execution error

&#x20;\* not nill(int):coordinate of the right side of the part

&#x20;\* Bottom nill: Execution error

&#x20;\* not nill(int):coordinate of the bottom side of the part

&#x20;\*Note：

&#x20;\*/

## Chapter 3 lfs operation library functions

**Declare**: The following lists only some of the functions of the lfs library, and others that are not mentioned in the document are unavailable. For details, see <http://math2.org/luasearch/lfs.html>.

### 3.1 lfs.attributes

table lfs.attributes(string filePath \[, aname])

/\*

&#x20;\*Function：Get a table with file attributes corresponding to the file path, if the second parameter is given, only the value of the named attribute is returned

&#x20;\*Parameter：

&#x20;\* filePath given path

&#x20;\* aname attribute（optional）

&#x20;\*Return：Return a table get successfully

&#x20;\* nil get error

&#x20;\*/

### 3.2 lfs.currentdir

string lfs.currentdir()

/\*

&#x20;\*Function：Get current working directory

&#x20;\*Parameter：

&#x20;\* none

&#x20;\*Return：Return path get successfully

&#x20;\* nil get error

&#x20;\*/

### 3.3 lfs.dir

string lfs.dir(string path)

/\*

&#x20;\*Function：go through current directory to get file name

&#x20;\*Parameter：

&#x20;\* path Current directory path

&#x20;\*Return：Return file name get successfully

&#x20;\* nil get error

&#x20;\*/

### 3.4 lfs.mkdir

bool lfs.mkdir(string dirName)

/\*

&#x20;\*Function：Create Folder

&#x20;\*Parameter：

&#x20;\* dirName Folder name

&#x20;\*Return： TRUE Operation correct

&#x20;\* nil Operation error

&#x20;\*/

### 3.5 lfs.rmdir

bool lfs.rmdir(string dirName)

/\*

&#x20;\*Function：remove folder

&#x20;\*Parameter：

&#x20;\* dirName folder name

&#x20;\*Return： TRUE operation correct

&#x20;\* nil operation error

&#x20;\*/


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wecon.gitbook.io/pistudio-manual/9.-scripts/lua-script/lua-script-interfaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
