sluaunreal

lua dev plugin for unreal engine 4 or 5

OTHER License

Stars
1.7K

Bot releases are visible (Hide)

sluaunreal - 1.0.3 release

Published by pangweiwei over 5 years ago

add support TSharedPtr and TSharedRef;
add support TDelegate for cppbinding;
add support gc in collecting thread;
no longer using lua weak table to cache UObject instead of TMap<UObject*, UD*>;
add some gc step in proper position;
fix code for UE 4.22;
fix BindLambda for UE 4.18

sluaunreal - 1.0.2 release

Published by pangweiwei over 5 years ago

fix crash on gcObject if UObject had been collect by unreal engine
fix crash if USTRUCT have USTRUCT in a TMap
fix crash if lua hold an UWorld cross world switch
add linux building support
some other minor fixs

sluaunreal - 1.0.1 release

Published by pangweiwei over 5 years ago

add loadObject util function
add support loadUI can accept owner to manage UI lifetime
fix crash of checkUObject if PropertyClass is nil or Object Class is nil
fix map2actor error

sluaunreal - 1.0 release

Published by pangweiwei over 5 years ago

add console cmd for dump memDetail and uobjects
add cpu profile tools
add LuaActor for extend AActor or Blueprint Actor
add support for binding lua function to FScriptDelegate.
add dead-loop code checking
add a complete demo for demostrate how to using slua
add support export enum in cppbinding
add gc and mem console command
add error checking if ud had been freed
add error checking if passed a wrong UObject
fix crash if using a struct that parent had been freed
fix memory leak on LuaVar hold an UObject
fix mistake to index element of TArray
fix callByUFunction can't push const& param
many minor fixs

更加安全可靠的gc

slua unreal 反复修改了gc机制,以适应unreal引擎各种特点,新版本的gc机制充分测试,更加安全可靠。

更加便捷的重用现有c++,蓝图Actor

正式版slua提供了一种新的能力来快速重用、扩展Actor,不管这个Actor是蓝图Actor还是c++ Actor,具体可以参考这里:LuaActor的使用

增加lua cpu profile工具

通过这个工具可以方便的分析lua代码性能,类似Unity,未来还会增加Lua Memory Profile能力。

image

增加了死循环检查

现在slua会检查 lua代码的死循环,类似android的ANR,当脚本运行超时(5s),会跳出脚本运行,并报告一个脚本异常。

image

增加了一系列console命令

增加了一系列console命令,用于在编辑内快速调试lua状态,手动gc,列出尚未被回收的对象等,方便调试。

新的cppbinding支持导出enum

enum TestEnum {
	TE_OK,
	TE_BAD,
	TE_COUNT,
};
DefEnum(TestEnum, TE_OK, TE_BAD, TE_COUNT);

enum class TestEnum2 {
	OK,
	BAD,
	COUNT,
};
DefEnumClass(TestEnum2, TestEnum2::OK, TestEnum2::BAD, TestEnum2::COUNT);

新增了一个更加完整的demo演示如何使用slua

这个demo是改造自unreal官方自带教学demo,参考这里

image

修复大量已知Bug

添加了UObject类型检查,避免传入错误的UObject类型,导致异常;

添加了userdata生命周期的检查,现在在lua中使用,或者传递到c++,已经被释放的userdata都会报错,而不会崩溃;

修复了LuaVar如果持有UObject导致内存泄漏的问题;

修复了callByFunction无法返回lua返回值,无法处理out参数的问题;

大量其他小修改。

sluaunreal - 1.0 beta 2 release

Published by pangweiwei almost 6 years ago

add name for state to call blurprint from speified state
add method GetAllWidgets in LuaWidgetTree
add Add function for LuaArray
fix cache error ptr that cppbinding return same ptr for different object
fix cache error LuaMap ptr
fixed newindex null property crash
fix UFunction should not cache by class name instead of class ptr
fix blueprint return value
fix different ScriptMap share one UMapProperty

sluaunreal - 1.0 beta release

Published by pangweiwei almost 6 years ago

fix crash on set property if that not be find
add arm64 liblua.a and build file for android
add dumpLeak function for finding lua UObject leak
fix check UObject that maybe an actor

sluaunreal - 1.0 alpha_2 release

Published by pangweiwei almost 6 years ago

fix call blueprint function from lua may cause crash
fix loadClass function for constructing
refactor test case code

