Re: Using the result of a comma expression is deprecated

2016-11-27 Thread Erik van Velzen via Digitalmars-d-learn
On Sunday, 27 November 2016 at 12:13:03 UTC, Nicholas Wilson 
wrote:

On Sunday, 27 November 2016 at 11:49:25 UTC, Suliman wrote:

On Sunday, 27 November 2016 at 11:21:58 UTC, drug007 wrote:

	void dbInsert(string login, string uploading_date, string 
geometry_type, string data)

{

Statement stmt = conn.createStatement();
		string sqlinsert = (`INSERT INTO usersshapes (userlogin, 
uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', 
'%s') `, login, uploading_date, geometry_type, data);

stmt.executeUpdate(sqlinsert);
scope(exit) stmt.close(); // closing
}

full code.


Looks like you forgot a call to format before the opening 
parenthesis.


should be:
string sqlinsert = format(`INSERT INTO usersshapes (userlogin,
 uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s',
 '%s') `, login, uploading_date, geometry_type, data);

because what ends up happening is :
string sqlinsert = data;
which is almost certainly not what you want.


As an aside, for security reasons you should use a prepared 
statement.


Also, this is a decent usecase for scope(exit) but it should be 
put earlier in the function.


Re: Is it possible to store different generic types in ex. an

2016-11-12 Thread Erik van Velzen via Digitalmars-d-learn
On Wednesday, 9 November 2016 at 15:44:59 UTC, Is it possible to 
store different generic types? wrote:


Foo[] foos; // Where Foo of course should allow any generic 
version of Foo




You can use an array of std.variant


dmd compile large project

2014-01-25 Thread Erik van Velzen
I just downloaded a larger project from Github without a build 
script or anything.


Is there an easy way to compile it to a library or object files?


Re: dmd compile large project

2014-01-25 Thread Erik van Velzen
Thanks for the input I was thinking there maybe was an easy way 
that I wasn't aware of.


I only wanted to use a small part of the project so I just made a 
list of those files and their dependencies and compiled that.


logical operands on strings

2014-01-12 Thread Erik van Velzen

I would like to do this:

string one = x315c4eeaa8b5f8aaf9174145bf43e1784b;
string two = xc29398f5f3251a0d47e503c66e935de81230b59b7a;
string three = one ^ two;


The closests I've been able to get is:

string three = xor(one, two);

string xor(string one, string two) {
int len = min(one.length, two.length);
string result;
for(int i=0; ilen; i++) {
result ~= one[i] ^ two[i];
}
return cast(string)result;
}

Question 1: is there a more elegant way to implement the function 
xor? (foreach-ish or std.algorithm)



Then I tried to add operator overloading:

string opBinary(string op)(string lhs, string rhs) {
static if( op == ^ )
return xor(lhs, rhs);
else static assert(false, operator not possible);
}

But it doesn't invoke this function.

Question 2: how would I implement ^ for strings?


Re: logical operands on strings

2014-01-12 Thread Erik van Velzen

On Sunday, 12 January 2014 at 18:28:38 UTC, Meta wrote:


It looks like your opBinary on strings is an attempt at 
globally overriding the XOR operator. I'm almost 100% sure this 
won't work in D. All operator overloads have to be part of a 
class or struct.


How would I do that without rewriting an entire string class? It 
seems I can't even inherit from string.


Forgive me for making the comparison, but I believe in C++ i can 
simply implement this function and be done with it:


string operator^(string lhs, string rhs);


Re: Compile/link Win64

2014-01-12 Thread Erik van Velzen

On Friday, 10 January 2014 at 21:47:23 UTC, Nick Sabalausky wrote:

Hmm, I hadn't ever uninstalled it.

Regardless, *now* I've just uninstalled and reinstalled the 
Windows SDK, and re-ran vcvarsall.bat. The %WindowsSdkDir% is 
now set, but I'm still getting the same problem.


The %WindowsSdkDir% is set to C:\Program Files (x86)\Microsoft 
SDKs\Windows\v8.0A, but there doesn't appear to be much in 
there (Just a Bootstrapper\Packages directory with not much 
inside it either). I don't think it installed correctly. There 
doesn't appear to be any other Windows SDK installation AFAICT 
either. Stupid f#*^# microsoft tools...



