]> granicus.if.org Git - icinga2/blob - lib/base/reference-script.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / reference-script.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/reference.hpp"
4 #include "base/function.hpp"
5 #include "base/functionwrapper.hpp"
6 #include "base/scriptframe.hpp"
7 #include "base/exception.hpp"
8
9 using namespace icinga;
10
11 static void ReferenceSet(const Value& value)
12 {
13         ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
14         Reference::Ptr self = static_cast<Reference::Ptr>(vframe->Self);
15         REQUIRE_NOT_NULL(self);
16         self->Set(value);
17 }
18
19 static Value ReferenceGet()
20 {
21         ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
22         Reference::Ptr self = static_cast<Reference::Ptr>(vframe->Self);
23         REQUIRE_NOT_NULL(self);
24         return self->Get();
25 }
26
27 Object::Ptr Reference::GetPrototype()
28 {
29         static Dictionary::Ptr prototype = new Dictionary({
30                 { "set", new Function("Reference#set", ReferenceSet, { "value" }) },
31                 { "get", new Function("Reference#get", ReferenceGet, {}, true) },
32         });
33
34         return prototype;
35 }