Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

directly export a Function for each module

better organization
  • Loading branch information...
commit b14280b7c00c2ed04b02038c1d51fbf6ee5390fe 1 parent 76779f9
Nathan Rajlich TooTallNate authored
2  lib/cif.js
View
@@ -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')
2  lib/cif_var.js
View
@@ -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')
11 lib/ffi.js
View
@@ -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  lib/foreign_function_var.js
View
@@ -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')
32 lib/library.js
View
@@ -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 = {}
@@ -73,3 +68,4 @@ exports.Library = function Library (libfile, funcs) {
return lib
}
+module.exports = Library
6 lib/type.js
View
@@ -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)
@@ -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))
@@ -64,4 +64,4 @@ exports.Type = function Type (type) {
debug('returning `ffi_type`', rtn.name)
return rtn
}
-
+module.exports = Type
Please sign in to comment.
Something went wrong with that request. Please try again.