1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "base/function.hpp"
4 #include "base/function-ti.cpp"
5 #include "base/array.hpp"
6 #include "base/scriptframe.hpp"
8 using namespace icinga;
10 REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
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))
17 SetSideEffectFree(side_effect_free, true);
18 SetDeprecated(deprecated, true);
19 SetArguments(Array::FromVector(args), true);
22 Value Function::Invoke(const std::vector<Value>& arguments)
24 ScriptFrame frame(false);
25 return m_Callback(arguments);
28 Value Function::InvokeThis(const Value& otherThis, const std::vector<Value>& arguments)
30 ScriptFrame frame(false, otherThis);
31 return m_Callback(arguments);
34 Object::Ptr Function::Clone() const
36 return const_cast<Function *>(this);