Skip to content

Commit

Permalink
directly export a Function for each module
Browse files Browse the repository at this point in the history
better organization
  • Loading branch information
TooTallNate committed Jun 28, 2012
1 parent 76779f9 commit b14280b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/cif.js
Expand Up @@ -3,7 +3,7 @@
* Module dependencies.
*/

var Type = require('./type').Type
var Type = require('./type')
, assert = require('assert')
, debug = require('debug')('ffi:cif')
, ref = require('ref')
Expand Down
2 changes: 1 addition & 1 deletion lib/cif_var.js
Expand Up @@ -3,7 +3,7 @@
* Module dependencies.
*/

var Type = require('./type').Type
var Type = require('./type')
, assert = require('assert')
, debug = require('debug')('ffi:cif_var')
, ref = require('ref')
Expand Down
11 changes: 7 additions & 4 deletions lib/ffi.js
Expand Up @@ -73,10 +73,13 @@ exports.CIF_var = require('./cif_var')
exports.ForeignFunction = require('./foreign_function')
exports.VariadicForeignFunction = require('./foreign_function_var')
exports.DynamicLibrary = require('./dynamic_library')
exports.Library = require('./library').Library
exports.LIB_EXT = require('./library').LIB_EXT
exports.Library = require('./library')
exports.Callback = require('./callback')
exports.errno = require('./errno')
exports.ffiType = require('./type').Type
exports.FFI_TYPE = require('./type').FFI_TYPE
exports.ffiType = require('./type')

// the shared library extension for this platform
exports.LIB_EXT = exports.Library.EXT

// the FFI_TYPE struct definition
exports.FFI_TYPE = exports.ffiType.FFI_TYPE
2 changes: 1 addition & 1 deletion lib/foreign_function_var.js
Expand Up @@ -4,7 +4,7 @@
*/

var CIF_var = require('./cif_var')
, Type = require('./type').Type
, Type = require('./type')
, _ForeignFunction = require('./_foreign_function')
, assert = require('assert')
, debug = require('debug')('ffi:VariadicForeignFunction')
Expand Down
32 changes: 14 additions & 18 deletions lib/library.js
Expand Up @@ -14,32 +14,27 @@ var DynamicLibrary = require('./dynamic_library')
* i.e. libm -> libm.so on linux
*/

Object.defineProperty(exports, 'LIB_EXT', {
configurable: true
, enumerable: true
, writable: false
, value: {
'linux': '.so'
, 'linux2': '.so'
, 'sunos': '.so'
, 'solaris':'.so'
, 'darwin': '.dylib'
, 'mac': '.dylib'
, 'win32': '.dll'
}[process.platform]
})
var EXT = Library.EXT = {
'linux': '.so'
, 'linux2': '.so'
, 'sunos': '.so'
, 'solaris':'.so'
, 'darwin': '.dylib'
, 'mac': '.dylib'
, 'win32': '.dll'
}[process.platform]

/**
* Provides a friendly abstraction/API on-top of DynamicLibrary and
* ForeignFunction.
*/

exports.Library = function Library (libfile, funcs) {
function Library (libfile, funcs) {
debug('creating Library object for', libfile)

if (libfile && libfile.indexOf(exports.LIB_EXT) === -1) {
debug('appending library extension to library name', exports.LIB_EXT)
libfile += exports.LIB_EXT
if (libfile && libfile.indexOf(EXT) === -1) {
debug('appending library extension to library name', EXT)
libfile += EXT
}

var lib = {}
Expand Down Expand Up @@ -73,3 +68,4 @@ exports.Library = function Library (libfile, funcs) {

return lib
}
module.exports = Library
6 changes: 3 additions & 3 deletions lib/type.js
Expand Up @@ -14,7 +14,7 @@ var bindings = require('./bindings')
* This struct type is used internally to define custom struct rtn/arg types.
*/

exports.FFI_TYPE = FFI_TYPE = Struct()
var FFI_TYPE = Type.FFI_TYPE = Struct()
FFI_TYPE.defineProperty('size', ref.types.size_t)
FFI_TYPE.defineProperty('alignment', ref.types.ushort)
FFI_TYPE.defineProperty('type', ref.types.ushort)
Expand All @@ -27,7 +27,7 @@ assert.equal(bindings.FFI_TYPE_SIZE, FFI_TYPE.size)
* Returns a `ffi_type *` Buffer appropriate for the given "type".
*/

exports.Type = function Type (type) {
function Type (type) {
debug('Type()', type.name || type)
type = ref.coerceType(type)
assert(type.indirection >= 1, 'invalid "type" given: ' + (type.name || type))
Expand Down Expand Up @@ -64,4 +64,4 @@ exports.Type = function Type (type) {
debug('returning `ffi_type`', rtn.name)
return rtn
}

module.exports = Type

0 comments on commit b14280b

Please sign in to comment.