Remove support for type hints.

This commit is contained in:
Gunnar Beutner 2013-02-15 18:27:21 +01:00
parent 4998563a74
commit d0481ea578
4 changed files with 7 additions and 73 deletions

View File

@ -25,7 +25,7 @@ boost::signal<void (const String&, const ScriptFunction::Ptr&)> ScriptFunction::
boost::signal<void (const String&)> ScriptFunction::OnUnregistered;
ScriptFunction::ScriptFunction(const Callback& function)
: m_Callback(function), m_ArgumentCount(-1)
: m_Callback(function)
{ }
void ScriptFunction::Register(const String& name, const ScriptFunction::Ptr& function)
@ -62,43 +62,3 @@ map<String, ScriptFunction::Ptr>& ScriptFunction::GetFunctions(void)
static map<String, ScriptFunction::Ptr> functions;
return functions;
}
void ScriptFunction::SetArgumentCount(int count)
{
if (m_ArgumentCount >= 0)
m_ArgumentHints.resize(count);
m_ArgumentCount = count;
}
int ScriptFunction::GetArgumentCount(void) const
{
return m_ArgumentCount;
}
void ScriptFunction::SetArgumentHint(int index, const ScriptArgumentHint& hint)
{
assert(index >= 0 && index < m_ArgumentCount);
m_ArgumentHints[index] = hint;
}
ScriptArgumentHint ScriptFunction::GetArgumentHint(int index) const
{
if (m_ArgumentCount == -1 || index >= m_ArgumentCount)
return ScriptArgumentHint();
assert(index >= 0 && index < m_ArgumentHints.size());
return m_ArgumentHints[index];
}
void ScriptFunction::SetReturnHint(const ScriptArgumentHint& hint)
{
m_ReturnHint = hint;
}
ScriptArgumentHint ScriptFunction::GetReturnHint(void) const
{
return m_ReturnHint;
}

View File

@ -25,20 +25,6 @@ namespace icinga
class ScriptTask;
/**
* A type hint.
*/
struct ScriptArgumentHint
{
bool RestrictType;
ValueType Type;
String Class;
ScriptArgumentHint(void)
: RestrictType(false), Type(ValueEmpty), Class()
{ }
};
/**
* A script function that can be used to execute a script task.
*
@ -60,15 +46,6 @@ public:
void Invoke(const shared_ptr<ScriptTask>& task, const vector<Value>& arguments);
void SetArgumentCount(int count);
int GetArgumentCount(void) const;
void SetArgumentHint(int index, const ScriptArgumentHint& hint);
ScriptArgumentHint GetArgumentHint(int index) const;
void SetReturnHint(const ScriptArgumentHint& hint);
ScriptArgumentHint GetReturnHint(void) const;
static map<String, ScriptFunction::Ptr>& GetFunctions(void);
static boost::signal<void (const String&, const ScriptFunction::Ptr&)> OnRegistered;
@ -76,9 +53,6 @@ public:
private:
Callback m_Callback;
int m_ArgumentCount;
vector<ScriptArgumentHint> m_ArgumentHints;
ScriptArgumentHint m_ReturnHint;
};
/**

View File

@ -69,7 +69,7 @@ PyThreadState *PythonLanguage::GetMainThreadState(void) const
return m_MainThreadState;
}
PyObject *PythonLanguage::MarshalToPython(const Value& value, const ScriptArgumentHint& hint)
PyObject *PythonLanguage::MarshalToPython(const Value& value)
{
String svalue;
@ -158,10 +158,10 @@ PyObject *PythonLanguage::CallNativeFunction(PyObject *self, PyObject *args)
for (Py_ssize_t i = 0; i < PyTuple_Size(args); i++) {
PyObject *arg = PyTuple_GetItem(args, i);
arguments.push_back(MarshalFromPython(arg, function->GetArgumentHint(i)));
arguments.push_back(MarshalFromPython(arg));
}
} else {
arguments.push_back(MarshalFromPython(args, function->GetArgumentHint(0)));
arguments.push_back(MarshalFromPython(args));
}
}
@ -172,7 +172,7 @@ PyObject *PythonLanguage::CallNativeFunction(PyObject *self, PyObject *args)
try {
Value result = task->GetResult();
return MarshalToPython(result, function->GetReturnHint());
return MarshalToPython(result);
} catch (const std::exception& ex) {
String message = diagnostic_information(ex);
PyErr_SetString(PyExc_RuntimeError, message.CStr());

View File

@ -50,8 +50,8 @@ private:
static PyObject *CallNativeFunction(PyObject *self, PyObject *args);
static PyObject *MarshalToPython(const Value& value, const ScriptArgumentHint& hint);
static Value MarshalFromPython(PyObject *value, const ScriptArgumentHint& hint);
static PyObject *MarshalToPython(const Value& value);
static Value MarshalFromPython(PyObject *value);
};
}