Home » Developing U++ » U++ Developers corner » Some questions about witz
Re: Some questions about witz [message #37319 is a reply to message #37117] |
Fri, 21 September 2012 23:34   |
|
Hi Mirek,
I think I found another little bug The subscript operators sometimes work wrong for maps with numeric indices. Testcase:
handler | SKYLARK(HomePage, "")
{
ValueMap m;
m.Add(1, "first");
m.Add(2, "second");
http("TEST", m)
.RenderResult("Test/index");
}
|
index.witz | <html>
<body>
TEST = $TEST <br>
TEST[0] = $TEST[0] <br>
TEST[1] = $TEST[1] <br>
TEST[2] = $TEST[2] <br>
TEST[3] = $TEST[3] <br>
</body>
</html>
|
This renders as: | TEST = { 1: first, 2: second }
TEST[0] = first
TEST[1] = second
TEST[2] = second
TEST[3] =
|
To fix it, it is necessary to first check for ValueMap and only after that try ValueArray in ExeBracket::Eval():
Value Compiler::ExeBracket::Eval(ExeContext& x) const
{
Value m = value->Eval(x);
Value q = index->Eval(x);
if(IsValueMap(m)) {
ValueMap map = m;
return map[q];
}
if(IsNumber(q) && IsValueArray(m)) {
ValueArray va = m;
int i = q;
if(i >= 0 && i < va.GetCount())
return va[i];
}
return Value();
}
With this fix it renders correctly as | TEST = { 1: first, 2: second }
TEST[0] =
TEST[1] = first
TEST[2] = second
TEST[3] =
|
Is this solution correct?
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Mon Jun 09 08:46:25 CEST 2025
Total time taken to generate the page: 0.05973 seconds
|