Skip to content

Commit

Permalink
alter script* procs
Browse files Browse the repository at this point in the history
  • Loading branch information
neroist committed Jul 3, 2024
1 parent d69b791 commit fe0d620
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions webui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,13 @@ proc script*(window: Window; script: string; timeout: int = 0, bufferLen: static
## 8 kibibytes. (For larger responses make `bufferLen` larger)

var buffer: array[bufferLen, char]
let error = bindings.script(csize_t window, cstring script, csize_t timeout, cast[cstring](addr buffer), csize_t bufferLen)

let
error = bindings.script(csize_t window, cstring script, csize_t timeout, cast[cstring](addr buffer[0]), csize_t bufferLen)
data = $(cast[cstring](addr buffer[0])) # remove trailing null chars
result.data = newString(buffer.find('\0'))
for i in 0 ..< result.data.len:
result.data[i] = buffer[i]

result.data = data
# webui returns `false` in case of an error, we want to return `true`
result.error = not error

proc scriptClient*(event: Event; script: string; timeout: int = 0, bufferLen: static[int] = 1024 * 8): tuple[data: string; error: bool] =
Expand All @@ -629,12 +630,13 @@ proc scriptClient*(event: Event; script: string; timeout: int = 0, bufferLen: st
## 8 kibibytes. (For larger responses make `bufferLen` larger)

var buffer: array[bufferLen, char]
let error = bindings.scriptClient(event.impl, cstring script, csize_t timeout, cast[cstring](addr buffer), csize_t bufferLen)

let
error = bindings.scriptClient(event.impl, cstring script, csize_t timeout, cast[cstring](addr buffer[0]), csize_t bufferLen)
data = $(cast[cstring](addr buffer[0])) # remove trailing null chars
result.data = newString(buffer.find('\0'))
for i in 0 ..< result.data.len:
result.data[i] = buffer[i]

result.data = data
# webui returns `false` in case of an error, we want to return `true`
result.error = not error

proc run*(window: Window; script: string) =
Expand Down

0 comments on commit fe0d620

Please sign in to comment.