mirror of
https://github.com/Reuh/candran.git
synced 2025-10-28 10:19:30 +00:00
Rename lib to candran
This commit is contained in:
parent
5fff7612f4
commit
dc19ac56a9
13 changed files with 2007 additions and 2000 deletions
40
lib/util.can
40
lib/util.can
|
|
@ -1,40 +0,0 @@
|
|||
local util = {}
|
||||
|
||||
function util.search(modpath, exts={})
|
||||
for _, ext in ipairs(exts) do
|
||||
for path in package.path:gmatch("[^;]+") do
|
||||
local fpath = path:gsub("%.lua", "."..ext):gsub("%?", (modpath:gsub("%.", "/")))
|
||||
local f = io.open(fpath)
|
||||
if f then
|
||||
f:close()
|
||||
return fpath
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.load(str, name, env)
|
||||
if _VERSION == "Lua 5.1" then
|
||||
local fn, err = loadstring(str, name)
|
||||
if not fn then return fn, err end
|
||||
return env ~= nil and setfenv(fn, env) or fn
|
||||
else
|
||||
if env then
|
||||
return load(str, name, nil, env)
|
||||
else
|
||||
return load(str, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function util.merge(...)
|
||||
local r = {}
|
||||
for _, t in ipairs({...}) do
|
||||
for k, v in pairs(t) do
|
||||
r[k] = v
|
||||
end
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
return util
|
||||
Loading…
Add table
Add a link
Reference in a new issue