Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1.     // SDK
  2.     auto corecrlDir = Environment::getVariable(
  3.         "CORECLR_DIR",
  4.         "~/.dnx/runtimes/dnx-coreclr-linux-x64.1.0.0-rc2-20221/bin/");
  5.     //auto corecrlDir = "C:\\Users\\Javier\\.dnx\\runtimes\\dnx-coreclr-win-x64.1.0.0-rc1-update1\\bin";
  6.  
  7.     log.debug("CORECLR_DIR = ", corecrlDir);
  8.     log.debug("CORECLR_DIR EXISTS? = ", FileUtils::exists(corecrlDir));
  9.  
  10.     // CoreCLRConfig
  11.     coreclr::Config config { corecrlDir };
  12.     log.debug("CORECLR_LIB = ", config.coreclrLib());
  13.     log.debug("CORECLR_LIB EXISTS? = ", FileUtils::exists(config.coreclrLib()));
  14.     // CoreCLREmbedded
  15.  
  16.     auto host = coreclr::Host::make_shared(config);
  17.     host->init("../sample/libs");
  18.  
  19.     if (host->isValid())
  20.     {
  21.         const auto dll = "../sample/libs/sample.dll";
  22.         const auto className = "Sample.Test";
  23.        
  24.         FunctionFactory factory(host, dll, className);
  25.  
  26.         auto getInt = factory.create(
  27.             "GetInt",
  28.             Type::Int, Type::Void);
  29.         auto addTwo = factory.create(
  30.             "AddTwo",
  31.             Type::Int, Type::Int);
  32.         auto toggleBool = factory.create(
  33.             "ToggleBool",
  34.             Type::Bool, Type::Bool);
  35.         auto echo = factory.create(
  36.             "Echo",
  37.             Type::Void, Type::String);
  38.         auto returnEcho = factory.create(
  39.             "ReturnEcho",
  40.             Type::String, Type::String);
  41.         auto echoIntArray = factory.create(
  42.             "EchoIntArray",
  43.             Type::Void, Type::IntArray);
  44.  
  45.         int r1 = getInt.invoke<int>();
  46.         int r2 = addTwo.invoke<int>(r1);
  47.         bool b1 = toggleBool.invoke<bool>(false);
  48.         echo.invoke<void>("Hola cacerola ? ");
  49.         auto str = returnEcho.invoke<std::string>("Hola desde c++");
  50.         auto intArr = std::vector<int>{1,2,3,4,5};
  51.         echoIntArray.invoke<void>(intArr);
  52.        
  53.         log.debug("Result = ", r1);
  54.         log.debug("Result 2 = ", r2);
  55.         log.debug("Toggle Bool = ", b1);
  56.         log.debug("ReturnEcho = ", str);
  57.  
  58.         host->shutdown();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement