Changeset 103

Show
Ignore:
Timestamp:
03/05/07 17:30:51 (5 years ago)
Author:
KirkMcDonald
Message:

Added docstrings to the new API. (Haven't documented this yet.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/testdll/testdll.d

    r100 r103  
    121121        Foo, 
    122122        Init!(void delegate(int), void delegate(int, int)), 
    123         Property!(Foo.i), 
    124         Def!(Foo.foo
    125     )
     123        Property!(Foo.i, "A sample property of Foo."), 
     124        Def!(Foo.foo, "A sample method of Foo."
     125    ) ("A sample class.")
    126126 
    127127    wrap_struct!( 
    128128        S, 
    129         Def!(S.write_s), 
    130         Member!("i"), 
    131         Member!("s"
    132     )
     129        Def!(S.write_s, "A struct member function."), 
     130        Member!("i", "One sample data member of S."), 
     131        Member!("s", "Another sample data member of S."
     132    ) ("A sample struct.")
    133133} 
    134134 
  • trunk/infrastructure/pyd/class_wrap.d

    r101 r103  
    274274       if more than one function has the same name as this one. 
    275275*/ 
    276 template Def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn)) { 
    277     alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS) Def; 
    278 
    279 struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS) { 
     276//template Def(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
     277//    alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def; 
     278//} 
     279template Def(alias fn, char[] docstring="") { 
     280    alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) Def; 
     281
     282template Def(alias fn, char[] name, char[] docstring) { 
     283    alias Def!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) Def; 
     284
     285template Def(alias fn, char[] name, fn_t, char[] docstring) { 
     286    alias Def!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) Def; 
     287
     288template Def(alias fn, fn_t, char[] docstring="") { 
     289    alias Def!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) Def; 
     290
     291template Def(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
     292    alias Def!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def; 
     293
     294struct Def(alias fn, char[] _realname, char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
    280295    //static const type = ParamType.Def; 
    281296    alias fn func; 
     
    292307        list[length-1].ml_meth = &method_wrap!(T, fn, fn_t).func; 
    293308        list[length-1].ml_flags = METH_VARARGS; 
    294         list[length-1].ml_doc = ""
     309        list[length-1].ml_doc = (docstring~\0).ptr
    295310        list ~= empty; 
    296311        // It's possible that appending the empty item invalidated the 
     
    310325Wraps a static member function of the class. Identical to pyd.def.def 
    311326*/ 
    312 struct StaticDef(alias fn, char[] name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS=minArgs!(fn)) { 
     327template StaticDef(alias fn, char[] docstring="") { 
     328    alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), typeof(&fn), minArgs!(fn), docstring) Def; 
     329
     330template StaticDef(alias fn, char[] name, char[] docstring) { 
     331    alias StaticDef!(fn, symbolnameof!(fn), name, typeof(&fn), minArgs!(fn), docstring) Def; 
     332
     333template StaticDef(alias fn, char[] name, fn_t, char[] docstring) { 
     334    alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, minArgs!(fn), docstring) Def; 
     335
     336template StaticDef(alias fn, fn_t, char[] docstring="") { 
     337    alias StaticDef!(fn, symbolnameof!(fn), symbolnameof!(fn), fn_t, minArgs!(fn), docstring) Def; 
     338
     339template StaticDef(alias fn, char[] name, fn_t, uint MIN_ARGS=minArgs!(fn), char[] docstring="") { 
     340    alias StaticDef!(fn, symbolnameof!(fn), name, fn_t, MIN_ARGS, docstring) Def; 
     341
     342struct StaticDef(alias fn, char[] name, fn_t, uint MIN_ARGS, char[] docstring) { 
    313343    //static const type = ParamType.StaticDef; 
    314344    alias fn func; 
     
    323353        list[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; 
    324354        list[length-1].ml_flags = METH_VARARGS | METH_STATIC; 
    325         list[length-1].ml_doc = ""
     355        list[length-1].ml_doc = (docstring~\0).ptr
    326356        list ~= empty; 
    327357        wrapped_class_type!(T).tp_methods = list; 
     
    340370RO = Whether this is a read-only property. 
    341371*/ 
    342 template Property(alias fn, char[] name = symbolnameof!(fn), bool RO=false) { 
    343     alias Property!(fn, symbolnameof!(fn), name, RO) Property; 
    344 
    345 struct Property(alias fn, char[] _realname, char[] name, bool RO) { 
     372//template Property(alias fn, char[] name = symbolnameof!(fn), bool RO=false, char[] docstring = "") { 
     373//    alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property; 
     374//} 
     375template Property(alias fn, char[] docstring="") { 
     376    alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), false, docstring) Property; 
     377
     378template Property(alias fn, char[] name, char[] docstring) { 
     379    alias Property!(fn, symbolnameof!(fn), name, false, docstring) Property; 
     380
     381template Property(alias fn, char[] name, bool RO, char[] docstring="") { 
     382    alias Property!(fn, symbolnameof!(fn), name, RO, docstring) Property; 
     383
     384template Property(alias fn, bool RO, char[] docstring="") { 
     385    alias Property!(fn, symbolnameof!(fn), symbolnameof!(fn), RO, docstring) Property; 
     386
     387struct Property(alias fn, char[] _realname, char[] name, bool RO, char[] docstring) { 
    346388    alias property_parts!(fn).getter_type get_t; 
    347389    alias property_parts!(fn).setter_type set_t; 
     
    359401                &wrapped_set!(T, fn).func; 
    360402        } 
    361         wrapped_prop_list!(T)[length-1].doc = ""
     403        wrapped_prop_list!(T)[length-1].doc = (docstring~\0).ptr
    362404        wrapped_prop_list!(T)[length-1].closure = null; 
    363405        wrapped_prop_list!(T) ~= empty; 
     
    453495iterator. 
    454496*/ 
    455 struct AltIter(alias fn, char[] name = symbolnameof!(fn), iter_t = funcDelegInfoT!(typeof(&fn)).Meta.ArgType!(0)) { 
     497struct AltIter(alias fn, char[] name = symbolnameof!(fn), iter_t = ParameterTypeTuple!(fn)[0]) { 
    456498    static void call(T, shim) () { 
    457499        static PyMethodDef empty = { null, null, 0, null }; 
     
    461503        list[length-1].ml_meth = cast(PyCFunction)&wrapped_iter!(T, fn, int function(iter_t)).iter; 
    462504        list[length-1].ml_flags = METH_VARARGS; 
    463         list[length-1].ml_doc = (docstring ~ \0).ptr; 
     505        list[length-1].ml_doc = "";//(docstring ~ \0).ptr; 
    464506        list ~= empty; 
    465507        // It's possible that appending the empty item invalidated the 
     
    481523        alias make_wrapper!(_T, Params).wrapper shim_class; 
    482524        alias _T T; 
     525//    } else static if (is(_T == interface)) { 
     526//        pragma(msg, "wrap_interface: " ~ name); 
     527//        alias make_wrapper!(_T, Params).wrapper shim_class; 
     528//        alias _T T; 
    483529    } else { 
    484530        pragma(msg, "wrap_struct: " ~ name); 
     
    588634        wrapped_classes[T.classinfo] = &type; 
    589635        wrapped_classes[shim_class.classinfo] = &type; 
     636    } 
     637} 
     638 
     639//////////////// 
     640// DOCSTRINGS // 
     641//////////////// 
     642 
     643struct Docstring { 
     644    char[] name, doc; 
     645} 
     646 
     647void docstrings(T=void)(Docstring[] docs...) { 
     648    static if (is(T == void)) { 
     649         
    590650    } 
    591651} 
  • trunk/infrastructure/pyd/struct_wrap.d

    r101 r103  
    6363} 
    6464 
    65 struct Member(char[] realname, char[] name=realname) { 
     65template Member(char[] realname, char[] docstring="") { 
     66    alias Member!(realname, realname, docstring) Member; 
     67
     68struct Member(char[] realname, char[] name, char[] docstring) { 
    6669    static void call(T, dummy) () { 
    6770        pragma(msg, "struct.member: " ~ name); 
     
    7174        list[length-1].get = &wrapped_member!(T, realname).get; 
    7275        list[length-1].set = &wrapped_member!(T, realname).set; 
    73         list[length-1].doc = ""
     76        list[length-1].doc = (docstring~\0).ptr
    7477        list[length-1].closure = null; 
    7578        list ~= empty;