idea: Templates + AJAX = breakthrough application

Robert Fraser fraserofthenight at gmail.com
Sat Nov 17 22:11:04 PST 2007


BCS Wrote:

> 
> I have thought up a really cool template programming idea. I'm so swamped 
> now that I don't have time to work on it so I'm throwing it out here to see 
> if anyone wants to give it a go. Anyway, her its.
> 
> In a nutshell: Auto AJAX from template magic.
> 
> it would consist of a template that specializes on a class, interface, struct 
> or free function. The template would implement a function that would take 
> something of the given type. this function would be the server side of an 
> AJAX setup that would exercise the given variable's public interface. The 
> template would also generate a const string that is the JavaScript that is 
> needed for the client side.
> 
> I see it being used something like this:
> 
> // given the users partial input,
> // return a list of auto compleat choices
> char[][] GetChoices(char[] text){...}
> 
> const int AJAXport = 0xF00D;
> const char[] AJAXaddress = "somwhere.not";
> 
> char[] BuildWebPageBody()
> {
> 	char[] ret;
> 
> 	ret ~= stuff
> 	ret ~= "<script type='text/javascript'>\n";
> 	ret ~= AJAX!(GetChoices).JavaScript!(AJAXaddress, AJAXport);
> 	ret ~= "</script>\n";
> 	ret ~= moreStuff;
> 	return ret;
> }
> 
> AJAXthread AJAXserver;
> 
> static this()
> {
> 	AJAXserver = AJAX!(GetChoices).StartServerThread(AJAXport);
> }
> 
> static ~this()
> {
> 	AJAXserver.kill();
> }
> 
> 

I had this idea a while back, except I used a compile-time function not a template.



More information about the Digitalmars-d mailing list