This document discusses various approaches to interoperating between Clojure and C code, including JNI, JNA, JNR, and JavaCPP. It focuses on examples of using SDL, a cross-platform multimedia library, from Clojure. Specifically, it provides code samples for binding SDL using JNA and shares a Clojure project that demonstrates this approach. It encourages questions during the presentation through an online chat.
1 of 24
Download to read offline
More Related Content
Interop with c in clojure
1. Interop with C in Clojure
(load native)
netpyoung@gmail.com
April 2019
#1
2. Do you have any Questions?
- for keep time, to save each others time
- If you have questions, during presentation.
- message on slack #clojure-sg with page #numer.
- https://clojurians.slack.com/messages/clojure-sg
- ex) #10 - what is blabla?
- I will answer after presentation.
- so, I can polish this slide from your feedbacks.
#2
3. EunPyoung Kim
KOR -> JPN -> SGP
Game Client Programmer. (since 2012.04 ~ )
I like Lisp (not only clojure)
Im Lazy
because of that I like automatation (code generate also)
I like macro (but don't abuse)
I like Emacs
Cursive
(Neo)Vim.?
https://netpyoung.github.io/
#3
4. What I want & What I did.
I want to trying use SDL library via clojure
I made some examples for c binding.
I want to share approach and experience.
#4
5. Problem?
How to load library.
Writing wrapper function.
C structure layout for pointer access.
#5
6. Java & C Binding
performance check
https://github.com/yulewei/java-ffi-demo
JNI > JNR > JNA (Direct Mapping) > JNA (Interface Mapping)
name date
JNI 1997.02
JNA 2007.03
JNR 2013.02
JavaCPP 2015.07
Panama EAB
#6
No Examples on This
presentation
7. JNI
from JDK 1.1
https://docs.oracle.com/javase/8/docs/technotes/guides/jni/
#7
8. JNI Example
1. prepare native c library
2. writing && compile interop java file
3. generate interop c header
4. writing && compile interop c library
5. writing && build clojure project with interop java file
6. call clojure library with native c library and interop c library
#8
11. JNR
https://github.com/jnr/jnr-ffi
jnr-ffi is a Java library for loading native libraries without writing JNI code by hand, or using
tools such as SWIG.
/skrb/jnr-java-native-runtime
https://www.oracle.com/technetwork/java/jvmls2013nutter-2013526.pdf
#11
17. SDL
Simple DirectMedia Layer
cross-platform development library.
designed to provide low level access to audio, keyboard, mouse, joystick, and
graphics hardware via OpenGL and Direct3D
#17
18. SDL Language Bindings
https://www.libsdl.org/languages.php
Ada
C#
D
Go
Lua
OCaml
Pascal
Python
Rust
#18
19. Java SDL Binding?
https://github.com/javasdl/libjavasdl
using JNA
#19