Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何导出类的静态成员变量 #22

Closed
Junho2009 opened this issue Aug 20, 2019 · 5 comments
Closed

如何导出类的静态成员变量 #22

Junho2009 opened this issue Aug 20, 2019 · 5 comments

Comments

@Junho2009
Copy link

目前似乎没找到对应的宏。
从实现的方面,可以定义一个对应的静态函数来返回,然后导出这个静态函数,不过这样比较繁琐呢。

@futouyiba
Copy link

UGameplayStatics这种Bp library里面应该都是static函数,可以参考吧

@Junho2009
Copy link
Author

UGameplayStatics这种Bp library里面应该都是static函数,可以参考吧

是希望导出一个类的静态【变量】到lua哈。
当然也可以用lua的C API pushxxx,不过如果有对应的宏,就不用自行写胶水代码。

@rowechien
Copy link
Collaborator

@Junho2009 确实是没有这个功能,之后补上吧

@futouyiba
Copy link

UGameplayStatics这种Bp library里面应该都是static函数,可以参考吧

是希望导出一个类的静态【变量】到lua哈。
当然也可以用lua的C API pushxxx,不过如果有对应的宏,就不用自行写胶水代码。

不好意思,之前把静态变量看成了静态函数

@rowechien
Copy link
Collaborator

@Junho2009 UnLua对类的非静态变量导出后是以lightuserdata形式存在,通过类元表的__index函数再配合类实例的地址和偏移来对它进行读写。静态变量可以通过类直接访问,在lua里就是通过类元表直接访问,这个在UnLua里不好实现(因为直接就返回lightuserdata了),当然通过类的实例可以正常访问,不过这就少了静态变量的特色了。
UnLua不会对这个情况做特色处理了。你可以自己绕过去,比如写个类的静态成员函数,然后把它导出。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants