Skip to content

Instantly share code, notes, and snippets.

@greghull
greghull / nacl.lua
Created August 27, 2015 17:15
LuaJIT FFI Bindings to libsodium. Only binding the original NACL functions.
ffi = require "ffi"
base64 = require "base64"
nacl = ffi.load "sodium"
-- Stuff needed for random bytes
ffi.cdef [[
void randombytes(unsigned char * const buf, const unsigned long long buf_len);
]]
@greghull
greghull / nacl.go
Last active August 29, 2015 14:27
Golang libsodium bindings
package nacl
// Using libsodium for ease of building, but only relying on the original
// libnacl functions.
// #cgo LDFLAGS: -lsodium
// #include <sodium.h>
import "C"
import (
"encoding/hex"
@greghull
greghull / nacl.rkt
Last active August 29, 2015 14:27
Racket FFI bindings for libnacl
(require ffi/unsafe
ffi/unsafe/alloc
ffi/unsafe/define
test-engine/racket-tests)
(define (bytes->hex-string bstr)
(let* ([len (bytes-length bstr)]
[bstr2 (make-bytes (* len 2))]
[digit
(lambda (v)
@greghull
greghull / hoedown.rkt
Last active August 29, 2015 14:27
A Racket FFI binding to libhoedown -- Easily render Markdown (with lots of nice extensions) from Racket
;; A simple racket example that shows how to use FFI to bind to libhoedown
;; The end goal is to be able to make a simple function call:
;;
;; (markdown "Hello, world") ---> "<p>Hello, world</p>\n"
(require ffi/unsafe
ffi/unsafe/define
ffi/unsafe/alloc
test-engine/racket-tests)