1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00
candran/lib/util.can
Reuh 4af2b41a0d Candran 0.3.0
* Added @ self alias
* Added short anonymous functions declaration
* Made assignment operators works in every direction, except up, down,
behind and below, because this would be hard to visualize.
* Moved files around.
* Error rewriting.
* Discover the amazing can commandline tool, which includes a fantastic°
REPL and program running abilities.
* Added functions which plagiarize Lua.
* Added 0.1.0 to the version number.
* If you still love pineapple flavored bread, don't hesitate to show
your feelings.

Also, the tests are out of date. Sad.

°: not really.
2017-08-16 22:33:44 +02:00

40 lines
763 B
Text

local util = {}
function util.search(modpath, exts={"can", "lua"})
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