mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-09 15:25:56 -04:00
OpenOS: /lib/package.lua: add support for preload and config (#3447)
Add basic implementations of package.preload and package.config, necessary to get the Fennel compiler ( https://fennel-lang.org ) running.
This commit is contained in:
parent
3b60e93af5
commit
dde8337955
@ -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,
|
||||
@ -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")
|
||||
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user