diff --git a/src/Mod/Sandbox/App/AppSandbox.cpp b/src/Mod/Sandbox/App/AppSandbox.cpp index 051d7bd69..17aa8accf 100644 --- a/src/Mod/Sandbox/App/AppSandbox.cpp +++ b/src/Mod/Sandbox/App/AppSandbox.cpp @@ -52,6 +52,9 @@ public: Py::String name( names[i] ); std::cout << " " << name << std::endl; } + m_array.push_back(Py::Long(2)); + m_array.push_back(Py::Float(3.0)); + m_array.push_back(Py::String("4.0")); } virtual ~PythonBaseClass() @@ -65,6 +68,7 @@ public: behaviors().doc( "documentation for PythonBaseClass class" ); behaviors().supportGetattro(); behaviors().supportSetattro(); + behaviors().supportSequenceType(); PYCXX_ADD_NOARGS_METHOD( func_noargs, PythonBaseClass_func_noargs, "docs for PythonBaseClass_func_noargs" ); PYCXX_ADD_VARARGS_METHOD( func_varargs, PythonBaseClass_func_varargs, "docs for PythonBaseClass_func_varargs" ); @@ -142,8 +146,49 @@ public: return genericSetAttro( name_, value ); } } + virtual int sequence_length() + { + // len(x) + return m_array.size(); + } + virtual Py::Object sequence_concat(const Py::Object & i) + { + // x + y + throw Py::NotImplementedError("not yet implemented"); + } + virtual Py::Object sequence_repeat(Py_ssize_t i) + { + // x * 3 + throw Py::NotImplementedError("not yet implemented"); + } + virtual Py::Object sequence_item(Py_ssize_t i) + { + // x[0] + if (i >= static_cast(m_array.size())) + throw Py::IndexError("index out of range"); + return m_array[i]; + } + virtual Py::Object sequence_slice(Py_ssize_t i, Py_ssize_t j) + { + // x[0:3] + throw Py::NotImplementedError("not yet implemented"); + } + virtual int sequence_ass_item(Py_ssize_t i, const Py::Object & o) + { + // x[0] = y + if (i >= static_cast(m_array.size())) + throw Py::IndexError("index out of range"); + m_array[i] = o; + return 0; + } + virtual int sequence_ass_slice(Py_ssize_t i, Py_ssize_t j, const Py::Object & o) + { + // x[0:3] = y + throw Py::NotImplementedError("not yet implemented"); + } Py::String m_value; + std::vector m_array; }; /* module functions */