MCPcopy Create free account
hub / github.com/covscript/covscript / extension

Class extension

include/covscript/core/core.hpp:1200–1229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1198 } // namespace dll
1199
1200 class extension final : public name_space {
1201 void *mHandle;
1202
1203 public:
1204 extension() = delete;
1205
1206 extension(const extension &) = delete;
1207
1208 virtual ~extension() = default;
1209
1210 static inline int truncate(int n, int m)
1211 {
1212 return n == 0 ? 0 : n / int(std::pow(10, (std::max) (int(std::log10(std::abs(n))) - (std::max) (m, 0) + 1, 0)));
1213 }
1214
1215 explicit extension(std::string_view path)
1216 {
1217 mHandle = dll::open(path);
1218 dll::compatible_check_t dll_check = reinterpret_cast<dll::compatible_check_t>(dll::find_symbol(mHandle, dll::compatible_check));
1219 if (dll_check == nullptr || truncate(dll_check(), 4) != truncate(COVSCRIPT_ABI_VERSION, 4))
1220 throw runtime_error("Incompatible Extension. (Target ABI: " + std::to_string(dll_check()) +
1221 ", Current ABI: " + std::to_string(COVSCRIPT_ABI_VERSION) + ")");
1222 dll::main_entrance_t dll_main = reinterpret_cast<dll::main_entrance_t>(dll::find_symbol(mHandle, dll::main_entrance));
1223 if (dll_main != nullptr) {
1224 dll_main(this, current_process);
1225 }
1226 else
1227 throw runtime_error("Broken Extension.");
1228 }
1229 };
1230
1231 var make_namespace(const namespace_t &);
1232

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected