2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-02-09 08:12:42 +01:00
|
|
|
|
|
|
|
#include "base/dictionary.hpp"
|
|
|
|
#include "base/function.hpp"
|
|
|
|
#include "base/functionwrapper.hpp"
|
|
|
|
#include "base/scriptframe.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
|
|
|
#include "base/json.hpp"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
static String JsonEncodeShim(const Value& value)
|
|
|
|
{
|
|
|
|
return JsonEncode(value);
|
|
|
|
}
|
|
|
|
|
2016-08-27 09:35:08 +02:00
|
|
|
INITIALIZE_ONCE([]() {
|
2018-08-07 13:55:41 +02:00
|
|
|
auto jsonNSBehavior = new ConstNamespaceBehavior();
|
|
|
|
Namespace::Ptr jsonNS = new Namespace(jsonNSBehavior);
|
2015-02-09 08:12:42 +01:00
|
|
|
|
2018-08-07 13:55:41 +02:00
|
|
|
/* Methods */
|
|
|
|
jsonNS->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true));
|
|
|
|
jsonNS->Set("decode", new Function("Json#decode", JsonDecode, { "value" }, true));
|
|
|
|
|
|
|
|
jsonNSBehavior->Freeze();
|
|
|
|
|
|
|
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
2019-07-26 14:45:11 +02:00
|
|
|
systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS));
|
2016-08-27 09:35:08 +02:00
|
|
|
});
|