[C++-sig] Re: Pyste: support for user defined code.

David Abrahams dave at boost-consulting.com
Sat Aug 16 22:19:46 CEST 2003


Nicodemus <nicodemus at globalite.com.br> writes:

> Hi Prabhu!
>
> Prabhu Ramachandran wrote:
>
>>>>>>>"N" == nicodemus  <nicodemus at globalite.com.br> writes:
>>>>>>>            
>>
>>    N> Prabhu Ramachandran wrote:
>>    >> Hi,
>>    >>
>>    >> I was thinking of adding a new feature to Pyste so that a user
>>    >> could add arbitrary code to the code generated by Pyste.
>>    >> Something along these lines:
>>    >>
>>    >> ud = UserDefined() ud.addToHeader(['h1.hpp', 'h2.hpp'])
>>    >> ud.addToDeclaration("""// insert code in the declaration area
>>    >> """) ud.addToModule("""// insert code inside the module
>>    >> area""")
>>
>>    N> Seems easy, but I think a more functional interface would fit
>>    N> with the rest better:
>>
>>    N> add_include('h1.hpp', 'h2.hpp') add_code(MODULE, '''
>>    N>          class_< std::vector<bool> > ("VectorBool")
>>    N>              .def(vector_indexing_suite< std::vector<bool>,
>>    N>              true> ());''')
>>
>>Thats fine too but will there be a problem with ordering of the code
>>if the interface is functional? i.e. if I have a class('A', 'h.hpp')
>>and then want to add the user defined code after this, is it possible
>>to do with this approach?  I also thought that the UserDefined
>>approach would be easier to implement.
>>
>
> Yeah, no problem. The ordering is kept, since the exporters are kept
> in a list.
>
> So, how about this interface:
>
> add_include('header1', 'header2', 'header3')
> add_code(MODULE, <code>)
> add_code(DECLARATION, <code>)
> add_code(GLOBAL_DECLARATION, <code>)  # outside the namespace

What about, simply:

    include('header1', 'header2', 'header3')
    code(MODULE, <code>)
    code(DECLARATION, <code>)
    code(GLOBAL_DECLARATION, <code>)  # outside the namespace

Or:

    include('header1', 'header2', 'header3')
    inline(MODULE, <code>)
    inline(DECLARATION, <code>)
    inline(GLOBAL_DECLARATION, <code>)  # outside the namespace

But what are those ALL_CAPS names?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list