lib/ljm-ffi.js
function createSafeAsyncFunction(functionName, functionInfo) {
    return function safeAsyncFunction() {
        // Define a variable to store the error string in.
        var errStr;

        // Check to make sure the arguments seem to be valid.
        if(arguments.length != (functionInfo.args.length + 1)) {
            // Throw an error if an invalid number of arguments were found.
            errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += '.';
            throw new LJMFFIError(errStr);
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                // Throw an error if the last argument is not a function.  This
                // is mandatory for all async function calls.
                errStr = 'Invalid argument; last argument must be a function ';
                errStr += 'but was not. Function name: \'';
                errStr += functionName;
                errStr += '\'.';
                throw new LJMFFIError(errStr);
            }

            // Get a reference to the LJM function being called.
            var ljmFunction = ffi_liblabjack[functionName].async;
            
            // Check to make sure that the function being called has been
            // defined.
            if(typeof(ljmFunction) === 'function') {
                // Define a variable to store the ljmError value in.
                var ljmError;

                try {
                    // Execute the synchronous LJM function.
                    ljmError = ljmFunction.apply(this, arguments);
                } catch(err) {
                    // Throw an error if the function being called doesn't exist.
                    errStr = 'The function: ';
                    errStr += functionName;
                    errStr += ' is not implemented by the installed version of LJM.';
                    throw new LJMFFIError(errStr);
                }

                // Return the ljmError
                return ljmError;
            } else {
                // Throw an error if the function being called doesn't exist.
                errStr = 'The function: ';
                errStr += functionName;
                errStr += ' is not implemented by the installed version of LJM.';
                throw new LJMFFIError(errStr);
            }
        }
    };
}
function createSafeAsyncFunction(functionName, functionInfo) {
    return function safeAsyncFunction() {
        // Define a variable to store the error string in.
        var errStr;

        // Check to make sure the arguments seem to be valid.
        if(arguments.length != (functionInfo.args.length + 1)) {
            // Throw an error if an invalid number of arguments were found.
            errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += '.';
            throw new LJMFFIError(errStr);
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                // Throw an error if the last argument is not a function.  This
                // is mandatory for all async function calls.
                errStr = 'Invalid argument; last argument must be a function ';
                errStr += 'but was not. Function name: \'';
                errStr += functionName;
                errStr += '\'.';
                throw new LJMFFIError(errStr);
            }

            // Get a reference to the LJM function being called.
            var ljmFunction = ffi_liblabjack[functionName].async;
            
            // Check to make sure that the function being called has been
            // defined.
            if(typeof(ljmFunction) === 'function') {
                // Define a variable to store the ljmError value in.
                var ljmError;

                try {
                    // Execute the synchronous LJM function.
                    ljmError = ljmFunction.apply(this, arguments);
                } catch(err) {
                    // Throw an error if the function being called doesn't exist.
                    errStr = 'The function: ';
                    errStr += functionName;
                    errStr += ' is not implemented by the installed version of LJM.';
                    throw new LJMFFIError(errStr);
                }

                // Return the ljmError
                return ljmError;
            } else {
                // Throw an error if the function being called doesn't exist.
                errStr = 'The function: ';
                errStr += functionName;
                errStr += ' is not implemented by the installed version of LJM.';
                throw new LJMFFIError(errStr);
            }
        }
    };
}
function createSafeAsyncFunction ( functionName , functionInfo ) { return function safeAsyncFunction ( ) { // Define a variable to store the error string in. var errStr ; // Check to make sure the arguments seem to be valid. if ( arguments . length != ( functionInfo . args . length + 1 ) ) { // Throw an error if an invalid number of arguments were found. errStr = 'Invalid number of arguments.  Should be: ' ; errStr += functionInfo . args . length . toString ( ) + '.  ' ; errStr += getFunctionArgNames ( functionInfo ) . join ( ', ' ) ; errStr += '.' ; throw new LJMFFIError ( errStr ) ; } else { if ( typeof ( arguments [ functionInfo . args . length ] ) !== 'function' ) { // Throw an error if the last argument is not a function.  This // is mandatory for all async function calls. errStr = 'Invalid argument; last argument must be a function ' ; errStr += 'but was not. Function name: \'' ; errStr += functionName ; errStr += '\'.' ; throw new LJMFFIError ( errStr ) ; } // Get a reference to the LJM function being called. var ljmFunction = ffi_liblabjack [ functionName ] . async ; // Check to make sure that the function being called has been // defined. if ( typeof ( ljmFunction ) === 'function' ) { // Define a variable to store the ljmError value in. var ljmError ; try { // Execute the synchronous LJM function. ljmError = ljmFunction . apply ( this , arguments ) ; } catch ( err ) { // Throw an error if the function being called doesn't exist. errStr = 'The function: ' ; errStr += functionName ; errStr += ' is not implemented by the installed version of LJM.' ; throw new LJMFFIError ( errStr ) ; } // Return the ljmError return ljmError ; } else { // Throw an error if the function being called doesn't exist. errStr = 'The function: ' ; errStr += functionName ; errStr += ' is not implemented by the installed version of LJM.' ; throw new LJMFFIError ( errStr ) ; } } } ; }
Define a function that creates safe LJM ffi calls.
Define a function that creates safe LJM ffi calls .