1
0
mirror of synced 2024-11-16 12:03:22 +01:00
ImHex/plugins/builtin/source/content/pl_builtin_functions.cpp

28 lines
853 B
C++
Raw Normal View History

#include <hex/api/content_registry.hpp>
2021-09-25 16:24:08 +02:00
#include <hex/helpers/net.hpp>
2021-08-29 22:15:18 +02:00
#include <pl/token.hpp>
#include <pl/log_console.hpp>
#include <pl/evaluator.hpp>
#include <pl/patterns/pattern.hpp>
namespace hex::plugin::builtin {
void registerPatternLanguageFunctions() {
using namespace pl;
using FunctionParameterCount = pl::api::FunctionParameterCount;
api::Namespace nsStdHttp = { "builtin", "std", "http" };
2021-09-25 16:24:08 +02:00
{
/* get(url) */
ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
2021-09-25 16:24:08 +02:00
const auto url = Token::literalToString(params[0], false);
hex::Net net;
return net.getString(url).get().body;
});
2021-09-25 16:24:08 +02:00
}
}
}