Skip to content

Commit

Permalink
make addQuoted work on nimscript (nim-lang#12717) [backport]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Jenkins authored and alehander92 committed Dec 2, 2019
1 parent 6ee24b9 commit c7db8e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3824,11 +3824,6 @@ elif defined(JS):
proc deallocShared(p: pointer) = discard
proc reallocShared(p: pointer, newsize: Natural): pointer = discard

proc addInt*(result: var string; x: int64) =
result.add $x

proc addFloat*(result: var string; x: float) =
result.add $x

when defined(JS) and not defined(nimscript):
include "system/jssys"
Expand All @@ -3839,6 +3834,12 @@ elif defined(JS):
if x < y: return -1
return 1

when defined(JS) or defined(nimscript):
proc addInt*(result: var string; x: int64) =
result.add $x

proc addFloat*(result: var string; x: float) =
result.add $x

proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} =
## A shorthand for ``echo(errormsg); quit(errorcode)``.
Expand Down
5 changes: 5 additions & 0 deletions tests/compilerapi/myscript.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

import exposed

type NumberHolder = object
ival: int
fval: float

echo "top level statements are executed!"
echo NumberHolder(ival: 10, fval: 2.0)

proc hostProgramRunsThis*(a, b: float): float =
result = addFloats(a, b, 1.0)
Expand Down
1 change: 1 addition & 0 deletions tests/compilerapi/tcompilerapi.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
discard """
output: '''top level statements are executed!
(ival: 10, fval: 2.0)
2.0
my secret
11
Expand Down

0 comments on commit c7db8e3

Please sign in to comment.