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 文件内 就可识别了。