sluaunreal - 1.0 alpha release

Published by pangweiwei almost 6 years ago

完善了LuaArray和LuaMap

之前的版本,LuaArray和LuaMap是一个实验性的功能,用于支持TArray和TMap被导出给lua使用,实际并没有得到大规模使用过,拿给外部用户使用就暴露出很多问题,其中最主要的问题是,如果LuaArray和LuaMap保存了UObject指针,如何管理其什么周期?之前的版本是没有考虑这个问题的,即UObject元素的申明周期由外部管理,LuaArray、LuaMap不管理其生命周期,这在实际使用中,非常难于理解也难于控制,更自然的理解是容器类应该负责元素的生命周期,新版的sluaunreal完成了这个功能,LuaArray、LuaMap会持有UObject的引用,直到被lua回收掉,才会解除UObject的引用。

同时进一步完善TArray、TMap、UStruct相互嵌套的情况。

还有就是从c++侧到lua侧的数据传递,到底是copy还是引用传递?在之前的版本,都是copy一份数据传递到lua侧,copy完成后,c++侧和lua侧数据互相独立,修改了也不会互相影响,但在实际使用过程中,我们希望如果是UProperty,则应该维持c++侧和lua侧使用同一份数据,修改了互相可见。在新版中也完成这个功能,如果是UProperty的TArray和TMap,则采用指针传递,c++和lua共享一份数据,修改互相可见;如果是函数返回值,则仍然是数据copy,互相独立。

完善了lambda表达式和TFunciton的支持

新版的cppbinding支持了lambda表达式,可以使用lambda表示添加lua导出方法,添加扩展方法,例如:

DefLuaClass(Foo,Base)
	DefLuaMethod(testEnum, &Foo::testEnum)
        DefLuaMethod(bar,&Foo::bar)
        DefLuaMethod(getStr,&Foo::getStr)
        DefLuaMethod(getInstance,&Foo::getInstance)
        DefLuaMethod(virtualFunc,&Foo::virtualFunc)
        DefLuaMethod(setCallback,&Foo::setCallback)
        DefLuaMethod(docall,&Foo::docall)
        DefLuaMethod_With_Lambda(helloWorld,false,[]()->void {
            slua::Log::Log("Hello World from slua");
        })
EndDef(Foo,&Foo::create)

helloWorld方法就是一个成员方法,通过lambda表示实现。

之前不支持UE的TFunction作为函数参数,新版支持传入一个lua function,在c++侧被理解为TFunction当做回调函数使用,这样方便在非UObject类里实现代理、函数回调,非常方便,例如:

void setCallback(const TFunction<void(int)>& func) {
    callback = func;
}

在lua侧只需要传递一个lua function即可:

f1:setCallback(function(i) print("callback from cppbinding",i) end)

完善了导出重载函数

之前cppbinding是无法支持重载的函数导出使用,也不支持重载的函数注册为extension方法,新版都得到支持,例如:

DefLuaClass(Foo,Base)	
        DefLuaMethod_With_Type(getFruit_1,&Foo::getFruit,Fruit (Foo::*) ())
        DefLuaMethod_With_Type(getFruit_2,&Foo::getFruit,Fruit (Foo::*) (int))
EndDef(Foo,&Foo::create)

 这样可以通过函数签名明确到底导出那个版本的重载函数。

不再依赖USceneComponent

之前的实现希望 sluaunreal 作为一个Component 被添加到场景中,但实际的项目中,大家普遍反映希望LuaState可以独立存在,不依赖任何场景Actor,Component等,新版sluaunreal做了修改,初始化不需要任何参数,LuaState内部自己在需要的时候获取UWorld信息,游戏项目可以根据自己需求在合适的实际创建LuaState,不需要任何额外参数,方便使用。

Bug修复

修复了cppbinding注册类可能无效的问题;
修复了ufunction调用之后析构对应的c++类,避免内存泄露;
修复了在gc一个uclass的userdata时,导致可能crash的问题;
修复了luawrapper生成的代码,没有很好处理static方法的问题;
修复了UStruct也需要添加对UObject类引用的问题;
修复了4.19之后UE版本编译错误的问题;
修复了luasocket内部require出错问题;
out类型的参数,目前可以接受nil作为参数,out参数通过函数返回值额外返回;
修复了在vs2017下链接超时的问题;
修复其他若干不稳定问题。