diff options
author | bptato <nincsnevem662@gmail.com> | 2022-10-01 17:04:34 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-10-01 17:04:34 +0200 |
commit | 10d3154eff79ce53b82fa946556f52f3e10eac90 (patch) | |
tree | 49da673df4bc812ee1e3e3966f3d18a50ed2f6a4 /src/bindings | |
parent | 23caa878a3854dd0118792e1c051b5412ec345cc (diff) | |
download | chawan-10d3154eff79ce53b82fa946556f52f3e10eac90.tar.gz |
Binding & macro refactorings
Diffstat (limited to 'src/bindings')
-rw-r--r-- | src/bindings/curl.nim | 63 | ||||
-rw-r--r-- | src/bindings/quickjs.nim | 28 |
2 files changed, 64 insertions, 27 deletions
diff --git a/src/bindings/curl.nim b/src/bindings/curl.nim index 7c88f3f6..0a3f3fd0 100644 --- a/src/bindings/curl.nim +++ b/src/bindings/curl.nim @@ -33,8 +33,8 @@ const CURLINFO_PTR = 0x400000 # same as SLIST CURLINFO_SOCKET = 0x500000 CURLINFO_OFF_T = 0x600000 - CURLINFO_MASK = 0x0fffff - CURLINFO_TYPEMASK = 0xf00000 + CURLINFO_MASK {.used.} = 0x0fffff + CURLINFO_TYPEMASK {.used.} = 0xf00000 {.push cdecl, dynlib: curllib.} @@ -51,6 +51,8 @@ type CURLoption* {.size: sizeof(cint).} = enum # Long CURLOPT_PORT = CURLOPTTYPE_LONG + 3 + CURLOPT_SSLVERSION = CURLOPTTYPE_VALUES + 32 + CURLOPT_TIMECONDITION = CURLOPTTYPE_VALUES + 33 CURLOPT_POST = CURLOPTTYPE_LONG + 47 CURLOPT_FOLLOWLOCATION = CURLOPTTYPE_LONG + 52 CURLOPT_POSTFIELDSIZE = CURLOPTTYPE_LONG + 60 @@ -90,9 +92,25 @@ type # Long CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2 + # Double + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3 + + # S-list + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27 + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28 + + # Pointer + CURLINFO_CERTINFO = CURLINFO_PTR + 34 + CURLINFO_TLS_SESSION = CURLINFO_PTR + 43 + CURLINFO_TLS_SSL_PTR = CURLINFO_PTR + 45 + # Socket CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44 + # Off_t + CURLINFO_SIZE_UPLOAD_T = CURLINFO_OFF_T + 7 + CURLINFO_SIZE_DOWNLOAD_T = CURLINFO_OFF_T + 9 + CURLcode* {.size: sizeof(cint).} = enum CURLE_OK = 0, CURLE_UNSUPPORTED_PROTOCOL, # 1 @@ -221,24 +239,27 @@ type CURLE_UNRECOVERABLE_POLL, # 99 - poll/select returned fatal error CURL_LAST # never use! -proc curl_global_init*(flags: clong): CURLcode {.importc: "curl_global_init".} -proc curl_global_cleanup*() {.importc: "curl_global_cleanup".} - -proc curl_easy_init*(): CURL {.importc: "curl_easy_init".} -proc curl_easy_cleanup*(handle: CURL) {.importc: "curl_easy_cleanup".} -proc curl_easy_setopt*(handle: CURL, option: CURLoption): CURLcode {.importc: "curl_easy_setopt", varargs.} -proc curl_easy_perform*(handle: CURL): CURLcode {.importc: "curl_easy_perform".} -proc curl_easy_getinfo*(handle: CURL, info: CURLINFO): CURLcode {.importc: "curl_easy_getinfo", varargs.} - -proc curl_mime_init*(handle: CURL): curl_mime {.importc: "curl_mime_init".} -proc curl_mime_free*(mime: curl_mime) {.importc: "curl_mime_free".} -proc curl_mime_addpart*(mime: curl_mime): curl_mimepart {.importc: "curl_mime_addpart".} -proc curl_mime_name*(part: curl_mimepart, name: cstring) {.importc: "curl_mime_name".} -proc curl_mime_data*(part: curl_mimepart, data: cstring, datasize: csize_t) {.importc: "curl_mime_name".} -proc curl_mime_filename*(part: curl_mimepart, name: cstring) {.importc: "curl_mime_filename".} -proc curl_mime_filedata*(part: curl_mimepart, filename: cstring) {.importc: "curl_mime_filedata".} - -proc curl_slist_append*(slist: curl_slist, str: cstring): curl_slist {.importc: "curl_slist_append".} -proc curl_slist_free_all*(slist: curl_slist) {.importc: "curl_slist_free_all".} +{.push importc.} + +proc curl_global_init*(flags: clong): CURLcode +proc curl_global_cleanup*() + +proc curl_easy_init*(): CURL +proc curl_easy_cleanup*(handle: CURL) +proc curl_easy_setopt*(handle: CURL, option: CURLoption): CURLcode {.varargs.} +proc curl_easy_perform*(handle: CURL): CURLcode +proc curl_easy_getinfo*(handle: CURL, info: CURLINFO): CURLcode {.varargs.} + +proc curl_mime_init*(handle: CURL): curl_mime +proc curl_mime_free*(mime: curl_mime) +proc curl_mime_addpart*(mime: curl_mime): curl_mimepart +proc curl_mime_name*(part: curl_mimepart, name: cstring) +proc curl_mime_data*(part: curl_mimepart, data: cstring, datasize: csize_t) +proc curl_mime_filename*(part: curl_mimepart, name: cstring) +proc curl_mime_filedata*(part: curl_mimepart, filename: cstring) + +proc curl_slist_append*(slist: curl_slist, str: cstring): curl_slist +proc curl_slist_free_all*(slist: curl_slist) +{.pop.} {.pop.} diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim index d216f6cf..290cbeca 100644 --- a/src/bindings/quickjs.nim +++ b/src/bindings/quickjs.nim @@ -88,6 +88,8 @@ type JSCFunction* = proc (ctx: JSContext, this_val: JSValue, argc: int, argv: ptr JSValue): JSValue {.cdecl.} JSGetterFunction* = proc(ctx: JSContext, this_val: JSValue): JSValue {.cdecl.} JSSetterFunction* = proc(ctx: JSContext, this_val: JSValue, val: JSValue): JSValue {.cdecl.} + JSGetterMagicFunction* = proc(ctx: JSContext, this_val: JSValue, magic: cint): JSValue {.cdecl.} + JSSetterMagicFunction* = proc(ctx: JSContext, this_val: JSValue, val: JSValue, magic: cint): JSValue {.cdecl.} JSInterruptHandler* = proc (rt: JSRuntime, opaque: pointer): int {.cdecl.} JSClassID* = uint32 JSAtom* = uint32 @@ -130,6 +132,8 @@ type generic*: JSCFunction getter*: JSGetterFunction setter*: JSSetterFunction + getter_magic*: JSGetterMagicFunction + setter_magic*: JSSetterMagicFunction JSCFunctionListEntryFunc = object length*: uint8 @@ -236,17 +240,29 @@ template JS_CFUNC_DEF*(n: string, len: uint8, func1: JSCFunction): JSCFunctionLi prop_flags: JS_PROP_WRITABLE or JS_PROP_CONFIGURABLE, def_type: JS_DEF_CFUNC, u: JSCFunctionListEntryU( - `func`: JSCFunctionListEntryFunc(length: len, - cproto: JS_CFUNC_generic, - cfunc: JSCFunctionType(generic: func1)))) + `func`: JSCFunctionListEntryFunc( + length: len, + cproto: JS_CFUNC_generic, + cfunc: JSCFunctionType(generic: func1)))) template JS_CGETSET_DEF*(n: string, fgetter, fsetter: untyped): JSCFunctionListEntry = JSCFunctionListEntry(name: cstring(n), prop_flags: JS_PROP_CONFIGURABLE, def_type: JS_DEF_CGETSET, u: JSCFunctionListEntryU( - getset: JSCFunctionListEntryGetSet(get: JSCFunctionType(getter: fgetter), - set: JSCFunctionType(setter: fsetter)))) + getset: JSCFunctionListEntryGetSet( + get: JSCFunctionType(getter: fgetter), + set: JSCFunctionType(setter: fsetter)))) + +template JS_CGETSET_MAGIC_DEF*(n: string, fgetter, fsetter: untyped, m: cint): JSCFunctionListEntry = + JSCFunctionListEntry(name: cstring(n), + prop_flags: JS_PROP_CONFIGURABLE, + def_type: JS_DEF_CGETSET_MAGIC, + magic: m, + u: JSCFunctionListEntryU( + getset: JSCFunctionListEntryGetSet( + get: JSCFunctionType(getter_magic: fgetter), + set: JSCFunctionType(setter_magic: fsetter)))) {.push header: qjsheader, importc, cdecl.} @@ -289,7 +305,7 @@ proc JS_NewUint32*(ctx: JSContext, val: uint32): JSValue proc JS_NewUint64*(ctx: JSContext, val: uint64): JSValue proc JS_NewBigInt64*(ctx: JSContext, val: int64): JSValue proc JS_NewBigUInt64*(ctx: JSContext, val: uint64): JSValue -proc JS_NewFloat64*(ctx: JSContext, val: uint64): JSValue +proc JS_NewFloat64*(ctx: JSContext, val: cdouble): JSValue proc JS_NewAtomLen*(ctx: JSContext, str: cstring, len: csize_t): JSAtom proc JS_ValueToAtom*(ctx: JSContext, val: JSValue): JSAtom |