#!/usr/bin/env ascript

listMethods(type:expr):map = {
	strs = format("classref(`%s).%s", tostring(type), dir(classref(type)).sort())
	for (str in strs):list {
		eval(parse(str))
	}
}

listGlobalFunctions():map = {
	for (word in dir().sort()):xlist {
		if (word in ["break", "continue", "return"]) { continue }
		value = locals().lookup(tosymbol(word))
		if (isfunction(value)) { value }
	}
}

listFunctions(m:module):map = {
	for (word in dir(m).sort()):xlist {
		value = locals(m).lookup(tosymbol(word))
		if (isfunction(value)) { value }
	}
}

import(canvas)
import(csv)
import(re)
import(net)
import(sqlite3)
import(win32ole)
import(xml)
funcs = list(
	listGlobalFunctions()
	listFunctions(math, os, path, string, sys, time):flat
	listFunctions(canvas, csv, re, net, sqlite3, win32ole, xml):flat
	listMethods(`binary, `binaryptr, `datetime, `dict, `environment, `error,
		`expr, `file, `filestat, `function, `iterator, `list, `matrix,
		`semaphore, `string, `struct, `uri):flat
	listMethods(`canvas.canvas):flat
	listMethods(`re.match, `re.pattern):flat
	listMethods(`net.socket):flat
	listMethods(`sqlite3.sqlite3):flat
	listMethods(`win32ole.ole):flat
	listMethods(`xml.parser, `xml.element):flat
)
if (sys.argv.len() < 2) {
	printf("%s %s\n", chooseif(funcs:*help():*isempty(), " ", "*"), funcs)
	[cntDone, cnt] = [funcs:*help():*isempty().count(false), funcs.len()]
	printf("progress of help implementation: %d/%d (%.1f%%)\n",
									cntDone, cnt, cntDone / cnt * 100)
} else {
	text = sys.argv[1]
	for (func in funcs.filter(funcs:*fullname():*find(text))) {
		println()
		help(func)
	}
}
