GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
chaiscript_posix.hpp
Go to the documentation of this file.
1// This file is distributed under the BSD License.
2// See "license.txt" for details.
3// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4// Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5// http://www.chaiscript.com
6
7#ifndef CHAISCRIPT_POSIX_HPP_
8#define CHAISCRIPT_POSIX_HPP_
9
10namespace chaiscript
11{
12 namespace detail
13 {
15 {
16 struct DLModule
17 {
18 explicit DLModule(const std::string &t_filename)
19 : m_data(dlopen(t_filename.c_str(), RTLD_NOW))
20 {
21 if (m_data == nullptr)
22 {
24 }
25 }
26
27 DLModule(DLModule &&) = default;
28 DLModule &operator=(DLModule &&) = default;
29 DLModule(const DLModule &) = delete;
30 DLModule &operator=(const DLModule &) = delete;
31
33 {
34 dlclose(m_data);
35 }
36
37 void *m_data;
38 };
39
40 template<typename T>
41 struct DLSym
42 {
43 DLSym(DLModule &t_mod, const std::string &t_symbol)
44 : m_symbol(reinterpret_cast<T>(dlsym(t_mod.m_data, t_symbol.c_str())))
45 {
46 if (!m_symbol)
47 {
49 }
50 }
51
53 };
54
55 Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
56 : m_dlmodule(t_filename), m_func(m_dlmodule, "create_chaiscript_module_" + t_module_name),
57 m_moduleptr(m_func.m_symbol())
58 {
59 }
60
64 };
65 }
66}
67#endif
68
Classes and functions reserved for internal use. Items in this namespace are not supported.
Namespace chaiscript contains every API call that the average user will be concerned with.
std::shared_ptr< Module > ModulePtr
Convenience typedef for Module objects to be added to the ChaiScript runtime.
Definition dispatchkit.hpp:263
Definition GameApi.h:42
Definition chaiscript_posix.hpp:17
~DLModule()
Definition chaiscript_posix.hpp:32
void * m_data
Definition chaiscript_posix.hpp:37
DLModule & operator=(const DLModule &)=delete
DLModule & operator=(DLModule &&)=default
DLModule(const std::string &t_filename)
Definition chaiscript_posix.hpp:18
Definition chaiscript_posix.hpp:42
DLSym(DLModule &t_mod, const std::string &t_symbol)
Definition chaiscript_posix.hpp:43
T m_symbol
Definition chaiscript_posix.hpp:52
DLModule m_dlmodule
Definition chaiscript_posix.hpp:61
ModulePtr m_moduleptr
Definition chaiscript_posix.hpp:63
Loadable_Module(const std::string &t_module_name, const std::string &t_filename)
Definition chaiscript_posix.hpp:55
DLSym< Create_Module_Func > m_func
Definition chaiscript_posix.hpp:62
Thrown if an error occurs while attempting to load a binary module.
Definition chaiscript_common.hpp:138