xlua Dll 集成protobuf-c

xlua 最新版没有集合pbc

1、https://github.com/Tencent/xLua 功能目录

2、https://github.com/cloudwu/pbc 

3、在xlua-master 工bulid目录下新建一个luapbc目录

将pbc 目录下的下列文件拷贝过去

pbc文件夹下pbc.h

pbc\src文件夹下所有文件

pbc\binding\lua53文件夹下pbc-lua53.c(这个看lua的版本对应一个就行)

如图

4、配置CMakeLists.txt

#begin lua-protobuf
# 添加所有的c或者cpp文件
set (PROTOBUF_SRC
 luapbc/alloc.c
 luapbc/array.c
 luapbc/bootstrap.c
 luapbc/context.c
 luapbc/decode.c
 luapbc/map.c
 luapbc/pbc-lua53.c
 luapbc/proto.c
 luapbc/register.c
 luapbc/rmessage.c
 luapbc/stringpool.c
 luapbc/varint.c
 luapbc/wmessage.c
 luapbc/pattern.c
)
set_property(
 SOURCE ${PROTOBUF_SRC}
 APPEND
 PROPERTY COMPILE_DEFINITIONS
 LUA_LIB
)

# 头文件目录
list(APPEND THIRDPART_INC  lua-protobuf)
set (THIRDPART_SRC ${THIRDPART_SRC} ${PROTOBUF_SRC})
#end lua-protobuf

5、修改make_win64_lua53.bat

6、查看自己的vs版本

7、如果无法识别Cmake命令则去添加

8、编译生成。如果报错请添加

在 pbc.h 文件里面添加

#ifndef bool
#define bool char
#endif

#ifndef true
#define true 1
#endif

#ifndef false
#define false 0
#endif

在 pbc-lua53.c 修改871行

修改前 int luaopen_protobuf_c(lua_State *L)

修改后 __declspec(dllexport) int luaopen_protobuf_c(lua_State *L)

9、xlua.dll 生成在 xLua-master\build\build64\Release 目录中 查看dll接口

 

10、把编译好的xlua.dll(根据运行的.bat文件找到对应的生成文件)拷贝到unity项目Assets\Plugins下

11、创建 LuaExt.cs  扩展xlua 

using System.Runtime.InteropServices;

namespace XLua.LuaDLL
{
    public partial class Lua
    {   
        //增加lua-protobuf支持
        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
        public static extern int luaopen_protobuf_c(System.IntPtr L);

        [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]
        public static int LoadProtobufC(System.IntPtr L)
        {
            return luaopen_protobuf_c(L);
        }
        增加rapidjson支持
        //[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);
        //}
    }
}

 

12、Init xlua 之前添加我们的扩展

13、lua 文件内 就可识别了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾米神探

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值