elua: make the custom module system default

This commit is contained in:
Daniel Kolesa 2014-04-03 16:51:59 +01:00 committed by Daniel Kolesa
parent 832f652a5a
commit dbaa103d1e
2 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,5 @@
local ffi = require("ffi") local ffi = require("ffi")
local util = erequire("util") local util = require("util")
local elm, evas local elm, evas

View File

@ -5,13 +5,16 @@ local M = {}
local util = select(2, ...) local util = select(2, ...)
local preload = { local preload = {
ffi = package.preload["ffi"],
util = function() return util end util = function() return util end
} }
local loaded = { local loaded = {
} }
local path = "./?.lua;/?/init.lua" for k, v in pairs(package.loaded) do loaded[k] = v end
M.path = "./?.lua;/?/init.lua"
local loaders = { local loaders = {
function(modname) function(modname)
@ -22,7 +25,7 @@ local loaders = {
return v return v
end, end,
function(modname) function(modname)
local fname, err = package.searchpath(modname, path) local fname, err = package.searchpath(modname, M.path)
if not fname then return err end if not fname then return err end
local f, err = loadfile(fname) local f, err = loadfile(fname)
if not f then if not f then
@ -64,9 +67,13 @@ M.require = function(modname)
return loaded[modname] return loaded[modname]
end end
-- register require M.preload = preload
path = (...)(M.require, path) M.loaded = loaded
_G["erequire"] = M.require -- register require
M.path = (...)(M.require, M.path)
_G["require"] = M.require
_G["package"] = M
return M return M