Slua-unreal is an unreal4 plugin, which allows you to use Lua language to develop game logic and hot fix your code. It gives you 3 ways to wrap your C++ interface to Lua, including reflection by blueprint, C++ template and static code generation. It also enables a two-way communication between blueprint and Lua. The advantage of Lua over C++ is that it requires no compilation for logic change, which significantly speeds up game development process.
slua-unreal作为unreal引擎的插件,通过unreal自带蓝图接口的反射能力,结合libclang静态c++代码分析,自动化导出蓝图接口和静态c++接口,提供给lua语言,使得可以通过lua语言开发unreal游戏业务逻辑,方便游戏高效迭代开发,上线热更新,同时支持lua到c++双向,lua到蓝图双向调用,使用lua语言完美替代unreal的c++开发方式,修改业务逻辑不需要等待c++编译,大大提升开发速度。
目前该项目作为腾讯PUBG手游和潘多拉系统,该系统用于腾讯UE4游戏业务,帮助游戏业务构建周边系统、运营系统,上线质量稳定。
欢迎issue,pr,star,fork。
Slua-unreal is currently adopted in PUBG mobile game, one of Tencent’s most-played and highest-grossing mobile games, and Pandora system. This system is widely used in Tencent’s UE4 gaming business, helping the business build and maintain its commercial operation system.
Release 1.3.3, fix a crash bug, more stable
Release 1.3.2, fix building error on UE 4.24
Add a branch to support UE 4.25 or later
- Automatic export of blueprint API to the Lua interface
- Supporting RPC (Remote Procedure Call) functions
- Overriding any blueprint function with a Lua function
- Calling Lua functions as callback functions for blueprint events
- Normal C++ functions and classes exported by C++ template
- Auto code generation to wrap your normal C++ function for use in Lua
- Supporting enum, FVector etc
- Operator overloading in FVector or other struct class
- Allowing manual addition of a non-blueprint function to UObject
- Calling Lua functions from blueprint, vice versa
- Dead loop detection and error reporting when a dead loop is detected
- Multi-state for different runtime environments
- CPU profiling
- Multithread Lua GC (Garbage Collection)
- 通过蓝图反射机制,自动导出unreal 4的蓝图api到lua接口
- 支持rpc函数调用
- 支持复写任何蓝图函数,包括rpc函数,用lua函数替代
- 支持以lua function作为蓝图事件的回调函数
- 支持普通c++函数和类 通过静态代码生成或者泛型代码展开导出到lua接口,同时支持与蓝图接口交互
- 完整支持了unreal4的枚举,并导出了全部枚举值到lua
- 支持FVector等非蓝图类,同时支持操作符重载
- 支持扩展方法,将某些未标记为蓝图方法的函数,手动添加到蓝图类中,例如UUserWidget的GetWidgetFromName方法。
- 支持从蓝图中调入lua,并接收lua返回值,支持任意参数类型和任意参数个数。
- 支持蓝图out标记参数,支持c++非const引用作为out类型参数返回。
- 自动检查脚本死循环,当代码运行超时自动报错。
- 支持多luastate实例,用于创建不同运行环境的luastate。
- lua代码支持cpu profile
- lua 多线程 GC
- 性能分析工具,支持连接真机分析
我们开发了专门的vs code调试插件,支持真机调试,断点,查看变量值,代码智能提示等功能。调试器自动识别可以使用的UE UFunction蓝图函数和CppBinding导出的接口函数,不需要额外导出静态数据。
We developed a tool integrated with VsCode to support in-device debugging, breakpoint, variable inspection and code IntelliSense. Debugger will auto-generate data for UE UFunction and export C++ functions with CppBinding.
-- import blueprint class to use
local Button = import('Button');
local ButtonStyle = import('ButtonStyle');
local TextBlock = import('TextBlock');
local SluaTestCase=import('SluaTestCase');
-- call static function of uclass
SluaTestCase.StaticFunc()
-- create Button
local btn=Button();
local txt=TextBlock();
-- load panel of blueprint
local ui=slua.loadUI('/Game/Panel.Panel');
-- add to show
ui:AddToViewport(0);
-- find sub widget from the panel
local btn2=ui:FindWidget('Button1');
local index = 1
-- handle click event
btn2.OnClicked:Add(function()
index=index+1
print('say helloworld',index)
end);
-- handle text changed event
local edit=ui:FindWidget('TextBox_0');
local evt=edit.OnTextChanged:Add(function(txt) print('text changed',txt) end);
-- use FVector
local p = actor:K2_GetActorLocation()
local h = HitResult()
local v = FVector(math.sin(tt)*100,2,3)
local offset = FVector(0,math.cos(tt)*50,0)
-- support Operator
local ok,h=actor:K2_SetActorLocation(v+offset,true,h,true)
-- get referenced value
print("hit info",h)
-- this function called by blueprint
function bpcall(a,b,c,d)
print("call from bp",a,b,c,d)
end
Output is:
Slua: call from bp 1024 Hello World 3.1400001049042 UObject: 0x136486168
-- LuaActor.lua
local LuaActor={}
-- override event from blueprint
function LuaActor:BeginPlay()
self.bCanEverTick = true
print("LuaActor:BeginPlay")
end
function LuaActor:Tick(dt)
print("LuaActor:Tick",self,dt)
-- call LuaActor function
local pos = self:K2_GetActorLocation()
-- can pass self as Actor*
local dist = self:GetHorizontalDistanceTo(self)
print("LuaActor pos",pos,dist)
end
return Class(nil, nil, LuaActor)
- 解决1.x版本的生命周期管理问题
- 解决1.x self.Super:Func() 调用,在蓝图有jump指令时崩溃的问题
- Lua模块支持类继承形式书写,例如:
-- LuaActor.lua
local LuaActor ={}
-- override event from blueprint
function LuaActor:ReceiveBeginPlay()
self.bCanEverTick = true
-- set bCanBeDamaged property in parent
self.bCanBeDamaged = false
print("actor:ReceiveBeginPlay")
end
-- override event from blueprint
function LuaActor:ReceiveEndPlay(reason)
print("actor:ReceiveEndPlay")
end
return Class(nil, nil, LuaActor)
-- LuaBpActor.lua
local LuaBpActor = {}
-- override event from blueprint
function LuaBpActor:ReceiveBeginPlay()
print("bpactor:ReceiveBeginPlay")
-- call LuaActor super ReceiveBeginPlay
LuaBpActor.__super.ReceiveBeginPlay(self)
-- call blueprint super ReceiveBeginPlay
self.Super:ReceiveBeginPlay()
end
local CLuaActor = require("LuaActor")
-- CLuaActor is base class
return Class(CLuaActor, nil, LuaBpActor)
- 支持Lua定义RPC函数
-- LuaActor.lua
local LuaActor =
{
ServerRPC = {}, --C2S类RPC列表,类似UFUNCTION宏中的Server
ClientRPC = {}, --S2C类RPC列表,类似UFUNCTION宏中的Client
MulticastRPC = {}, --多播类RPC列表,类似UFUNCTION宏中的NetMulticast
}
local EPropertyClass = import("EPropertyClass")
LuaActor.ServerRPC.TestServerRPC = {
-- 是否可靠RPC
Reliable = true,
-- 定义参数列表
Params =
{
EPropertyClass.Int,
EPropertyClass.Str,
EPropertyClass.bool,
}
}
LuaActor.ClientRPC.TestClientRPC = {
-- 是否可靠RPC
Reliable = true,
-- 定义参数列表
Params =
{
EPropertyClass.Int,
EPropertyClass.Str,
EPropertyClass.bool,
}
}
LuaActor.MulticastRPC.TestMulticastRPC = {
-- 是否可靠RPC
Reliable = true,
-- 定义参数列表
Params =
{
EPropertyClass.Int,
EPropertyClass.Str,
EPropertyClass.bool,
}
}
function LuaActor:TestServerRPC(ArgInt, ArgStr, ArgBool)
end
function LuaActor:TestClientRPC(ArgInt, ArgStr, ArgBool)
end
function LuaActor:TestMulticastRPC(ArgInt, ArgStr, ArgBool)
end
- 支持Lua定义"值复制"信息,并且支持“条件值复制”、struct、数组
-- LuaActor.lua
local LuaActor ={}
function LuaActor:GetLifetimeReplicatedProps()
local ELifetimeCondition = import("ELifetimeCondition")
local FVectorType = import("Vector")
return {
{ "Name", ELifetimeCondition.COND_InitialOnly, EPropertyClass.Str},
{ "HP", ELifetimeCondition.COND_OwnerOnly, EPropertyClass.Float},
{ "Position", ELifetimeCondition.COND_SimulatedOnly, FVectorType},
{ "TeamateNameList", ELifetimeCondition.COND_None, EPropertyClass.Array, EPropertyClass.Str},
{ "TeamatePositions", ELifetimeCondition.COND_None, EPropertyClass.Array, FVectorType},
}
end
return Class(nil, nil, LuaActor)
- 被Override的Cpp函数里面可以直接调用对应Lua函数
-- MyActor.cpp
class MyActor : public Actor, public ILuaOverriderInterface
{
public:
void CallDemoFunction()
{
CallLuaFunction<bool>(TEXT("IsTestEnable"), Arg1, Arg2);
}
}
-- MyActor.lua
local MyActor ={}
function MyActor:IsTestEnable(Arg1, Args)
return true
end
return Class(nil, nil, MyActor)
- struct访问由拷贝改为引用,收益如下:
--- 以修改一个Vector类型字段为例
--- 老代码
local Position = Actor.Position
Position.X = 1
Actor.Position = Position
--- 新代码
Actor.Position.X = 1
- 函数索引相比 1.x 版本有10倍速度提升
- 属性访问、函数调用等,普遍有20%~800%的提升(大部分API速度是原来的1.5~3倍)。
支撑PUBG Mobile 线上业务开发,稳定性得到充分验证。
- UE4.18、UE4.26完整支持,支持UE5.1,其他版本因为时间精力问题暂时无法支持到位
- 兼容lua 5.4版本接入
slua-unreal提供3种技术绑定lua接口,包括:
1)蓝图反射方法
2)静态代码生成
3)CppBinding(模板展开)
其中方法2和3运行原理上没差别,只是方法2是基于libclang自动化生成代码,方法3是手写代码,所以下面的统计上仅针对1和3来对比,可以认为2和3的性能是等价的。
100万次函数调用时间统计(秒),测试用例可以参考附带的TestPerf.lua文件。
测试机器 MacOSX,Unreal 4.18 dev版(非release,release应该会稍微快一点),CPU i7 4GHz。
unit in second, 1,000,000 calls to C++ interface from Lua, compared reflection and cppbinding, (both reflection and cppbinding are supported by slua-unreal).
Test on MacOSX, Unreal 4.18 develop building, CPU i7 4GHz, test cases can be found in TestPerf.lua
Without the time spent on gc alloc, the blueprint reflection-based approach is twice as fast as the one using static code generation, while CppBinding is an order of magnitude faster than reflection.
蓝图反射方法(Reflection) | CppBinding方法(CppBinding) | |
---|---|---|
空函数调用(empty function call) | 0.541507 | 0.090571 |
函数返回int(function return int) | 0.560052 | 0.090419 |
传入int函数返回int(function return int and pass int) | 0.587115 | 0.097639 |
传入Fstring函数返回int(function return FString and pass int) | 0.930042 | 0.223207 |
与slua unity版本相比,因为unreal的蓝图反射更高效,没有gc alloc开销,基于蓝图反射的方法的性能比slua unity的静态代码生成还要快1倍,而cppbinding则快一个数量级。
slua-unreal依赖dot-clang做c++静态代码生成的工具稍后开源,目前常用FVector等常用类的静态生成代码已经附带。
QQ技术支持群:15647305,需要提交具体问题issue后申请入群,谢绝hr和非技术人员进入。
系统Win10 64位 CPU: AMD Ryzen 7 4700G with Radeon Graphics 3.60 GHZ
10万次/秒 | Slua | UnLua | Unlua/Slua |
---|---|---|---|
TestStaticCall | 0.01894 | 0.02667 | 1.41 |
TestEmptyCall | 0.0183 | 0.03351 | 1.83 |
TestSetBoolCall | 0.02541 | 0.04206 | 1.66 |
TestGetBoolCall | 0.02134 | 0.04893 | 2.29 |
TestSetIntCall | 0.02381 | 0.04222 | 1.77 |
TestGetIntCall | 0.02085 | 0.04239 | 2.03 |
TestSetFloatCall | 0.02265 | 0.04031 | 1.78 |
TestGetFloatCall | 0.02167 | 0.03701 | 1.71 |
TestSetFStringCall | 0.04986 | 0.08801 | 1.77 |
TestGetFStringCall | 0.03032 | 0.07163 | 2.36 |
TestSetVectorCall | 0.03339 | 0.07208 | 2.16 |
TestGetVectorCall | 0.05619 | 0.0878 | 1.56 |
TestSetStructCall | 0.0376 | 0.07982 | 2.12 |
TestGetStructCall | 0.08137 | 0.08871 | 1.09 |
TestGetObjectCall | 0.03054 | 0.04709 | 1.54 |
TestSetIntVar | 0.01305 | 0.01745 | 1.34 |
TestGetIntVar | 0.01396 | 0.01553 | 1.11 |
TestSetStrVar | 0.02573 | 0.03327 | 1.29 |
TestGetStrVar | 0.01743 | 0.02555 | 1.47 |
TestSetBoolVar | 0.01362 | 0.01559 | 1.14 |
TestGetBoolVar | 0.01406 | 0.01435 | 1.02 |
TestSetFloatVar | 0.01336 | 0.01557 | 1.17 |
TestGetFloatVar | 0.01381 | 0.01585 | 1.15 |
TestSetVectorVar | 0.0194 | 0.01773 | 0.91 |
TestGetVectorVar | 0.01109 | 0.02358 | 2.13 |
TestSetStructVar | 0.01918 | 0.02197 | 1.15 |
TestGetStructVar | 0.01085 | 0.02408 | 2.22 |
TestGetObjectVar | 0.02111 | 0.02322 | 1.10 |
TestAddArrayElement | 0.05216 | 0.07207 | 1.38 |
TestGetArrayElement | 0.04115 | 0.08281 | 2.01 |
TestAddSetElement | 0.08038 | 0.09814 | 1.22 |
TestGetSetElement | 0.02821 | ||
TestAddMapElement | 0.10757 | 0.16673 | 1.55 |
TestGetMapElement | 0.09039 | 0.14266 | 1.58 |
TestBPEmptyCall | 0.06335 | 0.07548 | 1.19 |
TestBPSetIntCall | 0.10759 | 0.13205 | 1.23 |
TestBPGetIntCall | 0.10575 | 0.13338 | 1.26 |
TestBPSetBoolCall | 0.10951 | 0.13201 | 1.21 |
TestBPGetBoolCall | 0.10572 | 0.13193 | 1.25 |
TestBPSetStringCall | 0.13069 | 0.18015 | 1.38 |
TestBPGetStringCall | 0.12013 | 0.15976 | 1.33 |
TestBPSetFloatCall | 0.10626 | 0.12982 | 1.22 |
TestBPGetFloatCall | 0.10486 | 0.1291 | 1.23 |
TestBPSetVectorCall | 0.1204 | 0.16478 | 1.37 |
TestBPGetVectorCall | 0.17194 | 0.18061 | 1.05 |
TestBPSetStructCall | 0.12453 | 0.17291 | 1.39 |
TestBPGetStructCall | 0.17526 | 0.18216 | 1.04 |
TestBPSetObjectCall | 0.11112 | 0.1445 | 1.30 |
TestBPGetObjectCall | 0.11979 | 0.14663 | 1.22 |
TestSetBPIntVar | 0.01288 | 0.01696 | 1.32 |
TestGetBPIntVar | 0.01432 | 0.01654 | 1.16 |
TestSetBPStrVar | 0.02481 | 0.03447 | 1.39 |
TestGetBPStrVar | 0.01701 | 0.02515 | 1.48 |
TestSetBPBoolVar | 0.01318 | 0.01801 | 1.37 |
TestGetBPBoolVar | 0.0131 | 0.0163 | 1.24 |
TestSetBPFloatVar | 0.01194 | 0.01646 | 1.38 |
TestGetBPFloatVar | 0.01352 | 0.01554 | 1.15 |
TestSetBPVectorVar | 0.02013 | 0.01738 | 0.86 |
TestGetBPVectorVar | 0.01127 | 0.02289 | 2.03 |
TestSetBPStructVar | 0.02006 | 0.01987 | 0.99 |
TestGetBPStructVar | 0.01154 | 0.02252 | 1.95 |
TestSetBPObjectVar | 0.018 | 0.01898 | 1.05 |
TestGetBPObjectVar | 0.01885 | 0.02216 | 1.18 |
TestAddBPArrayElement | 0.04994 | 0.07266 | 1.45 |
TestGetBPArrayElement | 0.04117 | 0.08902 | 2.16 |
TestAddBPSetElement | 0.07719 | 0.10107 | 1.31 |
TestGetBPSetElement | 0.08785 | ||
TestAddBPMapElement | 0.10685 | 0.15537 | 1.45 |
TestGetBPMapElement | 0.08607 | 0.14564 | 1.69 |
TestOverrideSetIntVar | 0.01253 | 0.01691 | 1.35 |
TestOverrideGetIntVar | 0.01315 | 0.01526 | 1.16 |
TestOverrideSetStrVar | 0.02569 | 0.03261 | 1.27 |
TestOverrideGetStrVar | 0.01637 | 0.02755 | 1.68 |
TestOverrideSetBoolVar | 0.01357 | 0.01731 | 1.28 |
TestOverrideGetBoolVar | 0.01312 | 0.01598 | 1.22 |
TestOverrideSetFloatVar | 0.01298 | 0.0168 | 1.29 |
TestOverrideGetFloatVar | 0.01325 | 0.01613 | 1.22 |
TestOverrideSetVectorVar | 0.02141 | 0.01795 | 0.84 |
TestOverrideGetVectorVar | 0.0103 | 0.02297 | 2.23 |
TestOverrideSetStructVar | 0.01906 | 0.01902 | 1.00 |
TestOverrideGetStructVar | 0.01135 | 0.02313 | 2.04 |
TestOverrideSetObjectVar | 0.02002 | 0.02091 | 1.04 |
TestOverrideGetObjectVar | 0.01871 | 0.0226 | 1.21 |
TestOverrideAddArrayElement | 0.04959 | 0.07026 | 1.42 |
TestOverrideGetArrayElement | 0.04033 | 0.08686 | 2.15 |
TestOverrideAddSetElement | 0.07604 | 0.09988 | 1.31 |
TestOverrideGetSetElement | 0.08807 | ||
TestOverrideAddMapElement | 0.1035 | 0.15905 | 1.54 |
TestOverrideGetMapElement | 0.08564 | 0.14475 | 1.69 |
TestOverrideReceiveBeginPlay | 0.00135 | 0.03956 | 29.30 |
TestOverrideTestFunc | 0.01313 | 0.09633 | 7.34 |
TestIndexStaticCall | 0.00125 | 0.00535 | 4.28 |
TestIndexEmptyCall | 0.00126 | 0.00559 | 4.44 |
TestIndexSetBoolCall | 0.00134 | 0.0058 | 4.33 |
TestIndexGetBoolCall | 0.00142 | 0.00572 | 4.03 |
TestIndexOverrideTestFunc | 0.00109 | 0.00069 | 0.63 |
sluaunreal's People
Forkers
jygod stuartwang zzwzfy linecode lishangwen dut3062796s davidmr001 doersa duzhanyuan xianliy menh walkinqin xubingyue ren19890419 skymysky mengjiangtao luoxz-ai comfanter olachan zhoudaqing jangocheng artstylepro jj4jj zhangf911 uvtong junjun7 yizheshiyang cybersl60 ijovi23 icyrains kerwinzxc jiangrui ialex32x kevinofsias kewuc movinghan beingway sincemetom alenwesker eryang zhoucantong a409197988 szm429006 northwolf521 jiexuan357 a83376750 pyzh stdnxd object-wth fedly hulaishun ly774508966 hengle lyntel 91act typed thuskey sikkey cxmlg oscargame chaohona zuoer lyuavery xermao qilinlee aingelu 1206660 whztt07 githubcomus sdsgwangpeng fangguanya ganshulong jonike bbx0331 cd756819220 jeremyssp tompandora danteslin blackhungry tamerlx zjhongxian houguohua indigos33k3r jinsesunshine smartether xuebai5 profiles chuqiuhan wizardbug00 kangtachan grandzhuo 253627764 lstarboy l5276261 onebigshrimp joe8524567913 predawnraziel liushunhang bestzachma sywnffsluaunreal's Issues
单播代理不支持返回lua函数的返回值
在SluaTestCase中添加一下测试代码
.h
DECLARE_DYNAMIC_DELEGATE_RetVal_OneParam(int32, FOnTestGetCount, FString, str);
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (IsBindableEvent = "True"))
FOnTestGetCount OnTestGetCount;
UFUNCTION(BlueprintCallable, Category = "Lua|TestCase")
void TestUnicastDelegate(FString str);
.cpp
void USluaTestCase::TestUnicastDelegate(FString str)
{
int32 retVal = OnTestGetCount.IsBound() ? OnTestGetCount.Execute(str) : -1;
slua::Log::Log("TestUnicastDelegate retVal=%d", retVal);
}
Lua中绑定
t.OnTestGetCount:Bind(function (s)
print(s)
return 1111
end)
t:TestUnicastDelegate("test unicast delegate")
得到的结果是0
一种解决方案:
在callByUFunction中添加
if (bHasReturnParam)
{
UProperty* p = func->GetReturnProperty();
docallWithRetProp(n, p, parms + p->GetOffset_ForInternal());
}
else
{
docall(n);
}
return true;
int LuaVar::docallWithRetProp(int argn, UProperty* prop, uint8* parms) {
if (!isValid()) {
Log::Error("State of lua function is invalid");
return 0;
}
auto L = getState();
int top = lua_gettop(L);
top = top - argn + 1;
LuaState::pushErrorHandler(L);
lua_insert(L, top);
vars[0].ref->push(L);
{
LuaScriptCallGuard g(L);
lua_insert(L, top + 1);
// top is err handler
if (lua_pcallk(L, argn, LUA_MULTRET, top, NULL, NULL))
lua_pop(L, 1);
else
{
auto func = LuaObject::getChecker(prop);
if (func) {
(*func)(L, prop, parms, lua_absindex(L, -1));
lua_pop(L, 1);
}
}
lua_remove(L, top); // remove err handler;
}
return lua_gettop(L) - top + 1;
}
LuaObject.h 226行有个拼写错误,写成了"excpect userdata..."
由于编译报错导致Android打包失败
lua插件的Log.h里对于宽字符输出的函数声明用的是const TCHAR*,在Log.cpp里实现用的是const wchar_t*,在windows平台该变量是一致的,但是在android平台是const char16_t *,导致函数找不到定义,编译失败
CppBinding问题,delegate的导入导出问题
定义两个代理
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnTestDynamicDelegate, int, P);
DECLARE_DELEGATE_TwoParams(FOnTestDelegate, int32, bool);
class FooChild : public Foo
{
void testFunc1(FOnTestDynamicDelegate d) {
d.ExecuteIfBound(1111);
}
void testFunc2(FOnTestDelegate d) {
d.ExecuteIfBound(2222, TEXT("=============="));
}
FOnTestDynamicDelegate testFunc3() {
}
FOnTestDelegate testFunc4() {
}
};
DefLuaClass(FooChild,Foo)
DefLuaMethod(testFunc1, &FooChild::testFunc1)
DefLuaMethod(testFunc2, &FooChild::testFunc2)
//DefLuaMethod(testFunc1, &FooChild::testFunc3)
//DefLuaMethod(testFunc2, &FooChild::testFunc4)
EndDef(FooChild,&FooChild::create)
问题1: 如果使用代理作为返回值,导出无法编译通过
问题2:
由于testFunc1,testFunc2不是由UFUNCTION,UPROPERTY等宏修饰的,导致在lua中绑定无法回调
t:testFunc1(slua.createDelegate(function(p, p1)
print("==================", p, p1)
end))
由于上面的问题,引擎内置不使用UObject的部分代码以及部分自定义代码使用上面的方式无法导出或者导出不生效,目前发现下面的项目中
https://github.com/asqbtcupid/unreal.lua.git
提供了一个宏,用来导出代理
LUA_GLUE_DELEGATE
请问目前如何在slua中解决这个问题?
FileNotFoundException: export-common
This lua-wrapper.exe
can not be running on macOS(10.13.6) anymore, but the previous version worked.
Is there changed while building the executable file?
Or is there missing files associated with export-common.dll
which didn't upload?
➜ Tools mono lua-wrapper.exe
Does not support running on the current platform.
System.IO.FileNotFoundException: Could not load file or assembly 'export-common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'export-common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at export_unreal.ExportUnreal.Start () [0x00001] in <8d2974b7de164bf39e78a81a0ce17755>:0
at export_unreal.Program.Main () [0x0011f] in <8d2974b7de164bf39e78a81a0ce17755>:0
4.21版本还不支持吗
如题
4.21里GetPlainANSIString变成自己传缓冲区了。
editor crash after builded vscode every time
vs version: vs2017
editor version 4.20
Demo中 TArray 添加 actor的时候 crash
demo 中 Map2Actor.lua 21行 self.ballarr:Add(actor)
做checkUProperty 会引发p->PropertyClass 空指针异常
调用GameplayStatics的方法,这样调用是否正确?import("GameplayStatics").GetPlayerCharacter
slua
蓝图对象传到Lua后的GC问题
Level上的Actor传到Lua中做逻辑,Level被移除后Actor触发UE4的GC早于Lua的GC,导致ULuaObject的Remove方法在Actor被GC时还未调用。
LuaDelegate连续多次绑定的内存泄漏问题
在Lua中连续调用多次BInd一个代理,断点发现ULuaDelegate的析构函数只有Clear的时候会析构最后一次绑定的ULuaDelegate对象,其他对象未被回收,需要等到程序结束后,才会断点到ULuaDelegate的析构函数,建议在Bind的时候,先检查上次的绑定对象是否是ULuaDelegate对象,如果是将它释放``int LuaDelegate::Bind(lua_State* L)
{
CheckUD(LuaDelegateWrap, L, 1);
auto object = UD->delegate->GetUObject();
if (object)
{
ULuaDelegate* delegateObj = Cast<ULuaDelegate>(object);
if (delegateObj)
{
delegateObj->dispose();
LuaObject::removeRef(L, object);
}
}
// bind luafucntion and signature function
auto obj = NewObject<ULuaDelegate>((UObject*)GetTransientPackage(), ULuaDelegate::StaticClass());
#if WITH_EDITOR
obj->setPropName(UD->pName);
#endif
obj->bindFunction(L, 2, UD->ufunc);
UD->delegate->BindUFunction(obj, TEXT("EventTrigger"));
// add reference
LuaObject::addRef(L, obj);
lua_pushlightuserdata(L, obj);
return 1;
}
有没有交流群?
1.为什么不在ExtensionMethod::init()中传入state,这样可以在这个函数里使用DefGlobalMethod;2.REG_EXTENSION_METHOD暂时不支持导出返回值是指针常量的函数吗?;3.REG_EXTENSION_METHOD暂时不支持导出FORCEINLINE的函数吗?;
请教几个使用上的问题
开发组你好,请教几个问题,该插件是基于USluaComponent生成LuaState,如果用于整个游戏的界面系统,应该是多个USluaComponent还是一个USluaComponent?
1.如果是1个USluaComponent维护所有界面,每个界面用一个脚本去控制,还需要一些共有数据脚本去存储数据,比如策划表,也有可能数据脚本保存一些共有变量,但是创建出来的新界面脚本需要如何去调用自己的init或tick函数,还有如何销毁某个界面。
2.如果是多个USluaComponent去分别创建自己LuaState,每个LuaState控制一个界面相关逻辑,那数据脚本可以相互访问吗,全局变量如何做到修改完,其他LuaState也被修改?
3.Lua中有一个lua_newthread的作用可以共用主线程LuaState数据,但是不知道怎么改,望开发组考虑一下数据共享问题。
望开发组解惑一下,非常感谢。
请问unreal slua 怎么接 protobuf3.6.1?
请问unreal lua 怎么接 protobuf3.6.1? 急~
democpp TestUI.lua error
run democpp click "Quit" button
slua error stack traceback:
[2019.01.22-03.12.52:135][712]Slua: Error: stack traceback:
[C]: in field 'dumpLeak'
...ace/GameClient/Unreal/sluaunreal/Content//Lua/TestUI.lua:15: in function 'remove'
...ace/GameClient/Unreal/sluaunreal/Content//Lua/TestUI.lua:8: in function <...ace/GameClient/Unreal/sluaunreal/Content//Lua/TestUI.lua:5>
linux编译问题
编译Linux版本的DS服务器链接错误,缺少linux的链接库,能否提供Linux版本的预编译库?现在的做法是把External的文件移到插件中编译,升级插件较为麻烦
请问如何实现全局(跨场景)的LuaState?
slua的开发团队你们好,在我学习过部分源码以及示例代码后,发现无论是之前依赖一个USceneComponent还是现在基于一个Actor的版本,LuaState都会绑定到场景中的某个UObject上,如此一来,LuaState的生命周期就会与这个UObject的生命周期相同,LuaState似乎就不具备全局(跨场景)的能力了,因为切换场景后,在当前场景的LuaState就会执行析构,然后新场景的LuaState就会开始它的生命周期。
我尝试过把LuaState放到一个全局的对象中进行管理,例如UGameplayStatics或者UGameInstance,但是退出游戏时会在 LuaState::removeRef
处出现异常,原因是切换场景时引擎会回收一部分UObject对象,而LuaState仍然持有这些对象的引用。
由于在项目开发中,Lua层不可避免地需要缓存一些全局的数据,所以想请教一下全局(跨场景)LuaState的实现方法,谢谢。
CreateDefaultSubobject,这种组件创建在lua里怎么做呢?
build android error
build android error after update code
UATHelper: 打包 (Android(ETC2)): [10/11] Module.slua_unreal.cpp [armv7-es2]
UATHelper: 打包 (Android(ETC2)): In file included from J:/WorkSpace/GameClient/Unreal/sluaunreal/Plugins/slua_unreal/Intermediate/Build/Android/UE4/Development/slua_unreal/Module.slua_unreal.cpp:5:
UATHelper: 打包 (Android(ETC2)): J:\WorkSpace\GameClient\Unreal\sluaunreal\Plugins\slua_unreal\Source\slua_unreal\Private\LuaBase.cpp(27,27): error: no member named 'GetDisplayNameText' in 'UFunction'
UATHelper: 打包 (Android(ETC2)): FString funcName = func->GetDisplayNameText().ToString();
UATHelper: 打包 (Android(ETC2)): ~~~~ ^
UATHelper: 打包 (Android(ETC2)): 1 error generated.
UATHelper: 打包 (Android(ETC2)): [11/11] democpp-armv7-es2.so
UATHelper: 打包 (Android(ETC2)): clang++.exe: error: no such file or directory: 'J:/WorkSpace/GameClient/Unreal/sluaunreal/Plugins/slua_unreal/Intermediate/Build/Android/UE4/Development/slua_unreal/Module.slua_unreal.cppa7.o'
UATHelper: 打包 (Android(ETC2)): ERROR: UBT ERROR: Failed to produce item: J:\WorkSpace\GameClient\Unreal\sluaunreal\Binaries\Android\democpp-armv7-es2.so
UATHelper: 打包 (Android(ETC2)): (see C:\Users\tylerzhu\AppData\Roaming\Unreal Engine\AutomationTool\Logs\G+Epic+Games+UE_4.21\UBT-democpp-Android-Development.txt for full exception trace)
UATHelper: 打包 (Android(ETC2)): Total build time: 65.97 seconds (Parallel executor: 0.00 seconds)
UATHelper: 打包 (Android(ETC2)): Took 66.4231548s to run UnrealBuildTool.exe, ExitCode=5
4.21 Android一開就閃退
最近把專案的sluaunreal插件更新
更新到目前最新 bb08199 (2/16)
Editor跑都正常,但出版到Android打開還沒看到場景就閃退
我把sluaunreal的內容打包出來也是
訊息如下
`[2019.02.18-08.37.07:236][994]LogLoad: Took 0.727573 seconds to LoadMap(/Game/TopDownCPP/Maps/TopDownExampleMap)
[2019.02.18-08.37.07:295][994]LogGarbage: Warning: Disregard for GC object None referencing LuaActor_C /Game/TopDownCPP/Maps/TopDownExampleMap.TopDownExampleMap:PersistentLevel.LuaActor_2 which is not part of root set
[2019.02.18-08.37.07:295][994]LogGarbage: Warning: Disregard for GC object None referencing LuaActor_C /Game/TopDownCPP/Maps/TopDownExampleMap.TopDownExampleMap:PersistentLevel.LuaActor_2 which is not part of root set
[2019.02.18-08.37.07:295][994]LogGarbage: Warning: Disregard for GC object None referencing PlayerInfo_C /Engine/Transient.GameEngine_0:GameInstance_0.PlayerInfo_C_0 which is not part of root set
[2019.02.18-08.37.07:296][994]LogGarbage: Warning: Disregard for GC object None referencing PlayerInfo_C /Engine/Transient.GameEngine_0:GameInstance_0.PlayerInfo_C_0 which is not part of root set
[2019.02.18-08.37.07:296][994]LogGarbage: Warning: Disregard for GC object None referencing TextBlock /Engine/Transient.GameEngine_0:GameInstance_0.PlayerInfo_C_0.WidgetTree_0.TextBlock_Position which is not part of root set
[2019.02.18-08.37.07:296][994]LogGarbage: Warning: Disregard for GC object None referencing TextBlock /Engine/Transient.GameEngine_0:GameInstance_0.PlayerInfo_C_0.WidgetTree_0.TextBlock_Position which is not part of root set
[2019.02.18-08.37.07:297][994]LogOutputDevice: Warning:
Script Stack (0 frames):
[2019.02.18-08.37.07:325][994]LogAndroid: Error: === Critical error: ===
[2019.02.18-08.37.07:325][994]LogAndroid: Error:
[2019.02.18-08.37.07:326][994]LogAndroid: Error: Fatal error: [File:D:\Build++UE4\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollectionVerification.cpp] [Line: 131]
[2019.02.18-08.37.07:326][994]LogAndroid: Error: Encountered 6 object(s) breaking Disregard for GC assumptions. Please check log for details.
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x000000009DAAC6A4 (0x00000000035FD6A4) libUE4.so!VerifyGCAssumptions() []
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x000000009DAAB6C4 (0x00000000035FC6C4) libUE4.so!CollectGarbageInternal(EObjectFlags, bool) []
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x000000009DAAE18C (0x00000000035FF18C) libUE4.so!TryCollectGarbage(EObjectFlags, bool) []
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x00000000A07A72BC (0x00000000062F82BC) libUE4.so!UEngine::ConditionalCollectGarbage() []
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x000000009FFDB0C8 (0x0000000005B2C0C8) libUE4.so!UWorld::Tick(ELevelTick, float) []
[2019.02.18-08.37.07:326][994]LogAndroid: Error: [Callstack] 0x000000009FDE2294 (0x0000000005933294) libUE4.so!UGameEngine::Tick(float, bool) []
[2019.02.18-08.37.07:327][994]LogAndroid: Error: [Callstack] 0x000000009CDAD768 (0x00000000028FE768) libUE4.so!FEngineLoop::Tick() []
[2019.02.18-08.37.07:327][994]LogAndroid: Error: [Callstack] 0x000000009CDA6140 (0x00000000028F7140) libUE4.so!AndroidMain(android_app*) []
[2019.02.18-08.37.07:327][994]LogAndroid: Error: [Callstack] 0x000000009CDB3408 (0x0000000002904408) libUE4.so!android_main() []
[2019.02.18-08.37.07:327][994]LogAndroid: Error: [Callstack] 0x000000009CDD4C80 (0x0000000002925C80) libUE4.so []
[2019.02.18-08.37.07:327][994]LogAndroid: Error:
[2019.02.18-08.37.07:327][994]LogAndroid: Error:
[2019.02.18-08.37.07:327][994]LogAndroid: Error:
[2019.02.18-08.37.07:327][994]LogAndroid: Error:
`
4.20 打包卡住
[2018.11.10-01.01.56:429][167]UATHelper: 打包 (Windows(64位)): [11/13] Module.slua_unreal.gen.cpp
4.20打包时编译到这一步就没反应了
请问是版本问题吗
使用Tools下的工具导出luawrapper存在bug
1.代码仓库里本身的luawrapper.cpp是正确的,但是用工具生成导出后的luawrapper.cppF类的静态方法参数个数存在问题,第一个参数仍然会占位
2.自动导出工具没有去检查基类,比如导出FVector_NetQuantize 其基类是FVector,生成的代码预期是
newTypeWithBase 结果是newType
自定的枚举怎么导出呢?
如题
4.21 開起專案卡住
我電腦Win7使用UE4.21及VS2017
照著【安装使用】直接打开 democpp.uproject文件
會卡在編譯的地方
2> [11/14] UE4Editor-lua_wrapper.dll 2> Creating library D:\Work\Git\UE4RPG\Client\LuaTest\LuaTest\Plugins\lua_wrapper\Intermediate\Build\Win64\UE4Editor\Development\lua_wrapper\UE4Editor-lua_wrapper.suppressed.lib and object D:\Work\Git\UE4RPG\Client\LuaTest\LuaTest\Plugins\lua_wrapper\Intermediate\Build\Win64\UE4Editor\Development\lua_wrapper\UE4Editor-lua_wrapper.suppressed.exp
產出.sln編譯也同樣
都會卡在lua_wrapper.suppressed.lib
超過一小時不會下一步
請問是否需要其他設置
需要自己安裝CMAKE嗎
CppBinding的问题,无法绑定返回值是TArray的函数
和Http模块导出相同的问题,在Base类中,添加四个函数,testFunc1, testFunc2, testFunc3, testFunc4,由于testFunc1,testFunc2的返回值是TArray,TArray导致无法导出,无法编译通过
测试代码:
class Base {
LuaClassBody()
public:
virtual ~Base() {
Log::Log("Base object %p had been freed",this);
}
void baseFunc1() {
Log::Log("baseFunc1 call");
}
TArray<uint8> testFunc1()
{
}
TArray<FString> testFunc2()
{
}
void testFunc3(TArray<uint8> arr)
{
}
void testFunc4(TArray<FString> arr)
{
}
};
DefLuaClass(Base)
DefLuaMethod(baseFunc1,&Base::baseFunc1)
//DefLuaMethod(testFunc1, &Base::testFunc1)
//DefLuaMethod(testFunc2, &Base::testFunc2)
DefLuaMethod(testFunc3, &Base::testFunc3)
DefLuaMethod(testFunc4, &Base::testFunc4)
EndDef(Base,&NoConstructor)
Lua函数无法使用unpack传参
嗨你好。
我们打算写一个基于xlua的事件系统,function(unpack(args)),这种写法无法触发回调。独立slua的测试时是可以的。
slua lua/luaconf_h 无法修改 extend c
嗨你好,
我想修改lua目录下luaconf_h,如下
#define LUA_API extern "C" __declspec(dllexport)
导出.c的形式。
但是无法编译,请问该如何处理呢?
我的根本目的是想使用luastudio 断点调试 slua。
请问UE4 C++ Actor里UFUNCTION(NetMulticast, Reliable),UFUNCTION(Server, Reliable, WithValidation), UFUNCTION(Client, Reliable), 在LuaActor里如何实现?
UFUNCTION(NetMulticast, Reliable)
void NetMulticastRPCAddBuff(int32 ParamBuffUniqueId, int32 ParamBuffId);
UFUNCTION(Client, Reliable)
void ClientRPCStartAction();
UFUNCTION(Server, Reliable, WithValidation)
void ServerRPCActionEnd();
请问UE4 C++ Actor里UFUNCTION(NetMulticast, Reliable),UFUNCTION(Server, Reliable, WithValidation), UFUNCTION(Client, Reliable), 在LuaActor里如何实现?
请问有公开的QQ群或微信群吗
rt
腾讯有哪些UE4手游用了Slua?
大佬你好,TArray在lua里目前是不是只支持int和string,Object还不支持吗?
我用这个slua.Array(UEnums.EPropertyClass.Object)
传入GameplayStatics.GetAllActorsOfClass,发现并不行。
关于TMap和TArray的bug和支持
1.TMap和TArray中有UObject类型时,作为方法的返回值或者作为对象字段,传给lua, 在GC调用AddReferencedObjects时会闪退,因为LuaReference的addRefByProperty方法中的ContainerPtrToValuePtr对于此种情况是多余的,因为此时传过来的base本身就是正确的地址,不需要偏移,我们这边增加了一个参数用来表示是否需要调用ContainerPtrToValuePtr对base进行偏移.
2.lua端创建TArray或者TMap时, 没有对BaseStruct(FVector之类的)或者UStruct做支持,你们是否有做支持的打算?这边我们把createProperty方法最后一个参数换成了UObject类型,可以传UClass或者UScriptStruct*,方法内部增加了EPropertyClass::Struct分支处理做了支持
3.C++端调用lua方法时,参数不支持TArray和TMap,这个你们是否有做支持的打算?这边我们改动的多了一点,加了2个push的模板函数匹配TArray和TMap,加了一个类用来根据T来创建UProperty
我不太会用git,如果你们没有打算加上面的东西,我可以在这边测试基本没啥问题之后,尝试着提交一个pull request
ULuaDelegate非编辑器平台内存浪费
ULuaDelegate的FString pName的声明,建议加上#if WITH_EDITOR,减少非编辑器平台的内存浪费
导出Http模块的问题
使用下面的宏导出http模块的接口,GetAllHeaders, GetContent两个函数导出无法编译通过,提示24个重载中没有一个可以转换所有参数类型,有什么办法能够导出UE的http到lua中使用吗?
DefLuaClass(IHttpBase)
DefLuaMethod(GetURL, &IHttpBase::GetURL)
DefLuaMethod(GetURLParameter, &IHttpBase::GetURLParameter)
DefLuaMethod(GetHeader, &IHttpBase::GetHeader)
//DefLuaMethod(GetAllHeaders, &IHttpBase::GetAllHeaders)
DefLuaMethod(GetContentType, &IHttpBase::GetContentType)
DefLuaMethod(GetContentLength, &IHttpBase::GetContentLength)
//DefLuaMethod(GetContent, &IHttpBase::GetContent)
EndDef(IHttpBase, &NoConstructor)
LuaDelegate::gc使用时没有Remove的会导致泄漏内存
sluaunreal/Plugins/slua_unreal/Source/slua_unreal/Private/LuaDelegate.cpp
Lines 113 to 116 in e29016f
这里是不是应该加个 LuaDelegate::Clear(L);回收掉没主动Remove的回调
int LuaDelegate::gc(lua_State* L) {
LuaDelegate::Clear(L);
CheckUD(LuaDelegateWrap,L,1);
delete UD;
return 0;
Slua使用Http报错
require("http")
然后报错Slua: Error: Can't load file socket.url ? 无法使用.
请问此工具是否有上线项目?
如题
lua-wrapper.exe 可以生成引擎下的包装类,没有生成自定义的类
config.json:
"TestClass": "{solution_dir}/Source/democpp/Public/TestClass.h",
"ATestActor": "{solution_dir}/Source/democpp/Public/TestActor.h"
救命:unreal-slua 添加pb, local pb = require("pb") , 出现如下错误
Slua: hello luasocket
Slua: LuaSocket 3.0-rc1
Slua: Error: Can't load file pb
Slua: Error: multiple Lua VMs detected
stack traceback:
[C]: in ?
[C]: in function 'require'
...../dst/git/ChessClient/Content//LuaClient/mainClient.lua:38: in field 'Init'
...../dst/git/ChessClient/Content//LuaClient/mainClient.lua:10: in function <...../dst/git/ChessClient/Content//LuaClient/mainClient.lua:9>
LuaSocketWrap编译问题
#include "LuaSocket/luasocket.h"
#include "LuaSocket/mime.h"
这里include的是LuaSocket/,External里面的文件夹名称是luasocket,某些平台编译会报错,改成小写可编译过去
64位编译时却只能找到32位的lua.lib
我的机器上总是链接不成功
建议改下slua_unreal.Build.cs
由
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
{
PublicLibraryPaths.Add(Path.Combine(externalLib, "Win32"));
PublicLibraryPaths.Add(Path.Combine(externalLib, "Win64"));
PublicAdditionalLibraries.Add("lua.lib");
break;
}
改成:
case UnrealTargetPlatform.Win32:
{
PublicLibraryPaths.Add(Path.Combine(externalLib, "Win32"));
PublicAdditionalLibraries.Add("lua.lib");
break;
}
case UnrealTargetPlatform.Win64:
{
PublicLibraryPaths.Add(Path.Combine(externalLib, "Win64"));
PublicAdditionalLibraries.Add("lua.lib");
break;
}
1.想问一下在lua里怎么用类似蓝图的cast的功能,或许只要一个isType接口? 2.在lua里能用蓝图类似Delay接口吗?
import写法的gc问题
luawrapper生成工具相关
请问生成工具有相关文档说明吗,目前项目用到一些F类在LuaWrapper中并没有导出,只能手写,同时也希望生成工具能开源,可以根据项目定制一些特异化的生成需求,十分感谢
请问UE4 C++ Actor里定义的UPROPERTY(Replicated)int32 NetPawnUniqueIdx 如何在LuaActor里定义?
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Replicated)
TArray ArrayInstructs; //FCWPawnInstructs是一個Struct
UPROPERTY(Replicated)
TArray ArrayPropertyAffectorData; //FCWBattlePropertyAffectorData是一個Struct
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated)
int32 NetPawnUniqueIdx;
请问C++里Actor里如上三个定义? 如何在LuaActor里定义?
点击lua-wrapper.exe 没有生成出代码, config.json已经配置。
I got an error when publish for Android: exception handling was disabled in PCH file but is currently enabled
Is there any way to debug it?
1、Idea IDE with emmylua plugin seems doesnt work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.