コード例 #1
0
ファイル: NativeModule.cs プロジェクト: Reve/beliEVE
        protected void AddMethod(string name, Python.CFunction function)
        {
            if (Initialized)
                throw new InvalidOperationException("Tried to add method after module was initialized");

            var def = new PyMethodDef {Name = name, Documentation = "", Flags = MethodFlag.VarArgs, Method = function};
            Methods.Add(def);
        }
コード例 #2
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();
         }
     }
 }
コード例 #3
0
ファイル: CodeBite.cs プロジェクト: sgfgaming/beliEVE
        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();
            }
        }
コード例 #4
0
        internal static string GetValueInternal(IntPtr pointer)
        {
            if (PyObject_IsInstance(pointer, Python.Type.Unicode) == 0)
            {
                var raw = GetRawInternal(pointer);
                if (raw == null)
                {
                    return("");
                }
                return(Encoding.ASCII.GetString(raw));
            }

            var mem = PyUnicodeUCS2_AsEncodedString(pointer, "utf-8", "ignore");

            if (mem == IntPtr.Zero)
            {
                return("");
            }
            var res = Marshal.PtrToStringAnsi(mem);

            Python.Py_DecRef(mem);
            return(res);
        }
コード例 #5
0
ファイル: PyObject.cs プロジェクト: sgfgaming/beliEVE
 public override string ToString()
 {
     return(Python.Repr(Pointer));
 }