The lastest Windows SDK installs to C:\Program Files 
(x86)\Windows Kits\8.1\


Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen

It works if you recompile phobos64.lib

So it seems the standard DMD 2.064.2 download comes with an
outdated version of phobos64.lib which is out of sync with the
included source code.


Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen

@Palmic the DWinProgramming samples use the overload

Runtime.initialize(ExceptionHandler)

Which gives a warning that it is deprecated and you should use 
this overload instead:


Runtime.initialize()

But this is not compiled in phobos64.lib, while it is included in 
the source code. So the library and source code are out of sync. 
Fortunately it is relatively easy to compile yourself.


I will make a bug report for this.


Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen

Filed under installer

https://d.puremagic.com/issues/show_bug.cgi?id=11871

You could add the linux thing as a comment if you're sure it's 
the same issue.


Re: D on Windows - linker question

2013-10-21 Thread Erik van Velzen

On Monday, 21 October 2013 at 04:38:05 UTC, evilrat wrote:


i'm currently trying to get up 
DirectX(d3d10(x),d3d11(x),xaudio2,x3daudio,d3dmath) up and 
running in free time, but i constantly encounter serious 
problems on my way. now i have some weird problems with COM(no 
COM - no DirectX).


so i don't recommend anyone even try it(DirectX) now, unless 
one is truly skilled with C++


Thanks for your advice, I suspected as much.

I will hack some more and see if I'm progressing or learning
anything. And decide in a few days if I continue with D3D in D,
or stick to C++. I do have experience in C++, though with server
apps on Linux without native GUIs.

p.s. for working win32 with dmd 2.063.2 go there(don't forget 
to convert .lib's to OMF, use coffimplib from digitalmars ftp) 
- 
https://github.com/AndrejMitrovic/DWinProgramming/tree/master/WindowsAPI


I'm using COFF with the visual studio linker, so I don't need to
convert.

I do get a few compiler errors with DMD in these win32.* modules
about incorrect typecasts. I will make a new topic if these
persist or file a bug report with the author.


Re: D on Windows - linker question

2013-10-20 Thread Erik van Velzen

My goal was to learn D and Direct3D at the same time.

I've tried to set up DMD to do this, but I keep running into 
issues that the available DirectX11 and win32 headers are 
incomplete, or won't compile (tried both dmd 2.063 and 2.064, 
they halt on different type errors), or won't link.


To be fair, these are only a few errors, but when the linker 
spews out some obfuscated function name I really don't know what 
to do.


Will I have more luck with GDC? Or should I try to make headers 
on my own incrementally? (or take the easy route and use C++?)


D on Windows - linker question

2013-10-18 Thread Erik van Velzen

Hello,
I have set up my enviroment according to these instructions:
http://wiki.dlang.org/Installing_DMD_on_64-bit_Windows_7_%28COFF-compatible%29

When I compile a small tutorial program I get this error:
error LNK2019: unresolved external symbol MessageBoxW referenced 
in function WinMain


I have to manually specify User32.Lib to dmd when I want to 
compile my program (or move User32.Lib to my project directory).


Is this normal?

Below is my sc.ini.

[Environment]
LIB=%DIR_WINSDK%\Lib\x64;%DIR_MSVC%\lib\amd64;%@P%\..\lib
DFLAGS=-I%@P%\..\..\src\phobos 
-I%@P%\..\..\src\druntime\import -m64

LINKCMD=%@P%\link.exe
LINKCMD64=%DIR_MSVC%\bin\amd64\link.exe

Obviously User32.Lib resides in %DIR_WINSDK%\Lib\x64. This 
directory resolves correctly in windows explorer to C:\Program 
Files\Microsoft SDKs\Windows\v7.1\Lib\x64


Re: Can't compile on 64 bit Windows

2013-10-18 Thread Erik van Velzen

(late I know but it may help someone)

The linker is trying to link against x86 libraries instead of x64.

If you followed the tutorial to the letter, you need to check if 
%DEV_DIR_WINSDK%\Lib\x64 resolves correctly (paste in cmd or 
windows explorer).