Skip to content

Conversation

@SuuperW
Copy link
Contributor

@SuuperW SuuperW commented Dec 12, 2025

@YoshiRulz

Doing this is also good for my Lua PR, since it currently still has LuaFormsLibrary assuming that the main form reference is a IDialogParent.

@SuuperW SuuperW requested a review from YoshiRulz December 12, 2025 01:17
if (mainForm is MainForm mainAsForm)
{
formsLib.DialogParent = mainAsForm;
formsLib.OwnerForm = mainAsForm;
Copy link
Member

@YoshiRulz YoshiRulz Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are one and the same semantically.

/// <remarks>In a WinForms app, inheritors must also inherit <c>System.Windows.Forms.IWin32Window</c>.</remarks>
public interface IDialogParent

As a Form, MainForm is the owner of any windows that are created by forms.newform. As an IDialogParent, MainForm is the owner of the file picker dialog when forms.openfile is called. In either case the object is only being used for the window handle encoded within it.
And if we change UI framework, FormsLuaLibrary can cast to the relevant window handle type. This class shouldn't be concerned with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it (FormsLuaLibrary) should only use a IDialogParent property, and cast that to Form?
I was imagining if we change UI framework, FormsLuaLibrary would not be used but another equivalent one would.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tools don't seem to have any way to reference the main form as IDialogParent. Rather than assume it is one, I have made LuaConsole pass itself to LuaLibraries for the IDialogParent reference.
Also changed FormsLuaLibrary to use it as IWin32Window instead of Form.

ApiContainer apiContainer)
{
_apiContainer = ApiManager.RestartLua(newServiceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
_apiContainer = apiContainer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this is an interesting idea. I'm not sure if it's semantically sound, but the call order seems the same so it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced that the restart logic is correct, but yeah this should be equivalent to what is already there. And I see no reason why LuaLibraries would need to be responsible for constructing the API instances or ApiContainer.

Btw this is something my other PR does too.

@YoshiRulz YoshiRulz added Meta Relating to code organisation or to things that aren't code Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API) labels Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Relating to code organisation or to things that aren't code Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants