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); }
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(); } } }
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(); } }
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); }
public override string ToString() { return(Python.Repr(Pointer)); }