sandbox
Loading...
Searching...
No Matches
runtime.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCRIPTING_MANAGED_RUNTIME_HPP_
3#define LIBSBX_SCRIPTING_MANAGED_RUNTIME_HPP_
4
5#include <string>
6#include <functional>
7#include <filesystem>
8
9#include <libsbx/scripting/managed/core.hpp>
10#include <libsbx/scripting/managed/object.hpp>
11#include <libsbx/scripting/managed/message_type.hpp>
12#include <libsbx/scripting/managed/assembly.hpp>
13
14namespace sbx::scripting::managed {
15
16using message_callback_fn = std::function<void(std::string_view, message_level)>;
17using exception_callback_fn = std::function<void(std::string_view)>;
18
20 std::string backend_path;
21
22 message_callback_fn message_callback;
23 message_level message_filter = message_level::all;
24
25 exception_callback_fn exception_callback;
26}; // struct rumtime_config
27
28enum class runtime_status {
29 success,
30 managed_not_found,
31 managed_init_error,
32 dot_net_not_found
33}; // enum class runtime_status
34
35class runtime {
36
37 friend class assembly_load_context;
38
39public:
40
41 auto initialize(rumtime_config settings) -> runtime_status;
42
43 auto shutdown() -> void;
44
45 auto create_assembly_load_context(std::string_view name) -> assembly_load_context;
46
47 auto unload_assembly_load_context(assembly_load_context& load_context) -> void;
48
49private:
50
51 auto load_host_fxr() const -> bool;
52
53 auto initialize_managed() -> bool;
54
55 auto load_functions() -> void;
56
57 auto load_managed_function_ptr(const std::filesystem::path& assembly_path, const char_type* type_name, const char_type* method_name, const char_type* delegate_type = SBX_SCRIPTING_UNMANAGED_CALLERS_ONLY) const -> void*;
58
59 template<typename Function>
60 auto load_managed_function_ptr(const char_type* type_name, const char_type* method_name, const char_type* delegate_type = SBX_SCRIPTING_UNMANAGED_CALLERS_ONLY) const -> Function {
61 return reinterpret_cast<Function>(load_managed_function_ptr(_managed_assembly_path, type_name, method_name, delegate_type));
62 }
63
64private:
65
66 rumtime_config _settings;
67 std::filesystem::path _managed_assembly_path;
68 void* _host_fxr_context = nullptr;
69 bool _initialized = false;
70
71}; // class runtime
72
73}; // namespace sbx::scripting::managed
74
75#endif // LIBSBX_SCRIPTING_MANAGED_RUNTIME_HPP_
Definition: runtime.hpp:35
Definition: runtime.hpp:19