# LibraryFunctionLoad with variable number of arguments

Posted 7 years ago
5707 Views
|
4 Replies
|
1 Total Likes
|
 Hi, I have studied compiling functions from language C to Mathematica as LibraryLink. Do you know how can I connect function with variable count of inputs? I used precompiled example: DLLEXPORT int demoNoArguments(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) { mint b = Argc; MArgument_setInteger(Res, b); return LIBRARY_NO_ERROR; } From this code is clear that number of arguments is defined somewhere outside.I would like prepare override function (multiple definitions of symbol) like this: demo1=LibraryFunctionLoad["demo", "demoNoArguments", {Integer}, Integer]; demo1=LibraryFunctionLoad["demo", "demoNoArguments", {Integer, Integer}, Integer]; or better: demo1=LibraryFunctionLoad["demo", "demoNoArguments", {_Integer..}, Integer]; but if I try to define function again, I see message:"LibraryFunction::overload: The function demoNoArguments has already been loaded with argument types {Integer,Integer}. The new function will be an overload for different types. >>"second choice is not possible to use because I see error:LibraryFunction::btype: "Invalid type and/or rank specification in _Integer... "Does anyone have any advice?
4 Replies
Sort By:
Posted 7 years ago
 Hi,Not sure whether it answers your question, but if you need tensor-like arguments, then here is how Mathematica does it: F = Compile[{{n, _Integer,1}},n^2, CompilationTarget -> "C" ]; ExportString[F,"C"] I.M.
Posted 7 years ago
 Hi,Thank you for your answer. Using matrix or tensor is workaround but good idea. Next worse workaround is this: demo1[arg___Integer] := (LibraryFunctionLoad["demo", "demoNoArguments", ConstantArray[Integer, Length[{arg}]], Integer][arg]) Problem is that symbol associated with compiled function cannot be defined for other argument.