# HG changeset patch # User Kim Alvefur # Date 1615297006 -3600 # Node ID 113f3912c7cbb95c254c1d7690508b57089759a8 # Parent 4874b54af344044edd006206a1e5a7007c5ba65e util: Add Teal interface definition files Enables writing code in Teal that is aware of the interfaces and function prototypes in these other utils. Could also be used to do type checks on Lua sources, but this tends to have a lot of noise. diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/compat.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/compat.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,4 @@ +local record lib + xpcall : function (function, function, ...:any):boolean, any +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/crand.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/crand.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ +local record lib + bytes : function (n : number) : string + enum sourceid "OpenSSL" "arc4random()" "Linux" end + _source : sourceid +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/dataforms.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/dataforms.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,52 @@ +local stanza_t = require "util.stanza".stanza_t + +local enum form_type + "form" + "submit" + "cancel" + "result" +end + +local enum field_type + "boolean" + "fixed" + "hidden" + "jid-multi" + "jid-single" + "list-multi" + "list-single" + "text-multi" + "text-private" + "text-single" +end + +local record form_field + + type : field_type + var : string -- protocol name + name : string -- internal name + + label : string + desc : string + + datatype : string + range_min : number + range_max : number + + value : any -- depends on field_type + options : table +end + +local record dataform + title : string + instructions : string + { form_field } -- XXX https://github.com/teal-language/tl/pull/415 + + form : function ( dataform, table, form_type ) : stanza_t +end + +local record lib + new : function ( dataform ) : dataform +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/datetime.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/datetime.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,11 @@ +-- TODO s/number/integer/ once Teal gets support for that + +local record lib + date : function (t : number) : string + datetime : function (t : number) : string + time : function (t : number) : string + legacy : function (t : number) : string + parse : function (t : string) : number +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/encodings.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/encodings.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,27 @@ +-- TODO many actually return Maybe(String) +local record lib + record base64 + encode : function (s : string) : string + decode : function (s : string) : string + end + record stringprep + nameprep : function (s : string, strict : boolean) : string + nodeprep : function (s : string, strict : boolean) : string + resourceprep : function (s : string, strict : boolean) : string + saslprep : function (s : string, strict : boolean) : string + end + record idna + to_ascii : function (s : string) : string + to_unicode : function (s : string) : string + end + record utf8 + valid : function (s : string) : boolean + length : function (s : string) : number + end + record confusable + skeleteon : function (s : string) : string + end + version : string +end +return lib + diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/error.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/error.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,78 @@ +local enum error_type + "auth" + "cancel" + "continue" + "modify" + "wait" +end + +local enum error_condition + "bad-request" + "conflict" + "feature-not-implemented" + "forbidden" + "gone" + "internal-server-error" + "item-not-found" + "jid-malformed" + "not-acceptable" + "not-allowed" + "not-authorized" + "policy-violation" + "recipient-unavailable" + "redirect" + "registration-required" + "remote-server-not-found" + "remote-server-timeout" + "resource-constraint" + "service-unavailable" + "subscription-required" + "undefined-condition" + "unexpected-request" +end + +local record protoerror + type : error_type + condition : error_condition + text : string + code : number +end + +local record error + type : error_type + condition : error_condition + text : string + code : number + context : { any : any } + source : string +end + +local type compact_registry_item = { string, string, string, string } +local type compact_registry = { compact_registry_item } +local type registry = { string : protoerror } +local type context = { string : any } + +local record error_registry_wrapper + source : string + registry : registry + new : function (string, context) : error + coerce : function (any, string) : any, error + wrap : function (error) : error + wrap : function (string, context) : error + is_error : function (any) : boolean +end + +local record lib + record configure_opt + auto_inject_traceback : boolean + end + new : function (protoerror, context, { string : protoerror }, string) : error + init : function (string, string, registry | compact_registry) : error_registry_wrapper + init : function (string, registry | compact_registry) : error_registry_wrapper + is_error : function (any) : boolean + coerce : function (any, string) : any, error + from_stanza : function (table, context, string) : error + configure : function +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/format.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/format.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,4 @@ +local record lib + format : function (string, ... : any) : string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/hashes.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/hashes.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,21 @@ +local type hash = function (msg : string, hex : boolean) : string +local type hmac = function (key : string, msg : string, hex : boolean) : string +local type kdf = function (pass : string, salt : string, i : number) : string + +local record lib + sha1 : hash + sha256 : hash + sha224 : hash + sha384 : hash + sha512 : hash + md5 : hash + hmac_sha1 : hmac + hmac_sha256 : hmac + hmac_sha512 : hmac + hmac_md5 : hmac + scram_Hi_sha1 : kdf + pbkdf2_hmac_sha1 : kdf + pbkdf2_hmac_sha256 : kdf + version : string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/hex.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/hex.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ +local type s2s = function (s : string) : string +local record lib + to : s2s + from : s2s +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/http.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/http.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,9 @@ +local record lib + urlencode : function (s : string) : string + urldecode : function (s : string) : string + formencode : function (f : { string : string }) : string + formdecode : function (s : string) : { string : string } + contains_token : function (field : string, token : string) : boolean + normalize_path : function (path : string) : string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/human/units.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/human/units.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,5 @@ +local lib = record + adjust : function (number, string) : number, string + format : function (number, string, string) : string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/id.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/id.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,9 @@ +local record lib + short : function () : string + medium : function () : string + long : function () : string + custom : function (number) : function () : string + +end +return lib + diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/interpolation.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/interpolation.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ +local type renderer = function (string, { string : any }) : string +local type filter = function (string, any) : string +local record lib + new : function (string, string, funcs : { string : filter }) : renderer +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/jid.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/jid.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,15 @@ +local record lib + split : function (string) : string, string, string + bare : function (string) : string + prepped_split : function (string, boolean) : string, string, string + join : function (string, string, string) : string + prep : function (string, boolean) : string + compare : function (string, string) : boolean + node : function (string) : string + host : function (string) : string + resource : function (string) : string + escape : function (string) : string + unescape : function (string) : string +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/json.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/json.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,5 @@ +local record lib + encode : function (any) : string + decode : function (string) : any, string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/net.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/net.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,13 @@ + +local enum type_strings + "both" + "ipv4" + "ipv6" +end + +local record lib + local_addresses : function (type_strings, boolean) + pton : function (string):string + ntop : function (string):string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/poll.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/poll.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,24 @@ +local record state + enum waiterr + "timeout" + "signal" + end + add : function (state, number, boolean, boolean) : boolean + add : function (state, number, boolean, boolean) : nil, string, number + set : function (state, number, boolean, boolean) : boolean + set : function (state, number, boolean, boolean) : nil, string, number + del : function (state, number) : boolean + del : function (state, number) : nil, string, number + wait : function (state, number) : number, boolean, boolean + wait : function (state, number) : nil, string, number + wait : function (state, number) : nil, waiterr + getfd : function (state) : number +end + +local record lib + new : function () : state + ENOENT : number + EEXIST : number +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/pposix.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/pposix.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,106 @@ +local record pposix + enum syslog_facility + "auth" + "authpriv" + "cron" + "daemon" + "ftp" + "kern" + "local0" + "local1" + "local2" + "local3" + "local4" + "local5" + "local6" + "local7" + "lpr" + "mail" + "syslog" + "user" + "uucp" + end + + enum syslog_level + "debug" + "info" + "notice" + "warn" + "error" + end + + enum ulimit_resource + "CORE" + "CPU" + "DATA" + "FSIZE" + "NOFILE" + "STACK" + "MEMLOCK" + "NPROC" + "RSS" + "NICE" + end + + enum ulimit_unlimited + "unlimited" + end + + type ulimit_limit = number | ulimit_unlimited + + record utsname + sysname : string + nodename : string + release : string + version : string + machine : string + domainname : string + end + + record memoryinfo + allocated : number + allocated_mmap : number + used : number + unused : number + returnable : number + end + + abort : function () + + daemonize : function () : boolean, string + + syslog_open : function (ident : string, facility : syslog_facility) + syslog_close : function () + syslog_log : function (level : syslog_level, src : string, msg : string) + syslog_setminlevel : function (level : syslog_level) + + getpid : function () : number + getuid : function () : number + getgid : function () : number + + setuid : function (uid : string) : boolean, string -- string|number + setgid : function (uid : string) : boolean, string + initgroups : function (user : string, gid : number) : boolean, string + + umask : function (umask : string) : string + + mkdir : function (dir : string) : boolean, string + + setrlimit : function (resource : ulimit_resource, soft : ulimit_limit, hard : ulimit_limit) : boolean, string + getrlimit : function (resource : ulimit_resource) : boolean, ulimit_limit, ulimit_limit + getrlimit : function (resource : ulimit_resource) : boolean, string + + uname : function () : utsname + + setenv : function (key : string, value : string) : boolean + + meminfo : function () : memoryinfo + + atomic_append : function (f : FILE, s : string) : boolean, string, number + + ENOENT : number + _NAME : string + _VESRION : string +end + +return pposix diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/random.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/random.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,4 @@ +local record lib + bytes : function (n:number):string +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/stanza.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/stanza.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,61 @@ +local record lib + + type children_iter = function ( stanza_t ) : stanza_t + type childtags_iter = function () : stanza_t + type maptags_cb = function ( stanza_t ) : stanza_t + + record stanza_t + name : string + attr : { string : string } + { stanza_t | string } + tags : { stanza_t } + + query : function ( stanza_t, string ) : stanza_t + body : function ( stanza_t, string, { string : string } ) : stanza_t + text_tag : function ( stanza_t, string, string, { string : string } ) : stanza_t + tag : function ( stanza_t, string, { string : string } ) : stanza_t + text : function ( stanza_t, string ) : stanza_t + up : function ( stanza_t ) : stanza_t + reset : function ( stanza_t ) : stanza_t + add_direct_child : function ( stanza_t, stanza_t ) + add_child : function ( stanza_t, stanza_t ) + remove_children : function ( stanza_t, string, string ) : stanza_t + + get_child : function ( stanza_t, string, string ) : stanza_t + get_text : function ( stanza_t ) : string + get_child_text : function ( stanza_t, string, string ) : string + child_with_name : function ( stanza_t, string, string ) : stanza_t + child_with_ns : function ( stanza_t, string, string ) : stanza_t + children : function ( stanza_t ) : children_iter, stanza_t, number + childtags : function ( stanza_t, string, string ) : childtags_iter + maptags : function ( stanza_t, maptags_cb ) : stanza_t + find : function ( stanza_t, string ) : stanza_t | string + + top_tag : function ( stanza_t ) : string + pretty_print : function ( stanza_t ) : string + pretty_top_tag : function ( stanza_t ) : string + + get_error : function ( stanza_t ) : string, string, string, stanza_t + indent : function ( stanza_t, number, string ) : stanza_t + end + + record serialized_stanza_t + name : string + attr : { string : string } + { serialized_stanza_t | string } + end + + stanza : function ( string, { string : string } ) : stanza_t + is_stanza : function ( any ) : boolean + preserialize : function ( stanza_t ) : serialized_stanza_t + deserialize : function ( serialized_stanza_t ) : stanza_t + clone : function ( stanza_t, boolean ) : stanza_t + message : function ( { string : string }, string ) : stanza_t + iq : function ( { string : string } ) : stanza_t + reply : function ( stanza_t ) : stanza_t + error_reply : function ( stanza_t, string, string, string, string ) + presence : function ( { string : string } ) : stanza_t + xml_escape : function ( string ) : string +end + +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/strbitop.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/strbitop.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ +local record mod + sand : function (string, string) : string + sor : function (string, string) : string + sxor : function (string, string) : string +end +return mod diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/table.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/table.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ +local record lib + create : function (narr:number, nrec:number):table + pack : function (...:any):{any} +end +return lib + diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/time.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/time.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,6 @@ + +local record lib + now : function () : number + monotonic : function () : number +end +return lib diff -r 4874b54af344 -r 113f3912c7cb teal-src/util/uuid.d.tl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/teal-src/util/uuid.d.tl Tue Mar 09 14:36:46 2021 +0100 @@ -0,0 +1,5 @@ +local record lib + generate : function (number) : string +end +return lib +