Mercurial Hosting > luan
view core/src/luan/modules/Which_mod.luan @ 628:6510de302f95
add "which" command
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jan 2016 06:42:50 -0700 |
parents | |
children | 35dde32c02ab |
line wrap: on
line source
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