matlab::cpplib::runMain
Execute a function with its input arguments within the main function
Description
int runMain(std::function<int(std::shared_ptr<MatlabApplication> func,
int, const char**)>std::shared_ptr<MatlabApplication>&& app, int argc,
const char **argv);
Execute a function with its input arguments within the main function.
matlab.cpplib.runMain accepts as input the function you want to
execute, an instance of MATLABApplication, and the inputs to the
function you want to execute. It returns as output a code indicating the success or
failure of execution.
This function can be used on any platform to separate the logic of the primary function
from that of main(). On macOS, it also fulfills the requirements of the Cocoa API
Parameters
std::function<int(std::shared_ptr<MATLABApplication>,
int, const char**)> func | A |
std::shared_ptr<MATLABApplication>&&
app | Instance of |
int argc | Number of input arguments from the command line. |
const char **argv | Input arguments array. |
Return Value
| Return code indicating success (by convention:
|
Examples
Move the MATLABApplication Object into runMain and Terminate It
int myMainFunc(std::shared_ptr<mc::MATLABApplication> app,
const int argc, const char * argv[])
{
try {
// initialize library, call feval, etc.
} catch(const std::exception & exc) {
std::cerr << exc.what() << std::endl;
return -1;
}
return 0; // no error
}
int main(const int argc, const char * argv[])
{
std::vector<std::u16string> options ;
auto matlabApplication = mc::initMATLABApplication(
mc::MATLABApplicationMode::IN_PROCESS,options);
return mc::runMain(myMainFunc, std::move(matlabApplication), argc, argv);
}
Version History
Introduced in R2018a
See Also
matlab::cpplib::initMATLABApplication | matlab::cpplib::convertUTF8StringToUTF16String | matlab::cpplib::convertUTF16StringToUTF8String | matlab::cpplib::initMATLABLibrary | matlab::cpplib::initMATLABLibraryAsync | matlab::cpplib::MATLABLibrary::feval | matlab::cpplib::MATLABLibrary::fevalAsync | matlab::cpplib::MATLABLibrary::waitForFiguresToClose