www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Function parameters name

reply Julian <julien onandon.be> writes:
Hello,

     I'm trying to obtain the parameters name of a function via __traits.

     The patches are on bugzilla :  
http://d.puremagic.com/issues/show_bug.cgi?id=3309

     Could you please review this ?

     Provided test case works.. but I actually have a problem with  
FuncDeclaration->parameters being NULL when the function is declared in  
another module.



     The main idea is to build a small web framework going along the lines  
of :

         class HelloResource
         {
             string show(in string username)
             {
                 return "Hello, " ~ username;
             }
         }

         (new ResourceMapper).connect!("/hello/{username}")(new  
HelloResource);

     http://www.example.com/hello/Julian : `show` method would be called  
with "Julian" being the `username` parameter.


         class UsersResource
         {
             User[] show(in ushort offset, in ushort limit)
             {
                 return [ user0, user1 ];
             }
         }

         (new ResourceMapper).connect!("/users")(new UsersResource);

     http://www.example.com/users?offset=0&limit=10 : `show` method would  
be called with 0 being the `offset` parameter and 10 being the `limit`  
parameter.


Thank you,
Julian.
Sep 10 2009
parent Jacob Carlborg <doob me.com> writes:
You can also get the parameter names using .stringof, see 
http://www.dsource.org/projects/dstep/browser/dstep/internal/Traits.d 
for an example. This will also work in D1.

On 9/10/09 20:34, Julian wrote:
 Hello,

 I'm trying to obtain the parameters name of a function via __traits.

 The patches are on bugzilla :
 http://d.puremagic.com/issues/show_bug.cgi?id=3309

 Could you please review this ?

 Provided test case works.. but I actually have a problem with
 FuncDeclaration->parameters being NULL when the function is declared in
 another module.



 The main idea is to build a small web framework going along the lines of :

 class HelloResource
 {
 string show(in string username)
 {
 return "Hello, " ~ username;
 }
 }

 (new ResourceMapper).connect!("/hello/{username}")(new HelloResource);

 http://www.example.com/hello/Julian : `show` method would be called with
 "Julian" being the `username` parameter.


 class UsersResource
 {
 User[] show(in ushort offset, in ushort limit)
 {
 return [ user0, user1 ];
 }
 }

 (new ResourceMapper).connect!("/users")(new UsersResource);

 http://www.example.com/users?offset=0&limit=10 : `show` method would be
 called with 0 being the `offset` parameter and 10 being the `limit`
 parameter.


 Thank you,
 Julian.

Sep 10 2009