Mercurial Hosting > luan
changeset 628:6510de302f95
add "which" command
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jan 2016 06:42:50 -0700 |
parents | a98812908fbc |
children | 35dde32c02ab |
files | core/src/luan/modules/Which_mod.luan core/src/luan/modules/which.luan |
diffstat | 2 files changed, 62 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/src/luan/modules/Which_mod.luan Mon Jan 18 06:42:50 2016 -0700 @@ -0,0 +1,53 @@ +local Luan = require "luan:Luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local pairs = Luan.pairs or error() +local type = Luan.type or error() +local String = require "luan:String" +local literal = String.literal or error() +local match = String.match or error() +local Io = require "luan:Io" +local print = Io.print or error() + + +local M = {} + +M.uris = { + "luan:Luan" + "luan:Binary" + "luan:Html" + "luan:Io" + "luan:Math" + "luan:Package" + "luan:String" + "luan:Table" + "luan:Thread" + "luan:Time" + "luan:host/Hosting" + "luan:http/Http" + "luan:http/Server" + "luan:lucene/Lucene" + "luan:lucene/Versioning" + "luan:mail/Mail" + "luan:logging/Logging" + "luan:stripe/Stripe" +} + +function M.which(name) + local ptn = "[:./]"..literal(name).."$" + for _, uri in ipairs(M.uris) do + local mod = require(uri) + if match(uri,ptn) ~= nil then + print(uri) + end + if type(mod) == "table" then + for key in pairs(mod) do + if key == name then + print(uri.." "..key) + end + end + end + end +end + +return M
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/src/luan/modules/which.luan Mon Jan 18 06:42:50 2016 -0700 @@ -0,0 +1,9 @@ +local Luan = require "luan:Luan" +local error = Luan.error +local values = Luan.values or error() +local Which_mod = require "luan:Which_mod" +local which = Which_mod.which or error() + +for name in values(...) do + which(name) +end