12#ifndef ARK_VM_PLUGIN_HPP
13#define ARK_VM_PLUGIN_HPP
17#if defined(ARK_OS_WINDOWS)
19# define WIN32_LEAN_AND_MEAN
22#elif defined(ARK_OS_LINUX)
25# error "Can not identify the platform on which you are running, aborting"
29#include <system_error>
86 [[nodiscard]]
const std::string&
path()
const {
return m_path; }
96 T
get(
const std::string& procname)
100#if defined(ARK_OS_WINDOWS)
101 if (NULL == (funcptr =
reinterpret_cast<T
>(GetProcAddress(m_instance, procname.c_str()))))
103 throw std::system_error(
104 std::error_code(::GetLastError(), std::system_category()), std::string(
"PluginError: Couldn't find ") + procname);
106#elif defined(ARK_OS_LINUX)
107 if (NULL == (funcptr =
reinterpret_cast<T
>(dlsym(m_instance, procname.c_str()))))
109 throw std::system_error(
110 std::error_code(errno, std::system_category()), fmt::format(
"PluginError: Couldn't find {}, {}", procname, dlerror()));
117#if defined(ARK_OS_WINDOWS)
118 HINSTANCE m_instance;
119#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.