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)
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;
-}
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.
*
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;
private:
Callback m_Callback;
- int m_ArgumentCount;
- vector<ScriptArgumentHint> m_ArgumentHints;
- ScriptArgumentHint m_ReturnHint;
};
/**
return m_MainThreadState;
}
-PyObject *PythonLanguage::MarshalToPython(const Value& value, const ScriptArgumentHint& hint)
+PyObject *PythonLanguage::MarshalToPython(const Value& value)
{
String svalue;
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));
}
}
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());
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);
};
}