How To Dynamic Web Rendering?

Nathan nchriste at yahoo.com
Tue May 24 13:46:46 PDT 2011


Adam,

Thanks for the step by step guide.  My problem was exactly what you
outlined, that "yourFunctionHere" did not take Cgi cgi as an argument.
That's all I needed!

I definitely understand the benefit of the mixin -- the overall design
makes a lot of sense.

Nathan





On Mon, 23 May 2011 16:57:06 +0000 (UTC), Adam D. Ruppe
<destructionator at gmail.com> wrote:

>Also:
>
>" other two errors say that "modulename.run" cannot be called with
>argument type Cgi and that 0 arguments are expected for function type void "
>
>When using the generic main mixin, the function you pass must
>always take one argument: a Cgi object.
>
>void yourFunctionHere(Cgi cgi) { }
>
>When the mixin is compiled, it expands to something like this:
>
>
>void main() {
>   auto cgi = new Cgi;
>   scope(exit) cgi.close();
>   try {
>        yourFunctionHere(cgi);
>   } catch (Exception) {
>        // log and maybe display the error then exit
>   }
>}
>
>
>So the function you pass to the mixin is called with an argument:
>
>        yourFunctionHere(cgi);
>
>
>Which might be producing the error you saw, if your function
>couldn't take the cgi object as it's own argument.
>
>
>
>
>Why use the mixin at all? Writing main yourself might be simpler.
>
>There's three reasons:
>
>!) It saves you from writing the same thing over and over as your
>   main function. This is a small benefit, but it's nice.
>
>2) It can display errors to the browser in debug mode. This makes
>   debugging easier. The message is right there.
>
>3) This is the biggest one: if the main() function ever needs to
>   change, your code doesn't.
>
>Thanks to the GenericMain mixin, for example, you can switch to
>using FastCGI or a built in webserver simply by recompiling with
>a different version. None of your code has to change.


More information about the Digitalmars-d-learn mailing list