Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
627:a98812908fbc | 628:6510de302f95 |
---|---|
1 local Luan = require "luan:Luan" | |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
4 local pairs = Luan.pairs or error() | |
5 local type = Luan.type or error() | |
6 local String = require "luan:String" | |
7 local literal = String.literal or error() | |
8 local match = String.match or error() | |
9 local Io = require "luan:Io" | |
10 local print = Io.print or error() | |
11 | |
12 | |
13 local M = {} | |
14 | |
15 M.uris = { | |
16 "luan:Luan" | |
17 "luan:Binary" | |
18 "luan:Html" | |
19 "luan:Io" | |
20 "luan:Math" | |
21 "luan:Package" | |
22 "luan:String" | |
23 "luan:Table" | |
24 "luan:Thread" | |
25 "luan:Time" | |
26 "luan:host/Hosting" | |
27 "luan:http/Http" | |
28 "luan:http/Server" | |
29 "luan:lucene/Lucene" | |
30 "luan:lucene/Versioning" | |
31 "luan:mail/Mail" | |
32 "luan:logging/Logging" | |
33 "luan:stripe/Stripe" | |
34 } | |
35 | |
36 function M.which(name) | |
37 local ptn = "[:./]"..literal(name).."$" | |
38 for _, uri in ipairs(M.uris) do | |
39 local mod = require(uri) | |
40 if match(uri,ptn) ~= nil then | |
41 print(uri) | |
42 end | |
43 if type(mod) == "table" then | |
44 for key in pairs(mod) do | |
45 if key == name then | |
46 print(uri.." "..key) | |
47 end | |
48 end | |
49 end | |
50 end | |
51 end | |
52 | |
53 return M |