patterns: Updated pattern language

This commit is contained in:
WerWolv
2024-11-30 13:49:27 +01:00
parent a639dddd19
commit 01af2f364c
3 changed files with 42 additions and 1 deletions

View File

@@ -552,6 +552,11 @@ namespace hex {
return *s_functions;
}
static AutoReset<std::vector<TypeDefinition>> s_types;
const std::vector<TypeDefinition>& getTypes() {
return *s_types;
}
}
static std::string getFunctionName(const pl::api::Namespace &ns, const std::string &name) {
@@ -605,6 +610,10 @@ namespace hex {
runtime.addFunction(ns, name, paramCount, callback);
}
for (const auto &[ns, name, paramCount, callback] : impl::getTypes()) {
runtime.addType(ns, name, paramCount, callback);
}
for (const auto &[name, callback] : impl::getPragmas()) {
runtime.addPragma(name, callback);
}
@@ -639,6 +648,15 @@ namespace hex {
});
}
void addType(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::TypeCallback &func) {
log::debug("Registered new pattern language type: {}", getFunctionName(ns, name));
impl::s_types->push_back({
ns, name,
parameterCount, func
});
}
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, pl::api::FunctionParameterCount parameterCount) {
log::debug("Registered new pattern visualizer function: {}", name);