rbranson/node-ffi — pull request #77 by tjfontaine (2012-09-28 17:17:30+00:00)
Title: add TypeDef to allow for runtime type checking

This is an idea I've been kicking around to let users more aggressively check at runtime that the right argument types are being passed. Specifically trying to handle the opaque pointer situation, though theoretically can be used with any type.

I decided to make it an alternate path such that users who don't want more overhead don't have to use it.

```javascript
var myType = TypeDef(ref.refType(ref.types.void))

var func = ffi.ForeignFunction(somefunc, ref.types.void, [myType])

var instance = ref.alloc(ref.refType(ref.types.void))

// will throw
func(instance)

// will succeed
func(myType.cast(instance))

```