Skip to content

Lua's onconsoleclose is broken #4685

@SuuperW

Description

@SuuperW

The Lua event onconsoleclose does not work, and the only way to trigger it does not involve closing the emulator. The code calling it is in LuaLibraries.Close, but all scripts are stopped (and their callbacks cleared) before this method runs. Lua scripts will not be stopped if the core reboot is due to client.reboot_core, but then LuaLibraries.Close also is not called so the Lua event still is not triggered.

Repro

Run this script, and observe it does not print when rebooting the core or closing the ROM:

event.onconsoleclose(function()
	print("console closed")
end)

while true do emu.frameadvance() end

The only way to trigger it is to close the Lua Console tool, which is a situation where it should not trigger. If you replace the print with something like client.togglepause() you can observe the event being triggered when you close the tool. The name "on console close" actually makes some sense for something that runs when the Lua Console tool closes, since the tool has "console" in it's name; but the Lua function's description says "Fires when the emulator console closes" so it refers to the emulator core, not the Lua Console.

I discovered this issue while looking for a workaround for #4629, trying to find a way to detect core reboots in a Lua script exit handler. (I did not find one.)

Output

No error message.

Host env.

Current master, 2.11, and 2.9.1 all have this issue and are the only versions I've tested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Tool: Lua ConsoleRelating to the Lua Console (not EmuHawk's Lua API)Working as intended (wontfix)Bug in deprecated feature, or misidentification of correct behavior, or unreasonable feature requestre: Lua API/scriptingRelating to EmuHawk's Lua API (not the Lua Console)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions