This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
niubinghui-luapluginmanage/test/plugin/example_plugin_message.lua

33 lines
1.2 KiB
Lua
Raw Normal View History

2024-09-02 16:10:51 +08:00
function plugin_ctx_new(sess, plug_env, sess_context)
-- print("now create new ctx example message, plugin id", plug_env.id)
end
function plugin_ctx_free(sess, sess_context, plug_env)
-- print("now begin to free ctx context example message")
end
function on_message(sess, topic_id, msg, sess_context, env)
-- print("message call on message function, id", topic_id)
2024-10-08 15:13:06 +08:00
print("get message is", topic_id, msg.data)
2024-09-02 16:10:51 +08:00
end
function plugin_load(stellar, plug_env)
plug_env.st = stellar
2024-09-06 18:57:29 +08:00
plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
2024-09-02 16:10:51 +08:00
plug_env.data = "this is message example plug env data"
--[[ 订阅TOPIC_SESSION_STAT, 并完成函数注册 ]]
2024-10-08 15:13:06 +08:00
test_topic_id = session_mq.get_topic_id(stellar, "LUA_TOPIC_SESSION_STAT")
if (test_topic_id < 0)
then
--[[ 该消息未创建, 创建该topic ]]
test_topic_id = session_mq.create_topic(stellar, "LUA_TOPIC_SESSION_STAT", nil, nil)
print("create topic is", test_topic_id)
end
2024-09-06 18:57:29 +08:00
session_mq.subscribe_topic(stellar, test_topic_id, on_message, plug_env.id)
2024-09-02 16:10:51 +08:00
end
function plugin_unload(plug_env)
print("now unload lua plugin example message")
print("plugin env data is", plug_env.data)
end