Add Lua API export in EmmyLua syntax.

This commit is contained in:
Matthias Mailänder
2021-10-20 20:12:20 +02:00
committed by atlimit8
parent 550db7e958
commit 709512b166
3 changed files with 365 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Eluant;
using OpenRA.Traits;
namespace OpenRA.Scripting
{
@@ -140,5 +141,18 @@ namespace OpenRA.Scripting
return false;
});
}
public static string[] RequiredTraitNames(Type t)
{
// Returns the inner types of all the Requires<T> interfaces on this type
var types = t.GetInterfaces()
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(Requires<>));
// Remove the namespace and the trailing "Info"
return types.SelectMany(i => i.GetGenericArguments())
.Select(g => g.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault())
.Select(s => s.EndsWith("Info") ? s.Remove(s.Length - 4, 4) : s)
.ToArray();
}
}
}