找回密码
 立即注册
查看: 266|回复: 0

Xlua常用第三方库(含rapidjson)

[复制链接]
发表于 2022-1-13 09:36 | 显示全部楼层 |阅读模式
XLua有官方的第三方库集成教程, 这里只是给不愿意折腾编译的小伙伴多一个选择。
下载

Github链接:https://github.com/chexiongsheng/build_xlua_with_libs 下载之后, 替换XLua的Plugins文件夹,里面包含RapidJson、LuaSocket、LPeg、lua-protobuf等
扩展LuaDLL.Lua类

新建一个CS文件,写入如下代码, 这里就以rapidjson为例
using System.Runtime.InteropServices;

namespace XLua.LuaDLL {

    public partial class Lua {

        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
        public static extern int luaopen_rapidjson(System.IntPtr L);

        [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
        public static int LoadRapidJson(System.IntPtr L) {
            return luaopen_rapidjson(L);
        }
    }
}
在合适的位置调用AddBuildin

//笔者是在LuaBehaviour中调用, 做if判断是为了防止重复添加
if (!luaEnv.buildin_initer.ContainsKey("rapidjson")) {               
     luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);            
}
以上步骤弄完之后,记得重启下Unity,要不然可能会报错:EntryPointNotFoundException: luaopen_rapidjson
最后在lua文件中require即可

local rapidJson = require("rapidjson”)附上rapidjson的API文档:https://github.com/xpol/lua-rapidjson/blob/master/API.md
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2025-5-14 12:35 , Processed in 0.446118 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表