我有一个使用泛型参数的实体组件系统。我正试图让Lua脚本使用NLua来工作。
但是,我不知道如何从Lua环境访问泛型参数。
像这样吗?:
if e:HasComponent<Position>() then
print("Found position...")
end如果没有办法做到这一点,那么我将如何使组件可以通过字符串访问?
代码段将根据请求提供,因为我不认为这是我的代码的问题。
发布于 2015-08-27 13:10:55
您可以尝试直接调用泛型方法,在没有类型参数的情况下,NLua将尝试匹配方法名。
if e:HasComponent () then
...
end如果失败,还可以尝试将泛型方法包装为非泛型扩展方法。
public static HasPositionComponent (this TypeE e)
{
return e.HasComponent<Position>();
}然后,您可以从Lua调用HasPositionComponent作为常规方法。
if e:HasPositionComponent () then
...
end看看GenericMethod测试:
https://github.com/NLua/NLua/blob/main/tests/src/LuaTests.cs#L442
https://stackoverflow.com/questions/31500734
复制相似问题