Skip to content

Commit

Permalink
Introduce ConfigObject#get_attribute()
Browse files Browse the repository at this point in the history
refs #8717
  • Loading branch information
Al2Klimov committed Apr 22, 2021
1 parent 734d4d2 commit 739f742
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/base/configobject-script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@
#include "base/dictionary.hpp"
#include "base/function.hpp"
#include "base/functionwrapper.hpp"
#include "base/reference.hpp"
#include "base/scriptframe.hpp"

using namespace icinga;

static bool ConfigObjectGetAttribute(const String& attr, const Reference::Ptr& result)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
ConfigObject::Ptr self = vframe->Self;

REQUIRE_NOT_NULL(self);

Value temp;
bool ok = self->GetAttribute(attr, &temp);

if (ok && result) {
result->Set(temp);
}

return ok;
}

static void ConfigObjectModifyAttribute(const String& attr, const Value& value)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Expand All @@ -27,6 +45,7 @@ static void ConfigObjectRestoreAttribute(const String& attr)
Object::Ptr ConfigObject::GetPrototype()
{
static Dictionary::Ptr prototype = new Dictionary({
{ "get_attribute", new Function("ConfigObject#get_attribute", ConfigObjectGetAttribute, { "attr", "result" }, false) },
{ "modify_attribute", new Function("ConfigObject#modify_attribute", ConfigObjectModifyAttribute, { "attr", "value" }, false) },
{ "restore_attribute", new Function("ConfigObject#restore_attribute", ConfigObjectRestoreAttribute, { "attr", "value" }, false) }
});
Expand Down

0 comments on commit 739f742

Please sign in to comment.