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的版本对应一个就行)

如图xlua Dll 集成protobuf-cxlua Dll 集成protobuf-c

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

xlua Dll 集成protobuf-c

5、修改make_win64_lua53.batxlua Dll 集成protobuf-c

6、查看自己的vs版本

xlua Dll 集成protobuf-c

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

xlua Dll 集成protobuf-c

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接口

xlua Dll 集成protobuf-c

 

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 之前添加我们的扩展

xlua Dll 集成protobuf-c

13、lua 文件内 xlua Dll 集成protobuf-c就可识别了。

 

相关文章:

  • 2022-01-02
  • 2021-06-30
  • 2021-12-05
  • 2022-12-23
  • 2021-09-09
  • 2021-08-06
  • 2021-05-10
猜你喜欢
  • 2021-09-17
  • 2022-12-23
  • 2021-10-26
  • 2021-11-11
  • 2022-12-23
  • 2021-08-16
  • 2021-04-09
相关资源
相似解决方案