diff --git a/Tutorial/Console_Workflow/Console_Workflow.sln b/Tutorial/Console_Workflow/Console_Workflow.sln index 906628ed..42d70f38 100644 --- a/Tutorial/Console_Workflow/Console_Workflow.sln +++ b/Tutorial/Console_Workflow/Console_Workflow.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "W01_RunningWorkflowScripts" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lib", "Lib\Lib.vcxproj", "{6D6FE50E-FD92-46F1-8897-3045E14BE02B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "W02_InvokingCppClasses", "W02_InvokingCppClasses\W02_InvokingCppClasses.vcxproj", "{ABA9D015-844F-427C-B4A8-9DE69A2A56B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {6D6FE50E-FD92-46F1-8897-3045E14BE02B}.Release|x64.Build.0 = Release|x64 {6D6FE50E-FD92-46F1-8897-3045E14BE02B}.Release|x86.ActiveCfg = Release|Win32 {6D6FE50E-FD92-46F1-8897-3045E14BE02B}.Release|x86.Build.0 = Release|Win32 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Debug|x64.ActiveCfg = Debug|x64 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Debug|x64.Build.0 = Debug|x64 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Debug|x86.ActiveCfg = Debug|Win32 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Debug|x86.Build.0 = Debug|Win32 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Release|x64.ActiveCfg = Release|x64 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Release|x64.Build.0 = Release|x64 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Release|x86.ActiveCfg = Release|Win32 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Tutorial/Console_Workflow/W01_RunningWorkflowScripts/Main.cpp b/Tutorial/Console_Workflow/W01_RunningWorkflowScripts/Main.cpp index 4ee69ca3..81da06d7 100644 --- a/Tutorial/Console_Workflow/W01_RunningWorkflowScripts/Main.cpp +++ b/Tutorial/Console_Workflow/W01_RunningWorkflowScripts/Main.cpp @@ -40,7 +40,8 @@ int main() // initialize the assembly auto globalContext = MakePtr(assembly); - LoadFunction(globalContext, L"")(); + auto initializeFunction = LoadFunction(globalContext, L""); + initializeFunction(); // call main auto mainFunction = LoadFunction(globalContext, L"main"); diff --git a/Tutorial/Console_Workflow/W02_InvokingCppClasses/Main.cpp b/Tutorial/Console_Workflow/W02_InvokingCppClasses/Main.cpp new file mode 100644 index 00000000..5708af26 --- /dev/null +++ b/Tutorial/Console_Workflow/W02_InvokingCppClasses/Main.cpp @@ -0,0 +1,112 @@ +#include + +using namespace vl; +using namespace vl::console; +using namespace vl::collections; +using namespace vl::parsing; +using namespace vl::reflection; +using namespace vl::reflection::description; +using namespace vl::workflow; +using namespace vl::workflow::emitter; +using namespace vl::workflow::runtime; + +namespace myapi +{ + class App : public Object, public Description + { + public: + static WString Get() + { + return Console::Read(); + } + + static void Print(const WString& text) + { + Console::WriteLine(text); + } + }; +} + +#define MYAPI_TYPELIST(F)\ + F(myapi::App)\ + +namespace vl +{ + namespace reflection + { + namespace description + { + MYAPI_TYPELIST(DECL_TYPE_INFO) + MYAPI_TYPELIST(IMPL_CPP_TYPE_INFO) + + using namespace myapi; + +#define _ , + + BEGIN_CLASS_MEMBER(App) + CLASS_MEMBER_STATIC_METHOD(Get, NO_PARAMETER) + CLASS_MEMBER_STATIC_METHOD(Print, { L"text" }) + END_CLASS_MEMBER(App) + +#undef _ + class MyApiTypeLoader : public Object, public ITypeLoader + { + public: + void Load(ITypeManager* manager) + { + MYAPI_TYPELIST(ADD_TYPE_INFO) + } + + void Unload(ITypeManager* manager) + { + } + }; + } + } +} + +const wchar_t ScriptCode[] = LR"Workflow( + +module sampleModule; + +using myapi::*; + +func main(): void +{ + App::Print("Hello, world!"); +} + +)Workflow"; + +int main() +{ + // start reflection + LoadPredefinedTypes(); + WfLoadLibraryTypes(); + GetGlobalTypeManager()->AddTypeLoader(new MyApiTypeLoader); + GetGlobalTypeManager()->Load(); + + { + // prepare Workflow script code + List codes; + codes.Add(WString(ScriptCode, false)); + + // compile code and get assemblies + List> errors; + auto table = WfLoadTable(); + auto assembly = Compile(table, codes, errors); + CHECK_ERROR(assembly && errors.Count() == 0, L"Please check the 'errors' variable."); + + // initialize the assembly + auto globalContext = MakePtr(assembly); + auto initializeFunction = LoadFunction(globalContext, L""); + initializeFunction(); + + // call main + auto mainFunction = LoadFunction(globalContext, L"main"); + mainFunction(); + } + + // stop reflection + DestroyGlobalTypeManager(); +} \ No newline at end of file diff --git a/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj b/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj new file mode 100644 index 00000000..b929f723 --- /dev/null +++ b/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj @@ -0,0 +1,160 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {ABA9D015-844F-427C-B4A8-9DE69A2A56B2} + Win32Proj + W02InvokingCppClasses + 10.0.17763.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)..\..\..\Import;$(IncludePath) + + + true + $(ProjectDir)..\..\..\Import;$(IncludePath) + + + false + $(ProjectDir)..\..\..\Import;$(IncludePath) + + + false + $(ProjectDir)..\..\..\Import;$(IncludePath) + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + true + Console + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + true + Console + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + true + true + true + Console + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + true + true + true + Console + + + + + {6d6fe50e-fd92-46f1-8897-3045e14be02b} + + + + + + + + + \ No newline at end of file diff --git a/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj.filters b/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj.filters new file mode 100644 index 00000000..e25ab333 --- /dev/null +++ b/Tutorial/Console_Workflow/W02_InvokingCppClasses/W02_InvokingCppClasses.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file