Skip to content

hxhb/unlua-pb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

What is this?

这是集成lua-ptorobuf到Unlua的Module。基于392ace3

Usage

  1. 把本仓库clone之后放到Unlua的ThirdParty下;
  2. UnLua.uplugin中的Modules下添加如下内容:
{
  "Name": "LuaProtobuf",
  "Type": "Runtime",
  "LoadingPhase": "Default"
}
  1. 在Unlua的build.cs中添加LuaProtobuf模块依赖;
  2. UnluaLuaContext.cpp中的FLuaContext::CreateState函数中调用FLuaProtobuf::RegisterLuaLib即可。
FLuaProtobuf& LuaProtobuf = FModuleManager::LoadModuleChecked<FLuaProtobuf>(TEXT("LuaProtobuf"));
LuaProtobuf.RegisterLuaLib(L);

模块注册时已经把protoc.luaserpent.lua都添加了,不需要再把他们放到Content/Script下。

注意:lua-protobuf官方版本在ue中当使用pb.loadfile的时候会用问题,它直接使用了fopen来打开传入的文件路径,这样不会基于ue的ufs来查找文件,所以会找不到pak里的文件,需要把lpb_loadfile这部分给改了,本项目内我已经修改支持,使用pb.loadufsfile即可。

pb.loadufsfile应该传递的是FPaths::ProjectContentDir() + proto文件相对于Content的路径,如FPaths::Combine(FPaths::ProjectContentDir(),TEXT("Script/Msg.pb"))。不过FPaths::Combine这个函数在UnLua官方版本里没有导出,我在debugable-unlua里导出了。

注意:pb.loadufsfile只能用来加载*.pb的文件,不能用来加载*.protoc的文件。 *pb可以通过protobuf中的protoc.exe来生成:

protoc.exe -o Msg.pb Msg.protoc

如果想要直接加载*.protoc的文本可以通过下列方法:

local filepath = UE4.FPaths.Combine(FPaths.ProjectContentDir(),"Script/TestMsg.proto")
local protoContent = UE4.FFileHelper.LoadFileToArray(filepath)
protoc:load(protoContent)

UnLua官方版本没有导出UE4.FFileHelper.LoadFileToArray这个符号到lua,我在debugable-unlua里导出了。

About

Integrate lua-protobuf into unlua

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published