【问题标题】:How do I solve the "attempt to call a table value" runtime error on lua?如何解决lua上的“尝试调用表值”运行时错误?
【发布时间】:2023-04-05 17:09:02
【问题描述】:

我正在编写一个将 IO Link 数据转换为 MQTT 的 lua 脚本。当我调试脚本时,我在函数 client:register 上遇到了以下运行时错误: 运行时错误:尝试调用表值(全局“字符串”)

我知道在需要的 3 个参数中,事件名称必须是字符串。来自Java,我尝试直接在函数中转换它。它看起来像这样:

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

它仍然不起作用。 有人知道如何解决这个问题吗?

您好。

【问题讨论】:

  • 什么是IOhandleOnDisconnected?提供更多上下文,否则我们无法帮助您解决问题
  • 你的意思是tostring吗?
  • IOhandleOnDisconnected 是指在与 IO Link 设备的连接中断时调用的函数。该函数的代码是:local function IOhandleOnDisconnected() gTimer:stop() print('[IO-Link 2 MQTT] IO-Link device disconnected.') end client:register( deviceHandle, string(IOhandleOnDisconnected) , IOhandleOnDisconnected )

标签: lua


【解决方案1】:

string 是 Lua 用于字符串操作的标准库。这是一个 Lua 表,不能像您在 string(IOhandleOnDisconnected) 中所做的那样调用

【讨论】:

    猜你喜欢
    • 2023-02-07
    • 2015-10-18
    • 2011-07-30
    • 1970-01-01
    • 2015-05-09
    • 2013-07-06
    • 1970-01-01
    • 2019-01-06
    • 2015-06-15
    相关资源
    最近更新 更多