12#ifndef ARK_VM_PLUGIN_HPP
13#define ARK_VM_PLUGIN_HPP
17#if defined(ARK_OS_WINDOWS)
19# define WIN32_LEAN_AND_MEAN
21#elif defined(ARK_OS_LINUX)
24# error "Can not identify the platform on which you are running, aborting"
28#include <system_error>
79 inline const std::string&
path()
const {
return m_path; }
89 T
get(
const std::string& procname)
93#if defined(ARK_OS_WINDOWS)
94 if (NULL == (funcptr =
reinterpret_cast<T
>(GetProcAddress(m_instance, procname.c_str()))))
96 throw std::system_error(
97 std::error_code(::GetLastError(), std::system_category()), std::string(
"PluginError: Couldn't find ") + procname);
99#elif defined(ARK_OS_LINUX)
100 if (NULL == (funcptr =
reinterpret_cast<T
>(dlsym(m_instance, procname.c_str()))))
102 throw std::system_error(
103 std::error_code(errno, std::system_category()), std::string(
"PluginError: Couldn't find ") + procname +
", " + std::string(dlerror()));
110#if defined(ARK_OS_WINDOWS)
111 HINSTANCE m_instance;
112#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
void unload()
Unload the shared library.
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
T get(const std::string &procname)
Return a function from the shared library.