MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / Module

Class Module

include/chaiscript/dispatchkit/dispatchkit.hpp:149–260  ·  view source on GitHub ↗

\brief Holds a collection of ChaiScript settings which can be applied to the ChaiScript runtime. Used to implement loadable module support.

Source from the content-addressed store, hash-verified

147 /// \brief Holds a collection of ChaiScript settings which can be applied to the ChaiScript runtime.
148 /// Used to implement loadable module support.
149 class Module
150 {
151 public:
152 Module &add(Type_Info ti, std::string name)
153 {
154 m_typeinfos.emplace_back(ti, std::move(name));
155 return *this;
156 }
157
158 Module &add(Type_Conversion d)
159 {
160 m_conversions.push_back(std::move(d));
161 return *this;
162 }
163
164 Module &add(Proxy_Function f, std::string name)
165 {
166 m_funcs.emplace_back(std::move(f), std::move(name));
167 return *this;
168 }
169
170 Module &add_global_const(Boxed_Value t_bv, std::string t_name)
171 {
172 if (!t_bv.is_const())
173 {
174 throw chaiscript::exception::global_non_const();
175 }
176
177 m_globals.emplace_back(std::move(t_bv), std::move(t_name));
178 return *this;
179 }
180
181
182 //Add a bit of ChaiScript to eval during module implementation
183 Module &eval(const std::string &str)
184 {
185 m_evals.push_back(str);
186 return *this;
187 }
188
189 template<typename Eval, typename Engine>
190 void apply(Eval &t_eval, Engine &t_engine) const
191 {
192 apply(m_typeinfos.begin(), m_typeinfos.end(), t_engine);
193 apply(m_funcs.begin(), m_funcs.end(), t_engine);
194 apply_eval(m_evals.begin(), m_evals.end(), t_eval);
195 apply_single(m_conversions.begin(), m_conversions.end(), t_engine);
196 apply_globals(m_globals.begin(), m_globals.end(), t_engine);
197 }
198
199 bool has_function(const Proxy_Function &new_f, const std::string &name)
200 {
201 return std::any_of(m_funcs.begin(), m_funcs.end(),
202 [&](const std::pair<Proxy_Function, std::string> &existing_f) {
203 return existing_f.second == name && *(existing_f.first) == *(new_f);
204 }
205 );
206 }

Callers

nothing calls this directly

Calls 2

global_non_constClass · 0.85
is_constMethod · 0.45

Tested by

no test coverage detected