[[https://www.wikidata.org/w/index.php?title=Special:Permalink/669075255#What_kind_of_functions_do_you_need?_5|As requested]], it should be possible for Lua users to get the [[https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/docs/options.wiki#Basic_Settings-3|site's global id]].
While this would thematically fit very well into [[https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Site_library|Scribunto's Site library]], only Wikibase currently knows a site's global id (which is caused by the current state of interwiki/site handling in MediaWiki).
I suggest adding `mw.wikibase.getGlobalSiteId()`. Alternatively, we could expose it simply as field `mw.wikibase.globalSiteId` or add it to Scribunto's Site library (although this would heavily mess with extension boundaries).
Note: T146616 is related to this as the `$wgDBname`/`wfWikiId()` matches the global site id in the WMF setup (but **not** generally).