0
回答
emqtt_lua_hook开发问题
华为云实践训练营,热门技术免费实践!>>>   

@emqtt 你好,想跟你请教个问题:

在lua_hook中,想使用cjson这个so包时报错,请问为什么在hook中无法加载so包?

emqttd/hook_lua/test.lua

package.path = "/usr/local/emqttd/hook_lua/include/?.lua;"
package.cpath = '/usr/local/emqttd/hook_lua/include/?.so;'
cjson = require "cjson"

function on_message_publish(clientid, username, topic, payload, qos, retain)
    msg = cjson.decode(payload)
    if msg["cmd"] == "test" then
        return topic, payload, qos, retain
    else 
        return false
    end   
end

function register_hook()
    return "on_message_publish"
end

而在外部lua脚本内使用cjson没有问题

test.lua

package.path = "/usr/local/emqttd/hook_lua/include/?.lua;"
package.cpath = '/usr/local/emqttd/hook_lua/include/?.so;'
cjson = require "cjson"

jsonStr =[[{"cmd":"test","title":"test message","content":"this is a test message."}]]
data = cjson.decode(jsonStr)
print(data["cmd"])

[root@localhost t1]# lua test.lua 
test

举报
skypeng123
发帖于2个月前 0回/22阅
顶部