Tencent / sluaunreal

lua dev plugin for unreal engine 4 or 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问可否提供静态绑定 Demo 及生成静态绑定代码工具

ZichaoNickFox opened this issue · comments

Is your feature request related to a problem? Please describe.
您好,项目在使用 unlua,unlua 使用元方法回调到 c++ 的 CallFunc,再 GetInstance 得到对象,再使用反射调用函数,这种方式效率太低,在考虑是否转型使用 slua,技术上希望使用静态绑定+代码生成的方式进行 lua、c++ 间的调用

Describe the solution you'd like
请问 slua 官方可以提供静态绑定的使用方式,以及生成静态绑定代码的生成工具

Describe alternatives you've considered
目前项目还在使用 unlua,其静态绑定支持不好

Additional context
另外,静态绑定+代码生成可能在读取成员变量时也要使用函数,比如 myStruct.a = 1 需要写成 myStruct.SetA(1),不知道技术上可否 myStruct.a = 1;再如 print(myStruct.a) 需要写成 print(myStruct.GetA()),不知道技术上可否写成 print(myStruct.a)

1、静态绑定demo,仅供参考:

class BASIC_API FTimeTicker
{
public:
    FTimeTicker();
    ~FTimeTicker();

    // constructor function for lua
    // LuaOwnedPtr will hold ptr by lua and auto collect it;
    static NS_SLUA::LuaOwnedPtr<FTimeTicker> create();

    void SetTickFunction(const NS_SLUA::LuaVar& LuaFunction);

    void AddTimer(int index, float InFirstDelay);

    void Tick(float DeltaTime);
}

// 静态绑定代码
namespace NS_SLUA
{
    DefLuaClass(FTimeTicker)
        DefLuaMethod(SetTickFunction, &FTimeTicker::SetTickFunction)
        DefLuaMethod(AddTimer, &FTimeTicker::AddTimer)
        DefLuaMethod(Tick, &FTimeTicker::Tick)
    EndDef(FTimeTicker, &FTimeTicker::create)
}

2、静态绑定代码生成工具是这个:
https://github.com/Tencent/sluaunreal/tree/master/Tools/lua-wrapper.exe

另:对于反射方面的性能的顾虑,我觉得大可不必,一般都是够用的了,项目实践中我们更多的是利用反射功能。性能方面的顾虑可参考官网readme最后的benchmark表格。欢迎使用slua!