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 » Using Raw Values in arrays (with Skylark)
Using Raw Values in arrays (with Skylark) [message #40194] Mon, 01 July 2013 22:48
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

I've been using (or abusing Smile ) the fact that ValueArrays and ValueMaps are translated in templates to something that resembles valid JavaScript. For numbers, it works quite well, but with Strings I've encountered a problem...

To make it work with strings, quotes must be included in the string, but quotes are automatically escaped. So I tried to use Raw() to prevent that, only to find out it doesn't really work.

Here are some things I tried:
SKYLARK(Test, "")
{
	// The goal is to produce javascript array like this:
	//    [ "a", "b" ]
	
	ValueArray v1;
	v1.Add("\"a\"");
	v1.Add("\"b\"");
	http("TEST1", v1);
	// produces ["a", "b"]
	//  --> not "raw"
	
	ValueArray v2;
	v2.Add(Raw("\"a\""));
	v2.Add(Raw("\"b\""));
	http("TEST2", v2);
	// produces [RAW: "a", RAW: "b"]
	//  --> not "raw" + totaly unusable because of the RAW: prefix
	
	Vector<String> v3;
	v3.Add("\"a\"");
	v3.Add("\"b\"");
	http("TEST3", Raw(Join(v3, ", ")));
	// produces "a", "b"
	//  --> closest to desired output (missing only enclosing []), but not 
	//      an array anymore (I might want to iterate over it someplace
	//      else in the template)
	
	http.RenderResult("test/index");
}

I'm currently using the third option, but it is not elegant (i.e. ugly) workaround... Is there some other way? Or would it be possible to modify the Skylark internals to print out the members of arrays and maps directly rather than just calling ToString() on the container? I think that that would make the second test work perfectly...

Best regards,
Honza

PS: I know I could iterate over the array in template using $for and build the Javascript array "manually", but that does hinder the readability of the templates quite considerably...

[Updated on: Mon, 01 July 2013 22:49]

Report message to a moderator

Previous Topic: Fatal error - GuiLock
Next Topic: Socket client out of buffer error and reusing sockets
Goto Forum:
  


Current Time: Tue Apr 16 19:57:16 CEST 2024

Total time taken to generate the page: 0.01275 seconds