Thanks to visit codestin.com
Credit goes to github.com

Skip to content

netpyoung/pt.c-interop-in-clojure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

Interop with C in Clojure

problem

  • How to load library.
  • writing wrapper function.
  • C structure layout for pointer access.

Java & C Binding

namedate
JNI1997.02
JNA2007.05
JNR2013.02
JavaCPP2015.07
panamaEAB

JNI

JNA

JNR

SKIP JavaCPP

Panama

performance check

https://github.com/yulewei/java-ffi-demo JNI > JNR > JNA (Direct Mapping) > JNA (Interface Mapping)

JNI Example

  1. prepare native c library
  2. writing && compile interop java file
  3. generate interop c header
  4. writing && c`mpile interop c library
  5. writing && build clojure project with interop java file
  6. call clojure library with native c library and interop c library

JNA Example

  1. prepare native c library
  2. writing && build clojure project

JNR Example

  1. prepare native c library
  2. writing && build clojure project

SKIP JavaCPP Example

Panama Example

JNA Example (SDL2)

SDL2(C language) binding in clojure

Panama Example (SDL2)

SDL2(C language) binding in clojure

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

SDL Language Bindings

https://www.libsdl.org/languages.php

Ada C# D Go Lua OCaml Pascal Python Rust

CommonLisp?

Java?

Clojure?

java interop types

Native TypeSizeJava TypeCommon Windows Type
char8byteBYTE, TCHAR
short16shortshort WORD
wchar_t16/32charWCHAR, TCHAR
int32intDWORD
intbooleanBOOL
long32/64NativeLongLONG
long long, __int6464long
float32float
double64double
char*C StringStringLPCTSTR
void*pointerPointerLPVOID, HANDLE, LPXXX