11#ifndef ARK_VM_PLUGIN_HPP
12#define ARK_VM_PLUGIN_HPP
16#if defined(ARK_OS_WINDOWS)
17# include <Proxy/MiniWindows.h>
18#elif defined(ARK_OS_LINUX)
21# error "Can not identify the platform on which you are running, aborting"
25#include <system_error>
82 [[nodiscard]]
const std::string&
path()
const {
return m_path; }
92 T
get(
const std::string& procname)
96#if defined(ARK_OS_WINDOWS)
97 if (NULL == (funcptr =
reinterpret_cast<T
>(GetProcAddress(m_instance, procname.c_str()))))
99 throw std::system_error(
100 std::error_code(::GetLastError(), std::system_category()), std::string(
"PluginError: Couldn't find ") + procname);
102#elif defined(ARK_OS_LINUX)
103 if (NULL == (funcptr =
reinterpret_cast<T
>(dlsym(m_instance, procname.c_str()))))
105 throw std::system_error(
106 std::error_code(errno, std::system_category()), fmt::format(
"PluginError: Couldn't find {}, {}", procname, dlerror()));
113#if defined(ARK_OS_WINDOWS)
114 HINSTANCE m_instance;
115#elif defined(ARK_OS_LINUX)
Handling a shared library as an ArkScript plugin.
~SharedLibrary()
Destroy the Shared Library object.
SharedLibrary()
Construct a new Shared Library object.
const std::string & path() const
SharedLibrary(const SharedLibrary &)=delete
Disable copy semantics as this contains a pointer.
void load(const std::string &path)
Load a shared library.
SharedLibrary & operator=(const SharedLibrary &)=delete
Disable copy semantics as this contains a pointer.
void unload() const
Unload the shared library.
T get(const std::string &procname)
Return a function from the shared library.