diff options
-rw-r--r-- | src/bindings/notcurses.nim | 66 | ||||
-rw-r--r-- | src/bindings/quickjs.nim | 5 | ||||
-rw-r--r-- | src/io/request.nim | 17 | ||||
-rw-r--r-- | src/js/javascript.nim | 9 |
4 files changed, 7 insertions, 90 deletions
diff --git a/src/bindings/notcurses.nim b/src/bindings/notcurses.nim deleted file mode 100644 index 8e1cd718..00000000 --- a/src/bindings/notcurses.nim +++ /dev/null @@ -1,66 +0,0 @@ -const notcurseslib = (func(): string = - when defined(windows): return "libnotcurses-core.dll" - elif defined(macos): return "libnotcurses-core(|.3|.3.0.8).dylib" - else: return "libnotcurses-core.so(|.3|.3.0.8)" # assume posix -)() - -{.push cdecl, dynlib: notcurseslib.} - -const - NCOPTION_INHIBIT_SETLOCALE* = 0x0001u64 - NCOPTION_NO_CLEAR_BITMAPS* = 0x0002u64 - NCOPTION_NO_WINCH_SIGHANDLER* = 0x0004u64 - NCOPTION_NO_QUIT_SIGHANDLERS* = 0x0008u64 - NCOPTION_PRESERVE_CURSOR* = 0x0010u64 - NCOPTION_SUPPRESS_BANNERS* = 0x0020u64 - NCOPTION_NO_ALTERNATE_SCREEN* = 0x0040u64 - NCOPTION_NO_FONT_CHANGES* = 0x0080u64 - NCOPTION_DRAIN_INPUT* = 0x0100u64 - NCOPTION_SCROLLING* = 0x0200u64 - -const - NCDIRECT_OPTION_INHIBIT_SETLOCALE* = 0x0001u64 - NCDIRECT_OPTION_INHIBIT_CBREAK* = 0x0002u64 - NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS* = 0x0008u64 - NCDIRECT_OPTION_VERBOSE* = 0x0010u64 - NCDIRECT_OPTION_VERY_VERBOSE* = 0x0020u64 - -const NCOPTION_CLI_MODE = NCOPTION_NO_ALTERNATE_SCREEN or - NCOPTION_NO_CLEAR_BITMAPS or - NCOPTION_PRESERVE_CURSOR or - NCOPTION_SCROLLING - -type - ncloglevel_e* {.size: sizeof(cint).} = enum - NCLOGLEVEL_SILENT # print nothing once fullscreen service begins - NCLOGLEVEL_PANIC # default. print diagnostics before we crash/exit - NCLOGLEVEL_FATAL # we're hanging around, but we've had a horrible fault - NCLOGLEVEL_ERROR # we can't keep doing this, but we can do other things - NCLOGLEVEL_WARNING # you probably don't want what's happening to happen - NCLOGLEVEL_INFO # "standard information" - NCLOGLEVEL_VERBOSE # "detailed information" - NCLOGLEVEL_DEBUG # this is honestly a bit much - NCLOGLEVEL_TRACE # there's probably a better way to do what you want - - notcurses_options_struct* = object - termtype*: cstring - loglevel*: ncloglevel_e - margin_t*: cuint - margin_r*: cuint - margin_b*: cuint - margin_l*: cuint - flags*: uint64 - - notcurses_options* = ptr notcurses_options_struct - - notcurses* = pointer - - ncdirect* = pointer - -{.push importc.} - -proc ncdirect_core_init*(termtype: cstring, fp: File, flags: uint64): ncdirect -proc ncdirect_stop*(nc: ncdirect): cint - -{.pop.} -{.pop.} diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim index 97aefcc7..306a3b3d 100644 --- a/src/bindings/quickjs.nim +++ b/src/bindings/quickjs.nim @@ -327,8 +327,9 @@ proc JS_NewPromiseCapability*(ctx: JSContext, resolving_funcs: ptr JSValue): JSV proc JS_SetOpaque*(obj: JSValue, opaque: pointer) proc JS_GetOpaque*(obj: JSValue, class_id: JSClassID): pointer proc JS_GetOpaque2*(ctx: JSContext, obj: JSValue, class_id: JSClassID): pointer -proc JS_ParseJSON*(ctx: JSContext, buf: ptr char, buf_len: csize_t, filename: cstring): JSValue -proc JS_ParseJSON2*(ctx: JSContext, buf: ptr char, buf_len: csize_t, filename: cstring, flags: cint): JSValue +proc JS_ParseJSON*(ctx: JSContext, buf: cstring, buf_len: csize_t, filename: cstring): JSValue +proc JS_ParseJSON2*(ctx: JSContext, buf: cstring, buf_len: csize_t, + filename: cstring, flags: cint): JSValue proc JS_NewClassID*(pclass_id: ptr JSClassID): JSClassID proc JS_NewClass*(rt: JSRuntime, class_id: JSClassID, class_def: ptr JSClassDef): cint diff --git a/src/io/request.nim b/src/io/request.nim index 4a123a0b..da3437fb 100644 --- a/src/io/request.nim +++ b/src/io/request.nim @@ -310,25 +310,16 @@ proc close*(response: Response) {.jsfunc.} = if response.body != nil: response.body.close() +#TODO text, json should return promises, not blocking reads proc text*(response: Response): string {.jsfunc.} = if response.body == nil: return "" result = response.body.readAll() response.close() -#TODO: get rid of this -proc readAll*(response: Response): string {.jsfunc.} = - return response.text() - -proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue): JSValue {.cdecl.} = - let op = getOpaque0(this) - if unlikely(not ctx.isInstanceOf(this, "Response") or op == nil): - return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response") - let response = cast[Response](op) +proc json(response: Response, ctx: JSContext): JSValue = var s = response.text() - if s == "": - return JS_ThrowSyntaxError("unexpected end of input") - return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>") + return JS_ParseJSON(ctx, cstring(s), cast[csize_t](s.len), cstring"<input>") func credentialsMode*(attribute: CORSAttribute): CredentialsMode = case attribute @@ -342,5 +333,5 @@ proc addRequestModule*(ctx: JSContext) = TabGetSet(name: "url", get: Request_url), TabGetSet(name: "referrer", get: Request_referrer) ]) - ctx.registerType(Response, extra_funcs = [TabFunc(name: "json", fun: Response_json)]) + ctx.registerType(Response) ctx.registerType(Headers) diff --git a/src/js/javascript.nim b/src/js/javascript.nim index 17bc555a..4de01aa9 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -1698,7 +1698,6 @@ type macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0, asglobal = false, nointerface = false, name: static string = "", extra_getset: static openarray[TabGetSet] = [], - extra_funcs: static openarray[TabFunc] = [], namespace: JSValue = JS_NULL): JSClassID = result = newStmtList() let tname = t.strVal # the nim type's name. @@ -1797,14 +1796,6 @@ macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0, asglobal = let m = x.magic tabList.add(quote do: JS_CGETSET_MAGIC_DEF(`k`, `g`, `s`, `m`)) - for x in extra_funcs: - #TODO TODO TODO ditto. wtf - if repr(x) != "" and repr(x) != "[]": - let name = x.name - let fun = x.fun - tabList.add(quote do: - JS_CFUNC_DEF(`name`, 0, (`fun`))) - if ctorFun != nil: sctr = ctorFun result.add(ctorImpl) |