Skip to content

Commit

Permalink
Merge pull request #1 from TankNut/fix-package-environment
Browse files Browse the repository at this point in the history
Fix environment.package, move package.path to ensure it is copied to environment
  • Loading branch information
wauterboi committed Apr 12, 2023
2 parents fa2806e + 91a468c commit 6269f2e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lua/includes/modules/require.moon
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ compile = (filepath, environment) ->
loader = CompileFile filepath
return setfenv loader, environment or _G

--- Module search path templates. See `package.path` in the Lua 5.1 manual for
-- more information.
-- @realm : shared
-- @scope : global
-- @type : string
-- @warning :
-- * The `file` library does not support leading slashes, so neither does
-- this function.
package.path = table.concat {
'?.lua'
'?/init.lua'
'lib/share/lua/5.1/?.lua'
'lib/share/lua/5.1/?/init.lua'
}, ';'

--- Environment for modules loaded using `get_custom_loader`. It is meant to
-- serve as an environment as close to the traditional Lua 5.1 environment
-- as reasonable. The default global table is accessible through `require
Expand Down Expand Up @@ -137,7 +152,7 @@ package.environment = do
'difftime'
'time'
}
package: copy os, {
package: copy package, {
'loaded'
'loaders'
'path'
Expand Down Expand Up @@ -361,21 +376,6 @@ iterate_searchers = ->
-- the module name points to its loader if precached
loaders = package.preload

--- Module search path templates. See `package.path` in the Lua 5.1 manual for
-- more information.
-- @realm : shared
-- @scope : global
-- @type : string
-- @warning :
-- * The `file` library does not support leading slashes, so neither does
-- this function.
package.path = table.concat {
'?.lua'
'?/init.lua'
'lib/share/lua/5.1/?.lua'
'lib/share/lua/5.1/?/init.lua'
}, ';'

--- Cached return values. If a module is executed but returns no values, `true`
-- is stored in its place. See `package.loaded` in the Lua 5.1 manual for more
-- information.
Expand Down Expand Up @@ -444,4 +444,4 @@ for searcher in *{get_cached_loader, get_stock_loader, get_custom_loader}
returns.require = require

-- Add global table to return cache
returns.gmod = _G
returns.gmod = _G

0 comments on commit 6269f2e

Please sign in to comment.