]> granicus.if.org Git - icinga2/blob - lib/base/function.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / function.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/function.hpp"
4 #include "base/function-ti.cpp"
5 #include "base/array.hpp"
6 #include "base/scriptframe.hpp"
7
8 using namespace icinga;
9
10 REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
11
12 Function::Function(const String& name, Callback function, const std::vector<String>& args,
13         bool side_effect_free, bool deprecated)
14         : m_Callback(std::move(function))
15 {
16         SetName(name, true);
17         SetSideEffectFree(side_effect_free, true);
18         SetDeprecated(deprecated, true);
19         SetArguments(Array::FromVector(args), true);
20 }
21
22 Value Function::Invoke(const std::vector<Value>& arguments)
23 {
24         ScriptFrame frame(false);
25         return m_Callback(arguments);
26 }
27
28 Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
29 {
30         ScriptFrame frame(false, otherThis);
31         return m_Callback(arguments);
32 }
33
34 Object::Ptr Function::Clone() const
35 {
36         return const_cast<Function *>(this);
37 }