diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-18 23:15:21 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-18 23:15:21 +0100 |
| commit | 28fefabdeb685f4777ad2ad2ebf05e5e94e179d6 (patch) | |
| tree | 56cd048df4a6987b4d9ef5924942119b3f2fd8aa /lib/monoucha0/test/basic.nim | |
| parent | b56abad0883c0b4179f9c329a7169bb544fac4a5 (diff) | |
| parent | 33efaee783c2adb20df019a8bc924411c4a97e7f (diff) | |
| download | chawan-28fefabdeb685f4777ad2ad2ebf05e5e94e179d6.tar.gz | |
Add 'lib/monoucha0/' from commit '33efaee783c2adb20df019a8bc924411c4a97e7f'
git-subtree-dir: lib/monoucha0
git-subtree-mainline: b56abad0883c0b4179f9c329a7169bb544fac4a5
git-subtree-split: 33efaee783c2adb20df019a8bc924411c4a97e7f
Diffstat (limited to 'lib/monoucha0/test/basic.nim')
| -rw-r--r-- | lib/monoucha0/test/basic.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/monoucha0/test/basic.nim b/lib/monoucha0/test/basic.nim new file mode 100644 index 00000000..25161b1a --- /dev/null +++ b/lib/monoucha0/test/basic.nim @@ -0,0 +1,26 @@ +import std/unittest + +import monoucha/fromjs +import monoucha/javascript +import monoucha/optshim + +type MyGlobal = ref object + s: string + +proc testFun(x: MyGlobal): string {.jsfunc.} = + return "Hello, " & x.s + +test "hello JS": + let rt = newJSRuntime() + let ctx = rt.newJSContext() + let global = MyGlobal(s: "world!") + ctx.registerType(MyGlobal, asglobal = true) + ctx.setGlobal(global) + const code = "testFun()" + let val = ctx.eval(code, "<test>", 0) + var res: string + check ctx.fromJS(val, res).isSome + check res == "Hello, world!" + JS_FreeValue(ctx, val) + ctx.free() + rt.free() |