@ExposedNew
public static PyObject StructLayout_new(PyNewWrapper new_, boolean init, PyType subtype,
PyObject[] args, String[] keywords) {
ArgParser ap = new ArgParser("__init__", args, keywords, new String[] { "fields", "union" }, 1);
if (!(ap.getPyObject(0) instanceof PyList)) {
throw Py.TypeError("expected list of jffi.StructLayout.Field");
}
PyList pyFields = (PyList) ap.getPyObject(0);
Field[] fields = new Field[pyFields.size()];
for (int i = 0; i < fields.length; ++i) {
PyObject pyField = pyFields.pyget(i);
if (!(pyField instanceof Field)) {
throw Py.TypeError(String.format("element %d of field list is not an instance of jffi.StructLayout.Field", i));
}
fields[i] = (Field) pyField;
}
return StructUtil.newStructLayout(fields, ap.getPyObject(1, Py.False).__nonzero__());
}