view core/src/luan/modules/Which_mod.luan @ 629:35dde32c02ab 0.15

change String.matches()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Jan 2016 23:07:52 -0700
parents 6510de302f95
children ca169567ce07
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 matches = String.matches 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 matches(uri,ptn) 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