1
votes

I'm working on a lua script to convert IO Link data into MQTT. When I debugged the script, I got following runtime error on the function client:register : Runtime error: attempt to call a table value (global 'string')

I understood that out of the 3 parameters needed, the eventname has to be in string. Coming from Java, I tried converting it directly in the function. It looks like this:

client:register( deviceHandle, string(IOhandleOnDisconnected) , IOhandleOnDisconnected )

It still does not work though. Does anybody have an idea how to fix this?

Greetings.

1
what is IOhandleOnDisconnected? provide more context or we cannot help you fix it - Piglet
Do you mean tostring instead? - lhf
IOhandleOnDisconnected is meant to be the function that is called if the connection to the IO Link device is interrupted. The code to the function is: local function IOhandleOnDisconnected() gTimer:stop() print('[IO-Link 2 MQTT] IO-Link device disconnected.') end client:register( deviceHandle, string(IOhandleOnDisconnected) , IOhandleOnDisconnected ) - WhatIsProtocoll

1 Answers

1
votes

string is Lua's standard library for string manipulation. It is a Lua table which cannot be called as you did in string(IOhandleOnDisconnected)