Skip to content

Commit

Permalink
Added docstrings to the new API. (Haven't documented this yet.)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.dsource.org/projects/pyd/trunk@103 1df65b71-e716-0410-9316-ac55df2b1602
  • Loading branch information
KirkMcDonald authored and KirkMcDonald committed Mar 5, 2007
1 parent bfae4f9 commit 3ecb2ee
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 21 deletions.
14 changes: 7 additions & 7 deletions examples/testdll/testdll.d
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ extern(C) void PydMain() {
wrap_class!(
Foo,
Init!(void delegate(int), void delegate(int, int)),
Property!(Foo.i),
Def!(Foo.foo)
);
Property!(Foo.i, "A sample property of Foo."),
Def!(Foo.foo, "A sample method of Foo.")
) ("A sample class.");

wrap_struct!(
S,
Def!(S.write_s),
Member!("i"),
Member!("s")
);
Def!(S.write_s, "A struct member function."),
Member!("i", "One sample data member of S."),
Member!("s", "Another sample data member of S.")
) ("A sample struct.");
}

84 changes: 72 additions & 12 deletions infrastructure/pyd/class_wrap.d
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,25 @@ name = The name of the function as it will appear in Python.
fn_t = The type of the function. It is only useful to specify this
if more than one function has the same name as this one.
*/
template Def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn)) {
alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS) Def;
//template Def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn), char[] docstring="") {
// alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def;
//}
template Def(alias fn, char[] docstring="") {
alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) Def;
}
struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS) {
template Def(alias fn, char[] name, char[] docstring) {
alias Def!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) Def;
}
template Def(alias fn, char[] name, fn_t, char[] docstring) {
alias Def!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) Def;
}
template Def(alias fn, fn_t, char[] docstring="") {
alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) Def;
}
template Def(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") {
alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def;
}
struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS, char[] docstring) {
//static const type = ParamType.Def;
alias fn func;
alias fn_t func_t;
Expand All @@ -291,7 +306,7 @@ struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS) {
list[length-1].ml_name = (name ~ \0).ptr;
list[length-1].ml_meth = &method_wrap!(T, fn, fn_t).func;
list[length-1].ml_flags = METH_VARARGS;
list[length-1].ml_doc = "";
list[length-1].ml_doc = (docstring~\0).ptr;
list ~= empty;
// It's possible that appending the empty item invalidated the
// pointer in the type struct, so we renew it here.
Expand All @@ -309,7 +324,22 @@ struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS) {
/**
Wraps a static member function of the class. Identical to pyd.def.def
*/
struct StaticDef(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn)) {
template StaticDef(alias fn, char[] docstring="") {
alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) Def;
}
template StaticDef(alias fn, char[] name, char[] docstring) {
alias StaticDef!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) Def;
}
template StaticDef(alias fn, char[] name, fn_t, char[] docstring) {
alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) Def;
}
template StaticDef(alias fn, fn_t, char[] docstring="") {
alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) Def;
}
template StaticDef(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") {
alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def;
}
struct StaticDef(alias fn, char[] name, fn_t, uint MIN_ARGS, char[] docstring) {
//static const type = ParamType.StaticDef;
alias fn func;
alias fn_t func_t;
Expand All @@ -322,7 +352,7 @@ struct StaticDef(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), ui
list[length-1].ml_name = (name ~ \0).ptr;
list[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func;
list[length-1].ml_flags = METH_VARARGS | METH_STATIC;
list[length-1].ml_doc = "";
list[length-1].ml_doc = (docstring~\0).ptr;
list ~= empty;
wrapped_class_type!(T).tp_methods = list;
}
Expand All @@ -339,10 +369,22 @@ fn = The property to wrap.
name = The name of the property as it will appear in Python.
RO = Whether this is a read-only property.
*/
template Property(alias fn, char[] name = symbolnameof!(fn), bool RO=false) {
alias Property!(fn, symbolnameof!(fn), name, RO) Property;
//template Property(alias fn, char[] name = symbolnameof!(fn), bool RO=false, char[] docstring = "") {
// alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property;
//}
template Property(alias fn, char[] docstring="") {
alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), false, docstring) Property;
}
struct Property(alias fn, char[] _realname, char[] name, bool RO) {
template Property(alias fn, char[] name, char[] docstring) {
alias Property!(fn, symbolnameof!(fn), name, false, docstring) Property;
}
template Property(alias fn, char[] name, bool RO, char[] docstring="") {
alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property;
}
template Property(alias fn, bool RO, char[] docstring="") {
alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), RO, docstring) Property;
}
struct Property(alias fn, char[] _realname, char[] name, bool RO, char[] docstring) {
alias property_parts!(fn).getter_type get_t;
alias property_parts!(fn).setter_type set_t;
static const char[] realname = _realname;
Expand All @@ -358,7 +400,7 @@ struct Property(alias fn, char[] _realname, char[] name, bool RO) {
wrapped_prop_list!(T)[length-1].set =
&wrapped_set!(T, fn).func;
}
wrapped_prop_list!(T)[length-1].doc = "";
wrapped_prop_list!(T)[length-1].doc = (docstring~\0).ptr;
wrapped_prop_list!(T)[length-1].closure = null;
wrapped_prop_list!(T) ~= empty;
// It's possible that appending the empty item invalidated the
Expand Down Expand Up @@ -452,15 +494,15 @@ Exposes alternate iteration methods, originally intended for use with
D's delegate-as-iterator features, as methods returning a Python
iterator.
*/
struct AltIter(alias fn, char[] name = symbolnameof!(fn), iter_t = funcDelegInfoT!(typeof(&fn)).Meta.ArgType!(0)) {
struct AltIter(alias fn, char[] name = symbolnameof!(fn), iter_t = ParameterTypeTuple!(fn)[0]) {
static void call(T, shim) () {
static PyMethodDef empty = { null, null, 0, null };
alias wrapped_method_list!(T) list;
PydStackContext_Ready();
list[length-1].ml_name = name ~ \0;
list[length-1].ml_meth = cast(PyCFunction)&wrapped_iter!(T, fn, int function(iter_t)).iter;
list[length-1].ml_flags = METH_VARARGS;
list[length-1].ml_doc = (docstring ~ \0).ptr;
list[length-1].ml_doc = "";//(docstring ~ \0).ptr;
list ~= empty;
// It's possible that appending the empty item invalidated the
// pointer in the type struct, so we renew it here.
Expand All @@ -480,6 +522,10 @@ void wrap_class(_T, char[] name, Params...) (char[] docstring="", char[] modulen
pragma(msg, "wrap_class: " ~ name);
alias make_wrapper!(_T, Params).wrapper shim_class;
alias _T T;
// } else static if (is(_T == interface)) {
// pragma(msg, "wrap_interface: " ~ name);
// alias make_wrapper!(_T, Params).wrapper shim_class;
// alias _T T;
} else {
pragma(msg, "wrap_struct: " ~ name);
alias void shim_class;
Expand Down Expand Up @@ -590,6 +636,20 @@ void wrap_class(_T, char[] name, Params...) (char[] docstring="", char[] modulen
}
}

////////////////
// DOCSTRINGS //
////////////////

struct Docstring {
char[] name, doc;
}

void docstrings(T=void)(Docstring[] docs...) {
static if (is(T == void)) {

}
}

///////////////////////
// PYD API FUNCTIONS //
///////////////////////
Expand Down
7 changes: 5 additions & 2 deletions infrastructure/pyd/struct_wrap.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ template wrapped_member(T, char[] name, _M=void) {
}
}

struct Member(char[] realname, char[] name=realname) {
template Member(char[] realname, char[] docstring="") {
alias Member!(realname, realname, docstring) Member;
}
struct Member(char[] realname, char[] name, char[] docstring) {
static void call(T, dummy) () {
pragma(msg, "struct.member: " ~ name);
static PyGetSetDef empty = {null, null, null, null, null};
alias wrapped_prop_list!(T) list;
list[length-1].name = (name ~ \0).ptr;
list[length-1].get = &wrapped_member!(T, realname).get;
list[length-1].set = &wrapped_member!(T, realname).set;
list[length-1].doc = "";
list[length-1].doc = (docstring~\0).ptr;
list[length-1].closure = null;
list ~= empty;
wrapped_class_type!(T).tp_getset = list.ptr;
Expand Down

0 comments on commit 3ecb2ee

Please sign in to comment.