Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --v2.0
- _G["shell"] = shell
- _G["multishell"] = multishell
- _G.package = {
- ["loaded"] = {
- ["os"] = os;
- ["bit"] = bit;
- ["colors"] = colors;
- ["commands"] = commands;
- ["coroutine"] = coroutine;
- ["disk"] = disk;
- ["fs"] = fs;
- ["gps"] = gps;
- ["help"] = help;
- ["http"] = http;
- ["io"] = io;
- ["keys"] = keys;
- ["math"] = math;
- ["multishell"] = multishell;
- ["paintutils"] = paintutils;
- ["parallel"] = parallel;
- ["peripheral"] = peripheral;
- ["rednet"] = rednet;
- ["redstone"] = redstone;
- ["shell"] = shell;
- ["string"] = string;
- ["table"] = table;
- ["term"] = term;
- ["textutils"] = textutils;
- ["turtle"] = turtle;
- ["vector"] = vector;
- ["window"] = window;
- },
- ["path"] = "/System/libs/?;/System/libs/?.lib;/System/libs/?.lua;/libs/?;/libs/?.lib;/libs/?.lua",
- ["loaders"] = {
- [1] = function(name)
- if package.preload[name] then
- return true, package.preload[name]
- else
- return false, 'in "package.preload,"'
- end
- end;
- [2] = function(name)
- local path = string.gsub(package.path, "?", name)
- local result
- local file
- for subPath in string.gmatch(path, "([^;]+)") do
- file = io.open(subPath)
- if file then
- result = subPath
- break
- end
- end
- if not result then
- return false, 'in "package.path" with name "'..name..'"'
- end
- local text = file:read("*a")
- local module, err = load(text, name)
- if not module then
- return false, "Error in the module file: "..err
- end
- local env, meta = { }
- env._ENV = env
- meta = {
- __index = _G;
- name = tostring(env):gsub("table", "module");
- __tostring = function()
- return meta.name
- end;
- }
- setmetatable(env, meta)
- setfenv(module, env)
- return true, module
- end
- },
- ["preload"] = { },
- }
- function _G.require( ... )
- local modules = { }
- for key, value in ipairs{ ... } do
- local message = ""
- if type(value) ~= "string" then error("Bad argument #"..key..": string expected, got "..type(value), 2) end
- if package.loaded[value] then
- modules[key] = package.loaded[value]
- else
- message = message..'Can\'t find module #'..key..' in "package.loaded",\n'
- for i=1, #package.loaders do
- local boolean, foo = package.loaders[i](value)
- if boolean then
- local ok, module = pcall(foo)
- if not ok then message = message..'Error in module "'..value..'": '..module.."\n"
- else
- if module == nil then
- if next(getfenv(foo)) then
- module = getfenv(foo)
- else
- module = true
- end
- end
- if type(module) == "table" and getmetatable(module) == nil then
- local meta
- meta = {
- __index = _G;
- name = tostring(module):gsub("table", "module");
- __tostring = function()
- return meta.name
- end;
- }
- setmetatable(module, meta)
- end
- modules[key] = module
- package.loaded[value] = module
- break
- end
- else
- message = message..foo.."\n"
- end
- end
- if not modules[key] then
- error(message, 2)
- end
- end
- end
- return unpack(modules)
- end
- function _G.module(name, lib)
- if type(name) ~= "string" then error("Bad argument: string expected, got "..type(name), 2) end
- if lib == nil then lib = { } end
- if package.loaded[name] then error("Module with name \""..name.."\" has already loaded", 2)
- else package.loaded[name] = lib end
- return lib
- end
- function _G.unload(name)
- package.loaded[name] = nil
- end
- function os.multiEvent( ... )
- if not ... then
- return coroutine.yield()
- end
- while true do
- local var, var2 = { coroutine.yield() }
- for _, value in ipairs{ ... } do
- if var[1] == value then
- return unpack( var )
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment