@@ -23,6 +23,7 @@ local globalSubs = util.multiTable(2)
2323--- @field links table<uri , vm.global.link>
2424--- @field setsCache ? table<uri , parser.object[]>
2525--- @field cate vm.global.cate
26+ --- @field uri string
2627local mt = {}
2728mt .__index = mt
2829mt .type = ' global'
@@ -155,10 +156,11 @@ end
155156
156157--- @param cate vm.global.cate
157158--- @return vm.global
158- local function createGlobal (name , cate )
159+ local function createGlobal (name , cate , uri )
159160 return setmetatable ({
160161 name = name ,
161162 cate = cate ,
163+ uri = uri ,
162164 links = util .multiTable (2 , function ()
163165 return {
164166 sets = {},
@@ -444,7 +446,7 @@ function vm.declareGlobal(cate, name, uri)
444446 globalSubs [uri ][key ] = true
445447 end
446448 if not allGlobals [key ] then
447- allGlobals [key ] = createGlobal (name , cate )
449+ allGlobals [key ] = createGlobal (name , cate , uri )
448450 end
449451 return allGlobals [key ]
450452end
@@ -510,6 +512,19 @@ function vm.getAllGlobals()
510512 return allGlobals
511513end
512514
515+ --- @return table<string , vm.global>
516+ function vm .getExportableGlobals ()
517+ local exportableGlobals = {}
518+ for key , global in pairs (allGlobals ) do
519+ -- If the source uri for the global matches the global variable METAPATH
520+ -- then the global is a builtin Lua language feature and should not be exported
521+ if global .uri and not string.find (global .uri , METAPATH , 1 , true ) then
522+ exportableGlobals [key ] = global
523+ end
524+ end
525+ return exportableGlobals
526+ end
527+
513528--- @param suri uri
514529--- @param cate vm.global.cate
515530--- @return parser.object[]
0 commit comments