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++ Library : Other (not classified elsewhere) » Skylark functions/links
Skylark functions/links [message #42922] Mon, 14 April 2014 17:46 Go to next message
mingodad is currently offline  mingodad
Messages: 53
Registered: February 2008
Location: Spain
Member
Hello !

I need to have a way to url_encode some values in witz templates (not in c++), it seems that there is a way to define new functions to be available in witz templates but is not documented, I looked at the source code but could not see how to do it.

Someone can shed a light here ?

Also the way to make links is not too good, I needed to add bookmarks to the links but the actual link function do not seem to accept it and also return a quoted string what makes add things to it in witz impossible.

I replaced on souce all ("\"" + theLink + "\"") by just (theLink) and could achieve my needs.

Another topic related with witz is the actual way to add witz code prefixing with "#$" works fine for hand write code from programmers but it's not friendly to designers and wysiwyg tools (need be aware of escaping "#$" and it can makes invalid html).

I propose to put then hidden inside tags:

<if()><else/></endif> <for()></endfor> ${variable}

It's a bit anoying for hand write but for wysiwyg editors it's fine.

Cheers !
Re: Skylark functions/links [message #42924 is a reply to message #42922] Mon, 14 April 2014 18:14 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 327
Registered: July 2009
Senior Member
Take a look at this thread:

http://www.ultimatepp.org/forums/index.php?t=msg&th=7545 &goto=39562&#msg_39562

You have to create function body and register it:

Value translate(const Vector<Value>& arg, const Renderer *)
{
	if(arg.GetCount() == 1 && IsString(arg[0]))
		return GetLngString(GetCurrentLanguage(), (String)arg[0]);
	return arg[0];
}

INITBLOCK {
	Compiler::Register("t_", translate);
};


And after that you can use it in witz:
$t_("some text")

[Updated on: Mon, 14 April 2014 18:21]

Report message to a moderator

Re: Skylark functions/links [message #42925 is a reply to message #42924] Mon, 14 April 2014 18:49 Go to previous messageGo to next message
mingodad is currently offline  mingodad
Messages: 53
Registered: February 2008
Location: Spain
Member
Thanks for the link !

I've created this function:
Value WitzUrlEncode(const Vector<Value>& arg, const Renderer *) {
	if(arg.GetCount() != 1 || !IsString(arg[0]))
		return String();
	StringBuffer buf;
	UrlEncode(buf, String(arg[0]));
	return Value(buf.Begin());
}

INITBLOCK {
	Compiler::Register("url_encode", WitzUrlEncode);
}


But I get two kind of errors ($rec.name has valid content) :
------
$url_encode($rec.name) >>> Internal server error (206,12): missing number
------
or
------
$url_encode(rec.name) >>> *************PANIC: Invalid memory access! Segmentation fault (core dumped)
------

Probably a bug in U++ !!!

Attached sample to test!

[Updated on: Mon, 14 April 2014 19:12]

Report message to a moderator

Re: Skylark functions/links [message #42926 is a reply to message #42925] Mon, 14 April 2014 20:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14162
Registered: November 2005
Ultimate Member
mingodad wrote on Mon, 14 April 2014 16:49
Thanks for the link !

I've created this function:
Value WitzUrlEncode(const Vector<Value>& arg, const Renderer *) {
	if(arg.GetCount() != 1 || !IsString(arg[0]))
		return String();
	StringBuffer buf;
	UrlEncode(buf, String(arg[0]));
	return Value(buf.Begin());
}

INITBLOCK {
	Compiler::Register("url_encode", WitzUrlEncode);
}


But I get two kind of errors ($rec.name has valid content) :
------
$url_encode($rec.name) >>> Internal server error (206,12): missing number
------
or
------
$url_encode(rec.name) >>> *************PANIC: Invalid memory access! Segmentation fault (core dumped)
------

Probably a bug in U++ !!!

Attached sample to test!


Well, this is nice one... Smile

What happened here is that you have probably seen

UrlEncode(StringBuffer& b, const char *s) signature in Skylark - but that is local function (my fault, should have made it static).

What got called instead was

UrlEncode(const char *begin, const char *end);

(from Core/Inet.h)

which, having begin and end pointing to unrelated things, obviously crashed.

This works:

Value WitzUrlEncode(const Vector<Value>& arg, const Renderer *) {
	return arg.GetCount() == 1 && IsString(arg[0]) ? UrlEncode(arg[0]) : String();
}

INITBLOCK {
	Compiler::Register("url_encode", WitzUrlEncode);
}
Re: Skylark functions/links [message #42931 is a reply to message #42926] Mon, 14 April 2014 21:20 Go to previous messageGo to next message
mingodad is currently offline  mingodad
Messages: 53
Registered: February 2008
Location: Spain
Member
Yes it works, thanks again !

One thing I noticed now but I didn't got it on the documentation, when using variables as parameters to functions in witz we should not use "$" in front of it, a bit confusing !

Cheers !
Re: Skylark functions/links [message #42934 is a reply to message #42931] Mon, 14 April 2014 22:39 Go to previous message
mirek is currently offline  mirek
Messages: 14162
Registered: November 2005
Ultimate Member
mingodad wrote on Mon, 14 April 2014 19:20
Yes it works, thanks again !

One thing I noticed now but I didn't got it on the documentation, when using variables as parameters to functions in witz we should not use "$" in front of it, a bit confusing !

Cheers !


It is not PHP Smile

$ just starts the expression.

Mirek
Previous Topic: ParseSvg.cpp:506:35: error: conversion from 'Upp::String' to non-scalar type
Next Topic: Witz template cryptic error messages
Goto Forum:
  


Current Time: Fri Dec 13 23:29:28 CET 2024

Total time taken to generate the page: 0.02852 seconds