Skip to content

Commit

Permalink
OpenOS: /lib/package.lua: add support for preload and config (#3447)
Browse files Browse the repository at this point in the history
Add basic implementations of package.preload and package.config,
necessary to get the Fennel compiler ( https://fennel-lang.org )
running.
  • Loading branch information
RobertCochran committed Apr 7, 2024
1 parent 3b60e93 commit dde8337
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
local package = {}

package.config = "/\n;\n?\n!\n-\n"

package.path = "/lib/?.lua;/usr/lib/?.lua;/home/lib/?.lua;./?.lua;/lib/?/init.lua;/usr/lib/?/init.lua;/home/lib/?/init.lua;./?/init.lua"

local loading = {}

local preload = {}

local loaded = {
["_G"] = _G,
["bit32"] = bit32,
Expand All @@ -15,6 +19,7 @@ local loaded = {
["table"] = table
}
package.loaded = loaded
package.preload = preload

function package.searchpath(name, path, sep, rep)
checkArg(1, name, "string")
Expand Down Expand Up @@ -46,6 +51,14 @@ function require(module)
checkArg(1, module, "string")
if loaded[module] ~= nil then
return loaded[module]
elseif package.preload[module] then
assert(type(package.preload[module]) == "function", string.format("package.preload for '%s' is not a function", module))
loading[module] = true
local library, status = pcall(package.preload[module], module)
loading[module] = false
assert(library, string.format("module '%s' load failed:\n%s", module, status))
loaded[module] = status
return status
elseif not loading[module] then
local library, status, step

Expand Down

0 comments on commit dde8337

Please sign in to comment.