Memoise a value during Lua lib function enumeration

This commit is contained in:
YoshiRulz 2025-01-10 23:14:21 +10:00
parent ea810cb89b
commit 89e94be8c1
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 5 additions and 3 deletions

View File

@ -37,6 +37,9 @@ namespace BizHawk.Client.EmuHawk
void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
{
var libraryDesc = type.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>()
.Select(static descAttr => descAttr.Description)
.FirstOrDefault() ?? string.Empty;
if (instance != null) _lua.NewTable(name);
foreach (var method in type.GetMethods())
{
@ -44,9 +47,8 @@ namespace BizHawk.Client.EmuHawk
if (foundAttrs.Length == 0) continue;
if (instance != null) _lua.RegisterFunction($"{name}.{((LuaMethodAttribute)foundAttrs[0]).Name}", instance, method);
LibraryFunction libFunc = new(
name,
type.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>()
.Select(descAttr => descAttr.Description).FirstOrDefault() ?? string.Empty,
library: name,
libraryDescription: libraryDesc,
method,
suggestInREPL: false
);