Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » How to call a C++ function in Witz template?
How to call a C++ function in Witz template? [message #39167] Thu, 21 February 2013 11:47 Go to next message
Peter is currently offline  Peter
Messages: 16
Registered: October 2012
Promising Member
Hi.

According to Witz manual it's possible to call a C++ function in Witz template. Unfortunately there's no example showing how to do that. In one of my source files I defined a trivial function:

void fun(int& i)
{
   i++;
}


and Skylark handler:

SKYLARK(AAA, "aaa")
{
   http("MYVAR", Value(2)); 
   http("MYFUN", fun);
   http.RenderResult("Project_name/aaa");
}


The corresponding aaa.witz template looks like this:

<html>
<body>

$MYVAR
$MYFUN($MYVAR)
$MYVAR

</body>
</html>


I expected to see the following output: 2 3 (old and new value of MYVAR). Instead I got the following error message:

"function nor link not found 'MYFUN'".

I assumed I just had to pass a pointer to my function as a value of shared variable MYFUN to make it visible in Witz template, but apparently that's not how it works. What's the correct way to do it?
Re: How to call a C++ function in Witz template? [message #39168 is a reply to message #39167] Thu, 21 February 2013 12:08 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Peter,

Peter wrote on Thu, 21 February 2013 11:47

I assumed I just had to pass a pointer to my function as a value of shared variable MYFUN to make it visible in Witz template, but apparently that's not how it works. What's the correct way to do it?


It would be nice if it would work this way, but unfortunately it doesn't (at least not yet Smile ). You have to register the function and it has to have correct signature. The simple increment function from your example can be done like this (not tested):
Value Fun(const Vector<Value>& arg, const Renderer *)
{
	if(arg.GetCount() != 1 && !IsNumber(arg[0]))
		return "ERROR";
	return (int)arg[0] + 1;
}

INITBLOCK {
	Compiler::Register("fun", Fun);
};

This code should be placed in .icpp file, to make sure it is linked correctly. Now you can call the function in witz using $fun(MYVAR), it does not have to be passed to the Http.

Is that clearer now? Further examples can be found in Skylark/StdLib.icpp.

Best regards,
Honza
Previous Topic: Skylark and Date/Time format
Next Topic: Cant connect but dont get an error
Goto Forum:
  


Current Time: Thu Apr 18 20:28:14 CEST 2024

Total time taken to generate the page: 0.05356 seconds