前一节,我们测试了luaBridge的基本用法,使用luaBridge向C++程序添加脚本插件能力1(编译与使用)_飞鸟真人的博客-优快云博客
但是还有问题需要解决,比如,我们的插件设计一般还是比较复杂的,举例说比如我们要做一个HTTP下载
业务相关的插件,我们需要向LUA脚本暴露如下几个类:
HttpHeader
HttpClient
Json
HtmlDom
RawFile
我们脚本的使用方式类似如下:
author = "Robin.Fox"
version = 42
setting = {
name = "XX下载脚本",
dir = "d:\\"
}
function lua_main(a, b)
printMessage("====>\nYou are using are demo script to show spider lua script works...")
printMessage("now dir is:" .. setting.dir)
header = HttpHeader()
header:SetItem("cookie", "asafafafafaf")
header:SetItem("dateType", "json")
client = HttpClient()
code = client:Get("http://asfa", header)
printMessage("get return " .. code)
printMessage("=======<\n")
return a + b
end

本文介绍了如何使用LuaBridge为C++程序扩展类功能,以实现更复杂的脚本插件设计。示例中展示了为HTTP下载业务创建相关类并注册到LUA脚本的过程,强调了只能注册一个构造函数以及保持注册方法参数类型一致的重要性。
最低0.47元/天 解锁文章
1307

被折叠的 条评论
为什么被折叠?



