Skip to content

Instantly share code, notes, and snippets.

@MattRix
Created April 24, 2023 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattRix/67fa1b6f883399530d5993f8e0ff8526 to your computer and use it in GitHub Desktop.
Save MattRix/67fa1b6f883399530d5993f8e0ff8526 to your computer and use it in GitHub Desktop.
Singleton in Verse
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