wstp-node 0.6.6 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,43 +1,60 @@
1
- # wstp-backend — API Reference
1
+ # wstp-backend
2
2
 
3
3
  **Author:** Nikolay Gromov
4
4
 
5
- Native Node.js addon for Wolfram kernel communication over WSTP supports full
6
- notebook-style evaluation with automatic `In`/`Out` history, real-time streaming,
7
- and an internal evaluation queue. All blocking I/O runs on the libuv thread pool;
8
- the JS event loop is never stalled.
5
+ Native Node.js addon for Wolfram kernel communication over WSTP. Enables notebook-style evaluation, real-time streaming, and robust kernel management from JavaScript.
6
+
7
+ ## Purpose
8
+
9
+ This package lets you control a WolframKernel process from Node.js, supporting both batch and interactive notebook-style evaluation. It is ideal for building VS Code extensions, automating Mathematica workflows, and integrating Wolfram computation into JS apps.
10
+
11
+ ## Installation
12
+
13
+ ### Prerequisites
14
+
15
+ | Requirement | Notes |
16
+ |-------------|-------|
17
+ | macOS | Tested on macOS 13+ (ARM64 and x86-64) |
18
+ | Windows 10/11 x64 | See [InstallationWindows.md](InstallationWindows.md) for the full Windows guide |
19
+ | Linux x86-64 / ARM64 | Should work with standard `node-gyp` toolchain |
20
+ | Node.js ≥ 18 | Earlier versions may work but are untested |
21
+ | Clang / Xcode Command Line Tools (macOS) | `xcode-select --install` |
22
+ | MSVC Build Tools with C++ workload (Windows) | Visual Studio 2019+ or Build Tools |
23
+ | Wolfram Mathematica or Wolfram Engine | Provides `WolframKernel` and the WSTP SDK headers/libraries |
24
+
25
+ ### 1. Clone
26
+
27
+ ```bash
28
+ git clone https://github.com/vanbaalon/mathematica-wstp-node.git
29
+ cd mathematica-wstp-node
30
+ ```
31
+
32
+ ### 2. Install Node dependencies
33
+
34
+ ```bash
35
+ npm install
36
+ ```
37
+
38
+ ### 3. Build the native addon
39
+
40
+ ```bash
41
+ bash build.sh
42
+ ```
43
+
44
+ ## Quick Start
9
45
 
10
46
  ```js
11
- const { WstpSession, WstpReader, setDiagHandler } = require('./build/Release/wstp.node');
47
+ const { WstpSession } = require('./build/Release/wstp.node');
48
+ const session = new WstpSession();
49
+ session.evaluate('Prime[10]').then(r => {
50
+ console.log(r.result.value); // 29
51
+ session.close();
52
+ });
12
53
  ```
13
54
 
14
- ---
55
+ ## API Reference
15
56
 
