From c7db8e34d07836e24c13e7796bc7e249ddacd0c0 Mon Sep 17 00:00:00 2001 From: Jasper Jenkins Date: Thu, 28 Nov 2019 14:01:17 -0800 Subject: [PATCH] make addQuoted work on nimscript (#12717) [backport] --- lib/system.nim | 11 ++++++----- tests/compilerapi/myscript.nim | 5 +++++ tests/compilerapi/tcompilerapi.nim | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 3f7ad464ac857..657f5621307ea 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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" @@ -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)``. diff --git a/tests/compilerapi/myscript.nim b/tests/compilerapi/myscript.nim index 539b07de112b5..c5d9fe22a6039 100644 --- a/tests/compilerapi/myscript.nim +++ b/tests/compilerapi/myscript.nim @@ -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) diff --git a/tests/compilerapi/tcompilerapi.nim b/tests/compilerapi/tcompilerapi.nim index 494765a8bab5c..edeaa2ba55d3b 100644 --- a/tests/compilerapi/tcompilerapi.nim +++ b/tests/compilerapi/tcompilerapi.nim @@ -1,5 +1,6 @@ discard """ output: '''top level statements are executed! +(ival: 10, fval: 2.0) 2.0 my secret 11