简体   繁体   中英

Lua callback function does not work with table

I am trying to change Xadow's baudrate of Uart and trying to do same thing on software PDF but everytime i get errors. I just need to know how should I write the syntax. Here is the guide of the lua software on xadow's writer

config={}
config["bit"]=9
config["par"]=0
config["stop"]=1
config["bdr"]=9600

function uartData(uart_id,len,data)
print(data)
end

uart_id=uart.create(1,uartData(config))
uart_id = uart.create(port, cb_func [,param])

Param is an optional Lua table as described in the documentation.

You have to call:

uart_id = uart.create(1, uartData, config)

not

uart_id = uart.create(1, uartData(config))

uartData(config) would pass the return value of uartData ( nil ) to uart.create instead of the function variable uartData

You can simply wirte config.bit=9 instead of config["bit"]=9 btw.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM