Lines Matching full:function

3 local require=function(modname)if package.loaded[modname]==nil then
4 if type(package.preload[modname])~="function"then
10 package.preload['luke._base']=function()
11 local _ENV=require'std.normalize'{}local function fatal(...)local msg=(...)if select('#',...)>1 then
14 return{diagnose=function(predicate,...)if not predicate then
18 package.preload['luke.cli']=function()
19 …ze'{'luke._base','luke.lukefile','luke.platforms','std.functional',}local function version()print[[
29 local function help()print[[
49 local function opterr(...)local msg=(...)if select('#',...)>1 then
52 local function display(...)return stdout:write(concat{...})end
53 local function dump(...)local s=concat(map(list(...),str))if len(s)>0 then
54 gsub(concat(map(list(...),str)),'\n*$','\n'):gsub('(.-)\n',function(line)stderr:write(' DEBUG: '.…
56 local function interpolate_to_substitute(s)return(gsub(s,'%$([%w_]+)','@%1@'))end
57function(args)local r={clidefs={},valreqs={},fname='lukefile',install={},log=nop,targets={},verbos…
58 end,['%-%-file=(.+)']=function(optarg)r.fname=optarg
59 end,['%-%-value=(.+)']=function(optarg)r.valreqs[#r.valreqs+1]=optarg
60 end,['--quiet']=function()r.write=nop
61 end,['--verbose']=function()r.verbose=display
62 end,['--help']=help,['--version']=version,['([^-][^=]-)=(.+)']=function(name,value)r.clidefs[name]=…
63 end,function(opt)if match(opt,'^-')~=nil then
66 end,validate_arguments=function(parsed)local luke,err=loadluke(parsed.fname)diagnose(luke~=nil,'bad…
68 local targets=call(function()if isempty(parsed.targets)or contains(parsed.targets,'all')then
70 local r=filter(parsed.targets,function(target)if target~='install'and luke.modules[target]==nil then
84 package.preload['luke.compile']=function()
85 …ARS='[%s%$"]',}local function spawn(env,...)local command=interpolate(env,concat({...},' '))return…
86 local function run(L,env,command)L.write(interpolate(env,concat(command,' ')),'\n')local status,err…
92 local function defines(env,deftables)return zip_with(merge({},unpack(deftables)),function(name,valu…
93 local function incdirs(...)return map(flatten(...),function(v)return'-I'..v
95 local function libdirs(...)return map(flatten(...),function(v)return'-L'..v
97 local function c_module_path(objdir,name)return format('%s/%s.$LIB_EXTENSION',objdir,gsub(name,'%.'…
98 local function c_source(module,objdir)local path=gsub(module,'%.','/')local src=c_module_path(objdi…
99 local function lua_source(module,src)local abspath='$INST_LUADIR/'..gsub(module,'%.','/')if match(s…
102function module_to_path(module,sources,objdir)return dropuntil(sources,function(source)return case…
103 return{build_c_module=function(L,env,luke,name)local rules=luke.modules[name]local c_module=c_modul…
105function(modules)return filter(keys(modules),function(name)return dropuntil(modules[name].sources,…
114 package.preload['luke.configure']=function()
115 …,'type.context-manager','type.dict',CCPROGS={'cc','gcc','clang'},}local function logspawn(L,env,..…
119 local function checking(L,...)L.verbose('checking ',concat({...},' '),'... ')end
120 local function found_library(L,x)if x==nil or x==''then
126 local function found_prog(L,x)L.verbose(x and'yes\n'or'no\n')return x
128 local function found_result(L,x)L.verbose(x==0 and'yes\n'or'no\n')return x~=0 and 0 or 1
130 local function bindirs(...)return map(flatten(...),function(v)return v..':'end)end
131 local function compile_command(L,env,config,filename)local command=flatten('$CC','-c','$CFLAGS',inc…
132 local function link_command(L,env,config,a_out,source,lib)local command=flatten('$CC','$CFLAGS',inc…
133function check_executable_in_path(L,env,config,prog)local PATH=concat(bindirs(config.bindir))..get…
134 return with(File(progpath,'r'),function(h)return h and isfile(h.context)and progpath or nil
137 local function check_header_compile(L,env,config,header,extra_hdrs)return with(CTest(),function(con…
138 local function check_struct_member_compile(L,env,config,structname,member,extra_hdrs)return with(CT…
147 local function try_link(L,env,config,lib,symbol)return with(CTest(),TmpFile(),function(conftest,a_o…
156 local function try_compile(L,env,config,headers)return with(CTest(),TmpFile(),function(conftest,a_o…
167 local function check_func_decl(L,env,config,fname,extra_hdrs)return with(CTest(),function(conftest)…
178 local function check_func_link(L,env,config,fname)return with(CTest(),TmpFile(),function(conftest,a…
212 local function add_external_deps(env,config,prefix)if prefix~=nil then
220 local function format_includes(includes)return map(includes or{},function(include)return format('#i…
221 …configure=setmetatable(OrderedDict({checkprog=function(L,env,config)return dropuntil(config.progs,
224function(L,env,config)checking(L,'for',config.checkheader)local extra_hdrs=concat(format_includes(…
229 local trylibs=reduce(libraries,{''},function(r,lib)append(r,'-l'..lib)end)return dropuntil(trylibs,
237function()L.verbose'\n'fatal("required symbol '%s' not found in any of libc, lib%s",symbol,concat(…
238 end,['table']=function()return dropuntil(self,function(fname)if config[fname]~=nil then
240 …keys(config),"', '"))end,function(type)fatal("unsupported configure type '%s'",type)end,})end,})re…
243 checking(L,interpolate(env,'whether $CC works'))local cm=CTest()local works,err=with(cm,function(co…
248 end,config_ldoc=function(L,env)local LDOC=env.LDOC
254 package.preload['luke.environment']=function()
255 …b(_VERSION,'[^0-9%.]+',''),}local env_mt={__index=function(self,varname)return dropuntil(self,func…
259 end)end,}local function interpolate_with(pattern,env,s)local r=''while r~=s do
261 s=gsub(r,pattern,function(varname)return env[varname]or''end)end
264 local function isenv(t)return getmetatable(t)==env_mt
266function(_,v)return getenv(v)end,}),expand=bind(interpolate_with,{'@([^@]+)@'}),interpolate=bind(i…
271 package.preload['luke']=function()
272 …e.configure','luke.environment','luke.lukefile','std.functional',}local function run_ldocs(L,env,l…
273 local function build_modules(L,env)local conf=makeenv(CONFIGENV,env)if not isempty(L.luke.ldocs or{…
277 …ke=run_templates(L,substitute,L.luke)local status=dropuntil(c,isnonzero,function(name)return build…
282 return{main=function(args)local L=validate_arguments(parse_arguments(args))local env=makeenv(L.clid…
284 map(L.valreqs,function(name)print(interpolate(env,concat{name,"='$",name,"'"}))end)exit(0)end
292 package.preload['luke.lukefile']=function()
293 …std.functional','type.context-manager',}local function has_anykey(t,keylist)return any(map(keylist…
295 local function isconfig(x)return istable(x)and has_anykey(x,configure)end
296 local function collect_configs(luke,modulename,configs)configs=configs or{}for k,v in next,luke do
308 local function deepcopy(t)return mapvalues(t,function(v)return case(type(v),{['table']=function()re…
309 local weighting=setmetatable(copy(configure),{__call=function(self,config)local t=config.t[config.k…
314 end})local function config_cmp(a,b)return weighting(a)<weighting(b)end
315 local function fill_templates(env,src,dest)with(File(dest,'w'),function(cm)for line in lines(src)do
319 local function rewrite_template_files(L,env,source)return case(source,{['(.+)%.in']=function(r)L.wr…
320 local function collect_variables(luke,variables)for k,v in next,luke do
322 map(keys(v),function(name)local rootdir=concat{'$',name,'_DIR'}variables[name..'_DIR']='/usr'variab…
327function normalize_configs(config)return cond({[not istable(config)]=config,},{[not isconfig(confi…
328 local function normalize_rules(rules)return case(type(rules),{['nil']=nop,['string']=function()retu…
331 return normalize_configs(rules)end,function(v)fatal("unsupported rule type '%s'",v)end,})end
332 local function unwrap_external_dependencies(luke)if istable(luke.external_dependencies)then
341 return{loadluke=function(filename)local content,err=slurp(File(filename))if content==nil then
351function(luke)return collect_variables(luke,{})end,run_configs=function(L,env,luke)local r=deepcop…
356 package.preload['luke.platforms']=function()
357 …iku','unix'),}local ALLPLATFORMS=reduce(values(CANON),function(acc,platforms)map(platforms,functio…
358 end)end)local function match_uname(canon,uname,x)return match(uname,x)and canon[x]end
359 local function toplatforms(canon,uname)local literalkeys,patternkeys=partition(keys(canon),function
360 local supported=toplatforms(CANON,popen('uname -s'):read'*l')local function isplatform(x)return ALL…
362 local function filter_platforms(t,using,predicate)local r,supported,isplatform={},using or supporte…
374 package.preload['std.functional']=function()
375function(x)return io.type(x)=='file'end,wrap=coroutine.wrap,yield=coroutine.yield,}local function
379 local function call(fn,...)assert(fn~=nil,'cannot call nil-valued function')if iscallable(fn)then
383 local function wrapnonnil(iterator)return function(...)local r=list(iterator(...))if r[1]~=nil then
388 local function each(seq)if type(seq)=='function'then
390 local i,n=0,int(seq.n)or len(seq)return function()if i<n then
395 local function eq(x)return function(y)return x==y
398 local function isnonnil(x)return x~=nil
400 local function mkpredicate(x)return type(x)=='function'and x or eq(x)end
401 local function except(seq,predicate)predicate=mkpredicate(predicate)local r={}for valu in each(seq)…
407 local function visit(x)if type(x)=='table'then
413 local function flatten(...)local r={}for v in wrap(visit),except(list(...),nil)do
418 return{any=function(seq)for valu in each(seq)do
424 end,apply=apply,bind=function(fn,bound)local n=bound.n or maxn(bound)return function(...)local argu…
433 end,call=call,case=function(s,branches)if branches[s]~=nil then
445 end,cond=function(...)for clauseu in each(list(...))do
449 end,contains=function(seq,predicate)if type(predicate)~='function'then
456 end,destructure=destructure,dropuntil=function(seq,predicate,block)if block==nil then
470 end,except=except,filter=function(seq,predicate)predicate=mkpredicate(predicate)local r={}for valu …
475 end,flatten=flatten,foldkeys=function(keymap,dict,combinator)local r={}for k,v in next,dict or{}do
482 end,get=function(dict,key)return(dict or{})[key]end,hoist=function(keylist,dict)local r={}for keyu …
485function(...)return...end,isempty=function(x)return type(x)=='table'and not next(x)end,isfile=isfi…
486 end,isstring=function(x)return type(x)=='string'end,istable=function(x)return type(x)=='table'end,i…
487 end,keys=function(iterable)local r=list()for k in next,iterable or{}do
490 end,map=function(seq,block)local r=list()for valu in each(seq)do
493 end,mapvalues=function(iterable,block)local r={}for k,v in next,iterable or{}do
497 end,nop=function()end,partition=function(seq,block)local r,s=list(),list()for valu in each(seq)do
500 end,pluck=function(keylist,dict)local r={}for keyu in each(keylist)do
503 end,reduce=function(seq,acc,block)if block==nil then
510 end,values=function(iterable)local r=list()for _,v in next,iterable or{}do
513 end,zip_with=function(iterable,block)local r=list()for k,v in next,iterable or{}do
518 package.preload['std.normalize']=function()
526 local pack=table.pack or function(...)return{n=select('#',...),...}end
534 …=match(config,'^([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)')local function copy(iterable)loc…
539 local int=(function(f)if f==nil then
540 return function(x)if type(x)=='number'and ceil(x)-x==0.0 then
545 return function(x)if type(x)=='number'then
550 end)(tointeger)local function iscallable(x)return type(x)=='function'and x or(getmetatable(x)or{}).…
552 local function getmetamethod(x,n)return iscallable((getmetatable(x)or{})[tostring(n)])end
553 local function rawlen(x)if type(x)~='table'then
564 local function len(x)local m=getmetamethod(x,'__len')return m and m(x)or rawlen(x)end
567 loadstring=function(s,filename,env)chunk,err=_loadstring(s,filename)if chunk~=nil and env~=nil then
572 loadstring=function(s,filename,env)return load(s,filename,"t",env)end
573 setfenv=function()end
575 local function keysort(a,b)if int(a)then
580 local function str(x,roots)roots=roots or{}local function stop_roots(x)return roots[x]or str(x,copy…
597 return setmetatable({append=function(seq,v)local n=(int(seq.n)or len(seq))+1
600 …,lines=io.lines,list=pack,loadstring=loadstring,match=string.match,maxn=function(iterable)local n=0
607 end,merge=function(r,...)local argu=pack(...)for i=1,argu.n do
613 end,next=next,open=io.open,pack=pack,pcall=pcall,pop=function(seq)local n,r=seq.n or len(seq)r,seq[…
617 …r,type=type,unpack=function(seq,i,j)return unpack(seq,int(i)or 1,int(j)or int(seq.n)or len(seq))en…
630 package.preload['type.context-manager']=function()
631 local _ENV=require'std.normalize'{'std.functional',}local contextmanager_mt={__index=function(self,…
632 return function(_,...)return self.context[key](self.context,...)end
636 end,}local function ContextManager(release,acquire,...)local fh,err=acquire(...)if not fh then
643 local function context_close(cm)return isfile(cm.context)and close(cm.context)end
644 local function with(...)local argu=list(...)local block=pop(argu)local r=list(apply(block,argu))map…
647 return{ContextManager=ContextManager,CTest=function()local conftest=tmpname()return ContextManager(
650function(fname,mode)return ContextManager(context_close,open,fname,mode)end,Pipe=function(cmd,mode…
653 end,open,fname or tmpname(),mode or'w')end,slurp=function(cm,...)if not cm then
655 return with(cm,function(h)return h:read'*a'end)end,with=with,}
657 package.preload['type.dict']=function()
658 local _ENV=require'std.normalize'{destructure=next,}return{OrderedDict=function(...)local r,argu={}…
664 package.preload['type.path']=function()
666 …urn{basename=function(path)return(gsub(path,BASENAMEPAT,''))end,dirname=function(path)return(gsub(…