Skip to content

Commit

Permalink
Memoise a value during Lua lib function enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Jan 10, 2025
1 parent ea810cb commit 89e94be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ public LuaLibraries(

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())
{
var foundAttrs = method.GetCustomAttributes(typeof(LuaMethodAttribute), false);
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
);
Expand Down

0 comments on commit 89e94be

Please sign in to comment.