报错/usr/lib/lua/luci/controller/admin/behave_audit.lua:92: bad argument #2 to 'remove' (integer expected, got string)
时间: 2023-07-05 07:35:12 浏览: 350
这个错误信息表明在 `/usr/lib/lua/luci/controller/admin/behave_audit.lua` 文件的第 92 行调用了 `table.remove()` 函数,并且传入了一个字符串作为第二个参数,但是 `table.remove()` 函数的第二个参数必须为整数类型。
因此,你需要检查一下 `/usr/lib/lua/luci/controller/admin/behave_audit.lua` 文件的第 92 行代码,确保 `table.remove()` 函数的第二个参数为整数类型。
在 Lua 中,table 中的元素是通过整数索引访问的,因此 `table.remove()` 函数的第二个参数应该是要删除元素的索引位置。如果你想删除 table 中的某个键值对,应该使用 `table[key] = nil` 语法,而不是 `table.remove()` 函数。
如果你需要更多帮助,请提供 `/usr/lib/lua/luci/controller/admin/behave_audit.lua` 文件的代码,以便我更好地帮助你解决问题。
相关问题
报错/usr/lib/lua/luci/controller/admin/behave_audit.lua:90: attempt to call method 'remove' (a nil value)
在 Lua 中,当调用一个方法时,如果该对象为 `nil`,就会出现类似“attempt to call method 'remove' (a nil value)”这样的错误。根据错误提示,可以看到是在第 90 行代码中调用了一个 `remove` 方法,但是该方法是一个 `nil` 值,也就是说该方法不存在或者被定义为 `nil`。
根据我们之前的代码修改,可以看出是在 `section` 对象上调用了 `remove` 方法,但是该对象并没有定义 `remove` 方法。因此,我们需要将 `section` 对象转换为 UCI `cursor` 对象,然后在 UCI `cursor` 对象上调用 `delete` 方法来删除 `log_send_enable` 配置项。修改后的代码如下所示:
```lua
function get_behave_audit_info(filter, uciname, secname, para)
dbg("get_behave_audit_info")
local uci_r = uci.cursor()
local result = {}
uci_r:foreach("behave_audit", "behave_audit",
function(section)
section["log_send"] = section["log_send_enable"]
uci_r:delete("behave_audit", section[".name"], "log_send_enable")
result[#result + 1] = section
end
)
return err.ENONE, result
end
```
修改后的代码将 `section` 对象的 `remove` 方法改为了 UCI `cursor` 对象的 `delete` 方法,同时传递了 `behave_audit`、`section[".name"]` 和 `log_send_enable` 三个参数来指定要删除的配置项。
阅读全文
相关推荐
















