vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1.04k stars 53 forks source link

Something like `atexit` #219

Closed skejeton closed 11 months ago

skejeton commented 1 year ago

atexit allows you to run some code before exit. In my case I want to save the editor layouts and other code when the program exits. I can do it at the end of main, but in case of runtime errors or other preemptive exits or multiple exit points, the program may not save the data I want.

RobLoach commented 1 year ago

Many languages have adopted the defer keyword, like Go's defer and C3's defer.

marekmaskarinec commented 1 year ago

@skejeton for your specific use case I could add an atexit to tophat, but I think it would be better to see it being an umka feature.

skejeton commented 1 year ago

Defer seems to exit on the end of scope, not exactly what I want it appears

On Sun, Oct 16, 2022, 2:40 AM Rob Loach @.***> wrote:

Many languages have adopted the defer keyword, like Go's defer https://go.dev/tour/flowcontrol/12 and C3's defer https://www.c3-lang.org/examples/#defer.

— Reply to this email directly, view it on GitHub https://github.com/vtereshkov/umka-lang/issues/219#issuecomment-1279828499, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGOSLSMMWL6JWNDBTM3ZEOTWDMJCZANCNFSM6AAAAAAQ2P4QYQ . You are receiving this because you authored the thread.Message ID: @.***>

vtereshkov commented 11 months ago

The reported use case is now covered by window.onDestroy.register({/*...*/}) in tophat.