예제 #1
0
        public IEnumerator <PyObject> GetEnumerator()
        {
            if (IsInvalid)
            {
                yield break;
            }

            var iter = PyObject_GetIter(Pointer);

            if (iter == IntPtr.Zero)
            {
                yield break;
            }

            if (Python.ErrorSet)
            {
                Python.ClearError();
                yield break;
            }

            IntPtr p = PyIter_Next(iter);

            while (p != IntPtr.Zero)
            {
                yield return(GetSpecialized(p));

                p = PyIter_Next(iter);
            }
        }
예제 #2
0
파일: PyList.cs 프로젝트: sgfgaming/beliEVE
        public bool Insert(int index, IntPtr item)
        {
            if (IsInvalid || item == IntPtr.Zero || index < 0)
            {
                return(false);
            }
            var r = PyList_Insert(Pointer, index, item);

            if (r == -1)
            {
                Python.ClearError();
                return(false);
            }
            return(true);
        }
예제 #3
0
파일: PyList.cs 프로젝트: sgfgaming/beliEVE
        public bool Append(IntPtr item)
        {
            if (IsInvalid || item == IntPtr.Zero)
            {
                return(false);
            }
            var r = PyList_Append(Pointer, item);

            if (r == -1)
            {
                Python.ClearError();
                return(false);
            }
            return(true);
        }
예제 #4
0
파일: PyList.cs 프로젝트: sgfgaming/beliEVE
 public override PyObject this[int key]
 {
     get
     {
         if (IsInvalid || key < 0)
         {
             return(null);
         }
         return(new PyObject(PyList_GetItem(Pointer, key), ReferenceType.Borrowed));
     }
     set
     {
         if (IsInvalid || key < 0 || value.IsInvalid)
         {
             return;
         }
         if (PyList_SetItem(Pointer, key, value.Pointer) != 0)
         {
             Python.ClearError();
         }
     }
 }
예제 #5
0
        private int RunCodeInternal(IntPtr unused)
        {
            try
            {
                Result = Python.RunPure(Code);

                if (Python.ErrorSet)
                {
                    _exception = Python.GetError();
                    Python.ClearError();
                }
                return(0);
            }
            catch (Exception ex)
            {
                _exception = ex;
                return(0);
            }
            finally
            {
                _executed.Set();
            }
        }