babashka 2026-08-21

Opens up a whole new world (well, at least a whole old world)! Your output of new features is just so impressive, @borkdude

yeah it opens up a new ecosystem, I'm happy this is working

what happens in the error case? An exception?

depends what error

similar errors as with directly using java.foreign

Initial FFI support is now merged on master! User docs: https://github.com/babashka/babashka/blob/master/doc/ffi.md Examples: bb examples/ffi/<TAB> <RET> Includes PacMan, Doom, Helitorus (raylib examples), libpython, etc. You can install the master build with:

bash <(curl ) --dev-build --dir /tmp --dynamic
The --dynamic flag is important for Linux since we ship the static binary by default. I urge you to play around with. the FFI by reading the docs (or pointing your LLM to it if you fancy that), trying the examples and then trying your own favorite native libraries with bb!

🔥 11

Now I really need to make this work with the build. Looks awesome!

I am making a good progress cleaning up Jank's Raylib examples, will give this a try shortly if I still staying awake for a bit. If not I will do that first thing tomorrow. Awesome works as always!

the API is similar to jolt. if you run into trouble let me know, the API can be changed, it's still young

👍 1

This is really cool. Does this mean we don't really need pods anymore if we have FFI support?

That's how I'd expect it to eventually go

👍 1

glad that we have doom now

it's a very basic version though ;)

🔥 1

The first babashka FFI lib: https://github.com/babashka/ffi-duckdb 🦆 duckie

🦆 8
🔥 5

hacker news loves duckdb - I imagine a post about this would do well there.

This probably won't impress HN, since it's kind of easy to build an FFI lib around duckdb

I was reading the code, and I wonder if the double c-destroy-prepare in the run* function's error path is intentional.

Must. Exercise. FFI. Moar. So here is another FFI lib: https://github.com/babashka/ffi-sqlite3#clojure-functions-in-sql One particularly cool thing you can do (which you could not do with the sqlite pod) is register a Clojure function you can run in sqlite3: https://github.com/babashka/ffi-sqlite3#clojure-functions-in-sql Thanks @andersmurphy for the idea

💯 1
❗ 3
🔥 1
❤️ 5

Call a Clojure function from sqlite? Nice!

Yes, it's amazing

@huahaiy Perhaps it's time to make a shared datalevin library so we can increase compatibility compared to the pod :)

@huahaiy This lib could also be used from other languages like JS etc perhaps

Certainly. It is one of the earliest ticket of Datalevin https://github.com/datalevin/datalevin/issues/37 I will see what I can do.

🚀 2

@huahaiy That's cool. I don't know if it's feasible to get the same "register a babashka function to run in the db" using this, but that's what reminded me of datalevin since there is a special trick for this in the pod

@borkdude glad to see you run with it application functions are awesome!

Also cool to see you add aggregates, was on my list but never got round to it.

Mostly did these two libs to see if I have enough coverage for the FFI stuff

but so far so good

🔥 1

it looks similar but there are some differences. best to read the doc here: https://github.com/babashka/babashka/blob/master/doc/ffi.md e.g. callback lifetimes are explicit, for perf and GC

Oh nice. That's a good addition. Does it solve the library loading order when using bundled libraries?

I had to add a hack around coffi as sometimes system libraries would shadow bundled.

haven't thought about that, so I'll await your insights. so far I have not bundled any libs myself, everything I did kinda assumes a system library on the load path or you load it with an explicit name

basically you want to be able to override find symbol (in coffi)

(SymbolLookup/libraryLookup (.getAbsolutePath (io/file file-name))
        sqlite-lookup-arena)

And currently coffi doesn't let you do that. Which means you're at the mercy of what loads first, you also get weird shadowing issues.

you mean, find-symbol needs the lib reference in addition to the symbol?

Doesn't matter when you don't bundle. Honestly, using system stuff is growing on me.

let me find a link to the orginal convo in coffi.

So it's more about narrowing symbol lookup so you don't accidentally pull in system libs.

that is supported with my (cfn lib "the-symbol" ..) but I should probably extend this to find-symbol too where lib is a (load-library ...) return value

(not sure if that fixes your problem)

I'll have to read up more, kinda busy, should've packed my bags for a vacation, but was busy doing FFI today :P

👍 1
🌴 1
🙏 1