/// Get a member of this module by name. public PyObj GetMember(string attrName) { PyObj result; unsafe { var rawDict = CPython.PyModule_GetDict(obj); if (rawDict == null) { throw new NullReferenceException("Failed to get dict from module."); } var rawString = CPython.PyUnicode_FromString(attrName); if (rawString == null) { throw new NullReferenceException("Failed to create PyObject from string."); } var rawResult = CPython.PyDict_GetItem(rawDict, rawString); if (rawResult == null) { throw new NullReferenceException("Failed to get item by key."); } result = new PyObj(rawResult); } return(result); }
/// If this Python object supports [] indexing, get an item by its key. public PyObj GetItem(PyObj key) { PyObj result; unsafe { var rawResult = CPython.PyObject_GetItem(obj, key.obj); if (rawResult == null) throw new NullReferenceException("Failed to get item by key."); result = new PyObj(rawResult); } return result; }
/// Call this Python object with the given arguments. public PyObj CallObject(PyObj args) { PyObj result; unsafe { var rawResult = CPython.PyObject_CallObject(obj, args.obj); if (rawResult == null) throw new NullReferenceException("Calling PyObject returned null."); result = new PyObj(rawResult); } return result; }
/// Create a PyObject from a long integer. public static PyObj FromLong(long value) { PyObj result; unsafe { var rawResult = CPython.PyLong_FromLong(value); if (rawResult == null) throw new NullReferenceException("Failed to create PyObject from long."); result = new PyObj(rawResult); } return result; }
/// Create a PyObject from a double. public static PyObj FromDouble(double value) { PyObj result; unsafe { var rawResult = CPython.PyFloat_FromDouble(value); if (rawResult == null) throw new NullReferenceException("Failed to create PyObject from double."); result = new PyObj(rawResult); } return result; }
public PyObj Next() { PyObj result; unsafe { var rawResult = CPython.PyIter_Next(obj); if (rawResult == null) throw new NullReferenceException("PyIter refused to yield an item."); result = new PyObj(rawResult); } return result; }
/// Get an attribute from this PyObject by string name. public PyObj GetAttrString(string attrName) { PyObj result; unsafe { var rawResult = CPython.PyObject_GetAttrString(obj, attrName); if (rawResult == null) throw new NullReferenceException( string.Format("Failed to get attribute `{0}` from PyObject.", attrName)); result = new PyObj(rawResult); } return result; }
/// If this Python object supports [] indexing, get an item by its key. public PyObj GetItem(PyObj key) { PyObj result; unsafe { var rawResult = CPython.PyObject_GetItem(obj, key.obj); if (rawResult == null) { throw new NullReferenceException("Failed to get item by key."); } result = new PyObj(rawResult); } return(result); }
/// Call this Python object with the given arguments. public PyObj CallObject(PyObj args) { PyObj result; unsafe { var rawResult = CPython.PyObject_CallObject(obj, args.obj); if (rawResult == null) { throw new NullReferenceException("Calling PyObject returned null."); } result = new PyObj(rawResult); } return(result); }
/// Create a PyObject from a long integer. public static PyObj FromLong(long value) { PyObj result; unsafe { var rawResult = CPython.PyLong_FromLong(value); if (rawResult == null) { throw new NullReferenceException("Failed to create PyObject from long."); } result = new PyObj(rawResult); } return(result); }
/// Create a PyObject from a double. public static PyObj FromDouble(double value) { PyObj result; unsafe { var rawResult = CPython.PyFloat_FromDouble(value); if (rawResult == null) { throw new NullReferenceException("Failed to create PyObject from double."); } result = new PyObj(rawResult); } return(result); }
/// Get a member of this module by name. public PyObj GetMember(string attrName) { PyObj result; unsafe { var rawDict = CPython.PyModule_GetDict(obj); if (rawDict == null) throw new NullReferenceException("Failed to get dict from module."); var rawString = CPython.PyUnicode_FromString(attrName); if (rawString == null) throw new NullReferenceException("Failed to create PyObject from string."); var rawResult = CPython.PyDict_GetItem(rawDict, rawString); if (rawResult == null) throw new NullReferenceException("Failed to get item by key."); result = new PyObj(rawResult); } return result; }
public PyObj Next() { PyObj result; unsafe { var rawResult = CPython.PyIter_Next(obj); if (rawResult == null) { throw new NullReferenceException("PyIter refused to yield an item."); } result = new PyObj(rawResult); } return(result); }
/// Get an attribute from this PyObject by string name. public PyObj GetAttrString(string attrName) { PyObj result; unsafe { var rawResult = CPython.PyObject_GetAttrString(obj, attrName); if (rawResult == null) { throw new NullReferenceException( string.Format("Failed to get attribute `{0}` from PyObject.", attrName)); } result = new PyObj(rawResult); } return(result); }