16
- ## Table of Contents
17
-
18
- 1. [Installation](#installation)
19
- 2. [Batch mode vs interactive mode](#batch-mode-vs-interactive-mode)
20
- 3. [Return types — `WExpr` and `EvalResult`](#return-types)
21
- 4. [`WstpSession` — main evaluation session](#wstpsession)
22
- - [Constructor](#constructor) — launch a kernel and open a session
23
- - [`evaluate(expr, opts?)`](#evaluateexpr-opts) — queue an expression for evaluation; supports streaming `Print` callbacks
24
- - [`sub(expr)`](#subexpr) — priority evaluation that jumps ahead of the queue, for quick queries during a long computation
25
- - [`abort()`](#abort) — interrupt the currently running evaluation
26
- - [`closeAllDialogs()`](#closealldialogs) — immediately reject all pending dialog promises and reset dialog state
27
- - [`dialogEval(expr)`](#dialogevalexpr) — evaluate inside an active `Dialog[]` subsession
28
- - [`exitDialog(retVal?)`](#exitdialogretval) — exit the current dialog and resume the main evaluation
29
- - [`interrupt()`](#interrupt) — send a low-level interrupt signal to the kernel
30
- - [`createSubsession(kernelPath?)`](#createsubsessionkernelpath) — spawn an independent parallel kernel session
31
- - [`close()`](#close) — gracefully shut down the kernel and free resources
32
- - [`isOpen` / `isDialogOpen`](#isopen--isdialogopen) — read-only status flags
33
- - [Dynamic eval API](#dynamic-eval-api) — register expressions for automatic periodic evaluation
34
- 5. [`WstpReader` — kernel-pushed side channel](#wstpreader)
35
- 6. [`setDiagHandler(fn)`](#setdiaghandlerfn)
36
- 5. [Usage examples](#usage-examples)
37
- - [Basic evaluation](#basic-evaluation)
38
- - [Interactive mode — In/Out history](#interactive-mode--inout-history)
39
- - [Streaming output](#streaming-output)
40
- - [Concurrent evaluations](#concurrent-evaluations)
57
+ See [API.md](./API.md) for full API details, usage examples, and advanced features.
41
58
  - [Priority `sub()` calls](#priority-sub-calls)
42
59
  - [Abort a long computation](#abort-a-long-computation)
43
60
  - [Dialog subsessions](#dialog-subsessions)
package/binding.gyp CHANGED
@@ -8,7 +8,15 @@
8
8
  "targets": [
9
9
  {
10
10
  "target_name": "wstp",
11
- "sources": ["src/addon.cc"],
11
+ "sources": [
12
+ "src/addon.cc",
13
+ "src/diag.cc",
14
+ "src/wstp_expr.cc",
15
+ "src/drain.cc",
16
+ "src/evaluate_worker.cc",
17
+ "src/wstp_session.cc",
18
+ "src/wstp_reader.cc"
19
+ ],
12
20
 
13
21
  "include_dirs": [
14
22
  "<!@(node -p \"require('node-addon-api').include\")",
Binary file
package/build.sh CHANGED
@@ -98,25 +98,38 @@ echo "WSTP SDK : $WSTP_SDK"
98
98
  NODE_LIB="$(node -p "process.execPath")"
99
99
  echo "Node lib : $NODE_LIB"
100
100
 
101
- # ── compile source ────────────────────────────────────────────────────────────
102
- SOURCE="$SCRIPT_DIR/src/addon.cc"
103
-
104
- echo ""
105
- echo "Compiling $SOURCE …"
106
-
107
- clang++ \
108
- -std=c++17 \
109
- "${OPT_FLAGS[@]}" \
110
- -Wall -Wextra \
111
- -fPIC \
112
- -fvisibility=hidden \
113
- -DBUILDING_NODE_EXTENSION \
114
- -DNAPI_DISABLE_CPP_EXCEPTIONS \
115
- -I "$NODE_HEADERS" \
116
- -I "$NAPI_INCLUDE" \
117
- -I "$WSTP_SDK" \
118
- -c "$SOURCE" \
119
- -o "$OUT_DIR/addon.o"
101
+ # ── compile sources ───────────────────────────────────────────────────────────
102
+ SOURCES=(
103
+ "$SCRIPT_DIR/src/addon.cc"
104
+ "$SCRIPT_DIR/src/diag.cc"
105
+ "$SCRIPT_DIR/src/wstp_expr.cc"
106
+ "$SCRIPT_DIR/src/drain.cc"
107
+ "$SCRIPT_DIR/src/evaluate_worker.cc"
108
+ "$SCRIPT_DIR/src/wstp_session.cc"
109
+ "$SCRIPT_DIR/src/wstp_reader.cc"
110
+ )
111
+
112
+ OBJECTS=()
113
+ for SRC in "${SOURCES[@]}"; do
114
+ BASE="$(basename "$SRC" .cc)"
115
+ OBJ="$OUT_DIR/${BASE}.o"
116
+ OBJECTS+=("$OBJ")
117
+ echo "Compiling $SRC …"
118
+ clang++ \
119
+ -std=c++17 \
120
+ "${OPT_FLAGS[@]}" \
121
+ -Wall -Wextra \
122
+ -fPIC \
123
+ -fvisibility=hidden \
124
+ -DBUILDING_NODE_EXTENSION \
125
+ -DNAPI_DISABLE_CPP_EXCEPTIONS \
126
+ -I "$NODE_HEADERS" \
127
+ -I "$NAPI_INCLUDE" \
128
+ -I "$WSTP_SDK" \
129
+ -I "$SCRIPT_DIR/src" \
130
+ -c "$SRC" \
131
+ -o "$OBJ"
132
+ done
120
133
 
121
134
  echo "Linking $OUTPUT …"
122
135
 
@@ -124,7 +137,7 @@ clang++ \
124
137
  -dynamiclib \
125
138
  -undefined dynamic_lookup \
126
139
  -o "$OUTPUT" \
127
- "$OUT_DIR/addon.o" \
140
+ "${OBJECTS[@]}" \
128
141
  "$WSTP_SDK/libWSTPi4.a" \
129
142
  -framework Foundation \
130
143
  -framework SystemConfiguration \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wstp-node",
3
- "version": "0.6.6",
3
+ "version": "0.7.0",
4
4
  "description": "Native Node.js addon for Wolfram/Mathematica WSTP — kernel sessions with evaluation queue, streaming Print/messages, Dialog subsessions, and side-channel WstpReader",
5
5
  "main": "build/Release/wstp.node",
6
6
  "types": "index.d.ts",