Files
bara-lang/experiments/native-lib/README.md
T
dimgigov ba0b300917 feat: add fullscreen TUI and project updates
- New TUI screens: Main Menu, Compile, Run, REPL, AI Generator, AI Settings, Help
- AI configuration persisted in ~/.config/cljnim/config.json
- Added illwill dependency for terminal UI
- Updated experiments, examples, docs, and core modules
2026-05-09 01:53:23 +03:00

965 B

Clojure/Nim → Native Shared Library

Compile Clojure code to a C shared library (.so / .dll / .dylib).

Why?

  • Embed Clojure in Python/Rust/Go/C via FFI
  • Tiny binaries — no JVM overhead
  • True C ABI — call Clojure functions from any language

Quick Start

./build.sh

This generates:

  • build/libmath.so — shared library
  • build/math.h — C header
  • build/math.nim — intermediate Nim source

Test from C

cd test_client
make
./test_client

Expected output:

square(5) = 25
add(10, 20) = 30
cube(3) = 27
factorial(5) = 120

How it works

  1. cljnim compile-lib — generates Nim with exported proc name*(...)
  2. nim c --app:lib --header — compiles Nim to .so + .h
  3. C client links against the .so and calls functions

Limitations

  • Functions use CljVal (Nim ref object) — client must call Nim runtime helpers
  • NimMain() must be called before using the library