From 71496092296a79efd243a6c234304be165c2fde3 Mon Sep 17 00:00:00 2001
From: YoshiRulz <OSSYoshiRulz+git@gmail.com>
Date: Fri, 10 Jan 2025 23:06:01 +1000
Subject: [PATCH] Gen docs for methods in Lua lib classes even w/o
 `[RequiredService]`s

resolves #4167
---
 .../tools/Lua/LuaLibraries.cs                       | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
index 5ac0a3922f..db48685d09 100644
--- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
@@ -10,6 +10,7 @@ using NLua.Native;
 
 using BizHawk.Client.Common;
 using BizHawk.Common;
+using BizHawk.Common.StringExtensions;
 using BizHawk.Emulation.Common;
 
 namespace BizHawk.Client.EmuHawk
@@ -65,11 +66,21 @@ namespace BizHawk.Client.EmuHawk
 
 			// Register lua libraries
 			foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
-				.Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
+				.Where(static t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed))
 			{
 				if (VersionInfo.DeveloperBuild
 					|| lib.GetCustomAttribute<LuaLibraryAttribute>(inherit: false)?.Released is not false)
 				{
+					if (!ServiceInjector.IsAvailable(serviceProvider, lib))
+					{
+						Util.DebugWriteLine($"couldn't instantiate {lib.Name}, adding to docs only");
+						EnumerateLuaFunctions(
+							lib.Name.RemoveSuffix("LuaLibrary").ToLowerInvariant(), // why tf aren't we doing this for all of them? or grabbing it from an attribute?
+							lib,
+							instance: null);
+						continue;
+					}
+
 					var instance = (LuaLibraryBase)Activator.CreateInstance(lib, this, _apiContainer, (Action<string>)LogToLuaConsole);
 					if (!ServiceInjector.UpdateServices(serviceProvider, instance, mayCache: true)) throw new Exception("Lua lib has required service(s) that can't be fulfilled");