D lodepng compilation error - image-processing

I have some trouble compiling lodepng (http://lodev.org/lodepng/) for D into my project.
In Encode.d I have the following code, where the compiler does not expect the assert statements.
Removing this block solves the issue.
invariant
{
assert(compressionLevel >=0 && compressionLevel <= 9, "invalid zlib compression level");
assert(targetColorType == ColorType.Any ||
targetColorType == ColorType.RGB ||
targetColorType == ColorType.RGBA, "colortype is not supported");
}
In Decode.d I have even more trouble, with the error "no identifier for declarator inout(value)"
for the middle line in:
info.backgroundColor.length = chunk.data.length / 2;
foreach(index, inout value; info.backgroundColor)
value = chunk.data[index * 2];
Is there some trouble with old syntax here, and how do I fix it?
Is there some other way to create png images in D in a simple manner?

Not sure about the invariant problem, but the second problem should be solved by replacing the "inout" with "ref" (D2 syntax change).

I gave up on lodepng, and used the code on
http://www.dsource.org/projects/plot2kill/browser/trunk/png.d
which works after some minor changes.

Related

Not sure how to resolve null aware before operator

I'm getting a warning
The left operand uses '?.', so its value can be null
from this line of code
code = username?.hashCode % 7 ?? 0 % 7;
Not sure what the best practise is and why!
You're trying to use the % 7 operator before you do your null check. You might be calling null % 7, which definitely won't work. Move that outside of your null check.
code = (username?.hashCode ?? 0) % 7;

How do I add an offset ot an IndexOf result in z3

How do I add an offset to a value obtained from an IndexOf expression? That is, how do I do this?
> import z3
> s = 'hello'
> t = 'e'
> z3.simplify(z3.IndexOf(s, t, 0) + z3.IntVal(1))
z3.z3types.Z3Exception: Non-sequence passed as a sequence
I want to get the location after than of e.
On the other hand, switching the order works as expected
> z3.simplify(z3.IntVal(1) + z3.IndexOf(s, t, 0))
2
You found a bug in z3py!
The bug is on this line: https://github.com/Z3Prover/z3/blob/master/src/api/python/z3/z3.py#L10150
which reads:
return SeqRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
Instead, it should say:
return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
I've reported this at their bug tracker: https://github.com/Z3Prover/z3/issues/2159
Once you make that change in your local-copy of z3.py, your program should work as is. Or you can wait till they release a fix.

JSHint: How do disable the check for unsafe characters for comments?

When using "unsafe characters" (e.g. umlauts) in comments I get the following error:
This character may get silently deleted by one or more browsers.
Is there any way to disable this check for comments (globally)?
I fixed it in one specific file by adding /* jshint -W100 */ in the top of the file.
To ignore it globally, I guess you have to add it somewhere in .jshintrc (though I don't know where).
I was able to fix this problem by saving the document as UTF-8.
I have several files all created the same way, three of them are giving me this error using gulp + jslint, I dont know why but I managed to get rid of the error in Sublime Text by going to:
File > Save with Encoding > UTF-8
Errors magically disappear!
I solve this problem as follows ...
in jshint.js change the lines
char = this.scanUnsafeChars();
if (char >= 0) {
this.trigger("warning",
{ code: "W100", line: this.line, character: char });
}
to
char = this.scanUnsafeChars();
if (char >= 0) {
var inCommentW100 = this.inComment ||
startsWith.call(inputTrimmed, "//") ||
startsWith.call(inputTrimmed, "/*");
if(!inCommentW100) {
this.trigger("warning",
{ code: "W100", line: this.line, character: char });
}
}

How can I get Velocity to output a greater than / less than without escaping it?

I'm trying to get Velocity to output the following Javascript code:
if ((whichOne+1) <= numCallouts ) {
whichOne = whichOne + 1; } else {
whichOne = 1;
}
Whenever I try to get Velocity to print a > or a <, it represents it as a & gt; or & lt;, which doesn't help me since I'm trying to get it to produce Javascript. I've tried:
#set ( $gt = ">" )
But even that ends up as a & gt;
Thanks in advance.
It is not a default behavior, the only reason I can think of why this is happening is if you have event ReferenceInsertionEventHandler configured with EscapeHtmlReference either in your velocity.config or in the Velocity initialization code.
Here is more info about events
I've had the same issue with Velocity - however, the problem is that I was using Velocity as an third party embedded language, and didn't have access to change the Velocity settings.
Unfortunately the only solution I was able to find was to rewrite the code without using greater than/less than explicitly, which admittedly is awful, but it's all about getting it to work...
Here is an example workaround for conditionals where you are trying to see if one number is larger than another:
if (n1 > n2) //Doesn't work because velocity turns this into if (n1 > n2)
if (n1 != n2)
{
diff = n1 - n2;
abs = abs(n1 - n2);
if (diff / abs == 1) //Greater than
else //if == -1 then less than
}
else //Equal
Maybe you are able to use the alternate symbols as described here :
http://velocity.apache.org/engine/devel/vtl-reference-guide.html#aifelseifelse_-_Output_conditional_on_truth_of_statements
So try to use if (n1 gt n2).

Lua = operator as print

In Lua, using the = operator without an l-value seems to be equivalent to a print(r-value), here are a few examples run in the Lua standalone interpreter:
> = a
nil
> a = 8
> = a
8
> = 'hello'
hello
> = print
function: 003657C8
And so on...
My question is : where can I find a detailed description of this use for the = operator? How does it work? Is it by implying a special default l-value? I guess the root of my problem is that I have no clue what to type in Google to find info about it :-)
edit:
Thanks for the answers, you are right it's a feature of the interpreter. Silly question, for I don't know which reason I completely overlooked the obvious. I should avoid posting before the morning coffee :-) For completeness, here is the code dealing with this in the interpreter:
while ((status = loadline(L)) != -1) {
if (status == 0) status = docall(L, 0, 0);
report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print");
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
l_message(progname, lua_pushfstring(L,
"error calling " LUA_QL("print") " (%s)",
lua_tostring(L, -1)));
}
}
edit2:
To be really complete, the whole trick about pushing values on the stack is in the "pushline" function:
if (firstline && b[0] == '=') /* first line starts with `=' ? */
lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
Quoting the man page:
In interactive mode ... If a line starts with '=', then lua displays the values of all the expressions in the remainder of the line. The expressions must be separated by commas.
I think that must be a feature of the stand alone interpreter. I can't make that work on anything I have compiled lua into.
I wouldn't call it a feature - the interpreter just returns the result of the statement. It's his job, isn't it?
Assignment isn't an expression that returns something in Lua like it is in C.

Resources