Created
April 24, 2023 15:27
-
-
Save MattRix/67fa1b6f883399530d5993f8e0ff8526 to your computer and use it in GitHub Desktop.
Singleton in Verse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global := class<varies><concrete>(): | |
var MaybeMainDevice : ?main_device = false | |
GetMainDevice():main_device = | |
if(MainDevice := Global.MaybeMainDevice?) then MainDevice else main_device{} | |
Global : global = global{} | |
#in the device's OnBegin you call | |
set Global.MaybeMainDevice = option{Self} | |
#in order to access it from elsewhere, you use | |
GetMainDevice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment