Code covered by the BSD License  

Highlights from
Universal MEX wrapper

Universal MEX wrapper

by

 

Call any function in a shared library from Matlab (with some limits on the function signature).

dl_exec(funName, varargin)
function [varargout] = dl_exec(funName, varargin)
%[varargs] = dl_exec(funName, varargs ...)
%
%Dynamically execute function funName with numeric arguments 
%varargin.  Arguments are cast transparently to 
%equivalent C data types and passed by reference to the function.
%The return value of the function, if any, is not exposed.  
%This method is ideal for calling BLAS-like numerical subroutines.
%Users must load shared libraries into the namespace with
%dl_load prior to calling this method.
%
%RETURNS: The method returns the inputs after the function has acted upon.
%The function returns values in the same order as the input, up to as many
%as are reqested by the user.
%
%SUPPORTED DATA TYPES: char, int8, uint8, int16, uint16, int32, uint32, 
%int64, uint64, single, double, complex float, complex double.  Arrays are
%cloned exactly as presented, while complex datatypes are converted into
%the C/FORTRAN complex format (with the real and imaginary parts of each
%array index stored contiguously).
%
%ERRORS: Errors on encountering a Matlab datatype that cannot be cast.  
%
%BUGS: Users can create bugs by loading libraries that conflict with the
%Matlab base shared object namespace.  In particular, this is a 
%problem when the functions have different signatures.  For instance, on
%x86_64 platforms, Matlab BLAS uses 8-byte integers whereas standard BLAS 
%uses 4-byte integers.  Users should use dl_check to see which library is
%providing a symbol.
%
%SEE ALSO: dl_load, dl_check
%
%LIMITATIONS: dynamic function calls are limited to 100 arguments by
%default.  Users desiring a higher limit can modify the Makefile and
%recompile.
%
%TODO: Extend support to non-void functions and functions with 
%call-by-value arguments, such as by passing arguments wrapped 
%in a cell array by value.  Also, it would be interesing exercise 
%to add support for call-back functions.


	global SO_HANDLE;
	if ~ischar(funName)
		error('First argument must be function name string');
	end
	varargout = cell(nargout,1);
	[varargout{:}] = dl_exec_mex(SO_HANDLE, funName, varargin{:});

Contact us