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

Class ChaiScript_Basic

include/chaiscript/language/chaiscript_engine.hpp:68–778  ·  view source on GitHub ↗

\brief The main object that the ChaiScript user will use.

Source from the content-addressed store, hash-verified

66
67 /// \brief The main object that the ChaiScript user will use.
68 class ChaiScript_Basic {
69
70 mutable chaiscript::detail::threading::shared_mutex m_mutex;
71 mutable chaiscript::detail::threading::recursive_mutex m_use_mutex;
72
73 std::set<std::string> m_used_files;
74 std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
75 std::set<std::string> m_active_loaded_modules;
76
77 std::vector<std::string> m_module_paths;
78 std::vector<std::string> m_use_paths;
79
80 std::unique_ptr<parser::ChaiScript_Parser_Base> m_parser;
81
82 chaiscript::detail::Dispatch_Engine m_engine;
83
84 std::map<std::string, std::function<Namespace&()>> m_namespace_generators;
85
86 /// Evaluates the given string in by parsing it and running the results through the evaluator
87 Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
88 {
89 try {
90 const auto p = m_parser->parse(t_input, t_filename);
91 return p->eval(chaiscript::detail::Dispatch_State(m_engine));
92 }
93 catch (chaiscript::eval::detail::Return_Value &rv) {
94 return rv.retval;
95 }
96 }
97
98
99
100 /// Evaluates the given file and looks in the 'use' paths
101 const Boxed_Value internal_eval_file(const std::string &t_filename) {
102 for (const auto &path : m_use_paths)
103 {
104 try {
105 const auto appendedpath = path + t_filename;
106 return do_eval(load_file(appendedpath), appendedpath, true);
107 } catch (const exception::file_not_found_error &) {
108 // failed to load, try the next path
109 } catch (const exception::eval_error &t_ee) {
110 throw Boxed_Value(t_ee);
111 }
112 }
113
114 // failed to load by any name
115 throw exception::file_not_found_error(t_filename);
116
117 }
118
119
120
121 /// Evaluates the given string, used during eval() inside of a script
122 const Boxed_Value internal_eval(const std::string &t_e) {
123 try {
124 return do_eval(t_e, "__EVAL__", true);
125 } catch (const exception::eval_error &t_ee) {

Callers

nothing calls this directly

Calls 5

add_global_constMethod · 0.80
add_globalMethod · 0.80
set_globalMethod · 0.80
applyMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected