Re: bug? for(int i=0;i<1;) vs while(true)
thank you :) works now
[Code Example for Beginners (like me)] Sockets with Fibers
hello! yesterday i got curious about how fibers work, and if the can be used as a replacement in network programming. so i started hacking a small example together, which is hopefully useful to other D beginners too :) http://pastebin.com/Xg4GJbKE
bug? for(int i=0;i<1;) vs while(true)
http://pastebin.com/fknwgjtz i tried to call fibers in a loop forever, to multiplex some networking client worker fibers and a listener fiber it seems to work correctly with for(int i=0;i<1;) with while(true) i get: C:\dev\server_client>dub Building server_client ~master configuration "application", build type debug. Compiling using dmd... source\app.d(72): Warning: statement is not reachable FAIL .dub\build\application-debug-windows-x86-dmd_2068-32A80D3C074EAD350DDE74DB2 61C6BB5\ server_client executable Error executing command run: dmd failed with exit code 1.
Re: bug? for(int i=0;i<1;) vs while(true)
using DMD32 D Compiler v2.068.0 on windows x64
Re: bug? for(int i=0;i<1;) vs while(true)
On Thursday, 17 September 2015 at 19:43:02 UTC, H. S. Teoh wrote: On Thu, Sep 17, 2015 at 07:32:13PM +, ddos via Digitalmars-d-learn wrote: http://pastebin.com/fknwgjtz i tried to call fibers in a loop forever, to multiplex some networking client worker fibers and a listener fiber it seems to work correctly with for(int i=0;i<1;) with while(true) i get: C:\dev\server_client>dub Building server_client ~master configuration "application", build type debug. Compiling using dmd... source\app.d(72): Warning: statement is not reachable FAIL .dub\build\application-debug-windows-x86-dmd_2068-32A80D3C074EAD350DDE74DB2 61C6BB5\ server_client executable Error executing command run: dmd failed with exit code 1. Maybe just write: for (;;) { ... } instead? You can read `(;;)` as "ever". :-P Also, could you post a (possibly reduced) code example that can be compiled? It's kinda hard to figure out what's wrong when the code in the paste is incomplete. T yeah i tried for(;;) and it generates the same warning :) sure, here is the full example, it's not too long anyways ( the example doesn't make much sense tho because socket.accept is blocking :P ) http://pastebin.com/9K0wRRD6 ps: pastebin needs D support :-D
Re: bug? for(int i=0;i<1;) vs while(true)
On Thursday, 17 September 2015 at 19:35:05 UTC, Adam D. Ruppe wrote: What's there? Anything after an endless loop is potentially unreachable and dub treats warnings as errors. i see, thx
Thrift
Looking for a RPC library, thrift looked promising, but i can't even compile the simple example given here https://thrift.apache.org/tutorial/d to compile i've 1. copied the thrift/lib/d/src/thrift folder to my source directory 2. copied the generated sources ( tutorial and share folder ) into my source directory 3. compiling with dub and dmd 66 ( ive also tried 68 before with the same result ) dub.json: http://pastebin.com/pQSsCUAd compiling errors: http://pastebin.com/qp02S1EW please help if you know how to get a simple example with d & thrift running thx, dominik
How do i sanitize a string for database query?
How do i sanitize a string for database query? Is there some builtin function? thx :)
Re: How do i sanitize a string for database query?
thx
Re: How do i sanitize a string for database query?
On Tuesday, 21 July 2015 at 17:58:55 UTC, Gary Willoughby wrote: On Tuesday, 21 July 2015 at 17:23:30 UTC, ddos wrote: How do i sanitize a string for database query? Is there some builtin function? thx :) Use prepared statements instead. https://en.wikipedia.org/wiki/Prepared_statement thx for reminding me of prepared statements this is ok for preventing an sql injection i guess, but still my insert would fail. maybe i should have specified what i want to achieve: i have a plugin for a call of duty gameserver, this plugin is able to ban players from the server by inserting name/ip/etc.. into a sql database. it is priority that the insert never fails. e.g. name could contain a ' which lets my insert fail.
Re: function shadowed
On Thursday, 9 April 2015 at 05:34:09 UTC, anonymous wrote: On Wednesday, 8 April 2015 at 22:53:39 UTC, ddos wrote: why not just make it callable without the alias? It's to prevent hijacking: http://dlang.org/hijack.html thx for the article!
function shadowed
i got two modules opengvg.d and vg.d vg.d contains calls to external c functions openvg.d should wrap and simplify some of those calls in openvg.d i make public import of submodule vg.d such that if openvg.d is imported the functions in vg.d can be called, this works as intended. but as soon as i overload a function from vg.d in openvg.d i can only call the function in openvg.d example: vg.d: module vg; extern (C) void vgSetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat *values); openvg.d module openvg; public import vg; void vgSetParameterfv(VGHandle object, VGint paramType, const(VGfloat[]) values) { vg.vgSetParameterfv(object, paramType, cast(int)values.length, cast(VGfloat*)values); } test.d import openvg; vgSetParameterfv(object, paramType, length, values); // call to fun in vg.d how can i call both functions? i'd like to avoid using the module prefix vg.vgSetParameterfv if possible source: https://github.com/oggs91/OpenVG_D/blob/master/openvg/
Re: function shadowed
On Wednesday, 8 April 2015 at 17:48:36 UTC, anonymous wrote: On Wednesday, 8 April 2015 at 12:05:00 UTC, ddos wrote: vg.d: module vg; extern (C) void vgSetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat *values); openvg.d module openvg; public import vg; void vgSetParameterfv(VGHandle object, VGint paramType, const(VGfloat[]) values) { vg.vgSetParameterfv(object, paramType, cast(int)values.length, cast(VGfloat*)values); } test.d import openvg; vgSetParameterfv(object, paramType, length, values); // call to fun in vg.d how can i call both functions? i'd like to avoid using the module prefix vg.vgSetParameterfv if possible Add to openvg: alias vgSetParameterfv = vg.vgSetParameterfv; thx that works, but why is it even necessary? same behavior when overriding methods of base classes class Matrix(T) { abstract const(T) opIndexAssign(const(T) val, int row, int col); Matrix!T opIndexAssign(T val, Tuple!(int,int) idx0, Tuple!(int,int) idx1) { ... } } class DenseMatrix(T) : Matrix!(T) { override const(T) opIndexAssign(const(T) val, int row, int col) { ... } alias opIndexAssign = Matrix!T.opIndexAssign; } why not just make it callable without the alias?
Re: Troubles with devisualization/window
On Monday, 6 April 2015 at 22:56:15 UTC, Rikki Cattermole wrote: On 7/04/2015 10:34 a.m., ddos wrote: it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d Ohhh right, call swapBuffers on the context after drawing. Probably be in the run loop (while). thanks a lot, problems fixed now, i've missing your test example :) if anyone else has problems - this works https://github.com/Devisualization/window/blob/master/test/main.d to get the vector graphics working i had to make a small change in the pixelformatdescriptor https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/context/opengl.d PIXELFORMATDESCRIPTOR, changed stencil buffer bits from 0 to 8 you may want to change this to default 8 to avoid problems. http://imgur.com/ME4b6ZO
Re: Troubles with devisualization/window
it's getting warmer, window doesnt freeze anymore and opengl calls don't crash the window, but it's still all white after calling glClearColor(1,0,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updated src: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d
Troubles with devisualization/window
Hi! i'm trying to get devisualization/window [1] working with some simple opengl calls. I have created a windows with opengl context using Window window = new Window(800, 600, My window!w, WindowContextType.Opengl); If i run writeln(type: , context.type); writeln(toolkit version: , context.toolkitVersion); writeln(shading language version: , context.shadingLanguageVersion); i get correct information has context type: Opengl toolkit version: 4.5.0 NVIDIA 347.09 shading language version: 4.50 NVIDIA First i tried to simply call glClearColor(1,0,0,1);, this crashes the application (Program exited with code -1073741819) I checked the function pointer with if(cast(void*)glClearColor !is null){...} and well ... it's a nullpointer the first two frames. Then i checked for nullpointer and called glClearColor(...) and glClear(...) - no crash but the window was just frozen. Does anyone use Devisualization/window on Windows with success? Fyi, if i dont do any opengl calls the window seems to work, i can close it normally, it's completely white. My example sourcecode can be found here: https://github.com/oggs91/OpenVG_D/blob/master/demo_DvisualizationWT/source/app.d [1] https://github.com/Devisualization/window
Re: How to generate D binding with SWIG?
On Monday, 6 April 2015 at 15:46:32 UTC, Jeremy DeHaan wrote: Do you even need to use swig? It looks like gdal has a C interface. I think that htod would be what you're looking for http://dlang.org/htod.html +1 for htod if there is a c interface!
linking C library with D, creating a OpenVG D port
hi! i'm trying to run OpenVG examples in D. So far i have compiled ShivaVG (an implementation of OpenVG standard) in C++ and created a shared library. Now i'd like to link my OpenVG.lib with a D program. (the library was compiled with msvc2013x86, i'd like to avoid switching compiler) to link the library i added my C++ lib to my dub file, libs: [OpenVG], dmd complains: Error 43: Not a Valid Library File after some googling i found out i have to convert/create my lib file in the appropriate format to be used with dmd, so i used implib to create a new lib from my dll. viewing this lib no exports are visible with dumpbin, dumpbin /EXPORTS OpenVG_D.lib also reports a warning: OpenVG_D.lib : warning LNK4048: Invalid format file; ignored maybe i have to use another tool here to view the exports? but dumpbin can view pe and coff, dmd uses coff i think so this should work i guess if i try to compile my application it now tells me about the obviously missing export, Error 42: Symbol Undefined _vgCreateContextS
Re: linking C library with D, creating a OpenVG D port
progress ... i think in some forum posts i've read 64bit dmd uses a differnt linker which supports coff atleast i can now link my app in 64bit mode without errors dmd -m64 source/app.d OpenVG.lib also an exported test function prints to stdout, so my problem is solved for x64 :) if anyone could explain how this could be done with 32bit builds i'd appreciate it why does dmd use different linkers for 32 and 64bit anyway?
Re: linking C library with D, creating a OpenVG D port
thanks Rikki! also if anyone is interested in OpenVG i have now a running demo in D based on ShivaVG and derelict GLFW3, it's not beautiful but it works :D http://imgur.com/ZH0kD0q i'm pretty impressed how painless the compiling and interfacing to C was actually :) +1 for D
Re: Compilation with dub + dmd: out of memory
On Tuesday, 10 February 2015 at 12:18:15 UTC, Vlasov Roman wrote: On Tuesday, 10 February 2015 at 11:55:43 UTC, Daniel Kozák wrote: V Tue, 10 Feb 2015 11:44:09 + Vlasov Roman via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: On Tuesday, 10 February 2015 at 11:32:32 UTC, bearophile wrote: Vlasov Roman: I have the quite computer with 2 GB RAM. At compilation with dub and dmd of small project this pair eating about 1.4~1.5 GB RAM. I solve this probleb by connecting swap partition, but it calls some freezes + it take ~10% of swap, and after compilation swap not released. At switching off swap as result we get ~200 MB of dead data in RAM, which can be released by rebooting. How i can resolve it? Look for CTFE code, perhaps some of it is excessive. You can convert some of it to run-time in a module-level static this(). Bye, bearophile I think you don't understand me. 1.4~1.5 GB taked by compilator at compilation my project in 100 string of code in 3 modules. Still it could be code dependent, can you share your code anywhere? https://bitbucket.org/VlasovRoman/ogl/overview a bit offtopic from your thread but maybe you are interested ... at vienna university of technology i attended a similar software rendering course, some resources are publicly available (and in english) https://lva.cg.tuwien.ac.at/ecg/wiki/doku.php some impressions from previous years entries: https://lva.cg.tuwien.ac.at/ecg/wiki/doku.php?id=students:ws2013:hall_of_fame
Re: generate an array of 100 uniform distributed numbers
thx, alot :) works as intended iota(0,100).map!(v = uniform(0.0,1.0)).writeln;
generate an array of 100 uniform distributed numbers
hi guys, firstly this has no direct application, i'm just playing around and learning i want to create 100 uniform distributed numbers and print them my first attempt, just written by intuition: [0 .. 100].map!(v = uniform(0.0, 1.0).writeln); i found out i can't write [0 .. 100] to define a simple number range, but is there a function to do so? second attempt, replacing the range with an simple array [0,1,2].map!(v = uniform(0.0,1.0).writeln); this does compile and run, but doesn't print anything, just an empty string, why is that? finally i got it working with this: auto t = [0,1,2].map!(v = uniform(0.0,1.0)); writeln(t); seems pretty easy eh? d is bugging me alot like this ^_^ but i love it's syntax
histogram [last thread contd]
i wrote a histogram algorithm i tried to write it the shortest and most D way possible ... please tell me if you see any simpler way of doing it is there a simpler way of getting the minimum of a range? (by intuition i tried range.min) auto numbers = iota(0,1).map!(_ = uniform(0.0,1.0)).array; auto nmin = numbers.reduce!((a,b) = min(a,b)); auto nmax = numbers.reduce!((a,b) = max(a,b)) + double.epsilon; int bins = 100; auto bin = iota!float(0, bins).map!(a = tuple((nmax-nmin)/bins*a+nmin, (nmax-nmin)/bins*(a+1)+nmin)); auto bincount = bin.map!(a = numbers.map!(b = b = a[0] b a[1] ? 1 : 0).sum); bincount.writeln;
Trouble with std.Variant
struct Vec2 { float[2] vec; public float length() { return sqrt(vec[0]*vec[0]+vec[1]*vec[1]); } } int main(string[] argv) { Vec2 test; Variant v = test; return 0; }
Re: Trouble with std.Variant
The following code fails because Vec2.length() does not return int ... so Variant is only usable with types that do not have a method with name length() ?? i'm confused On Thursday, 18 September 2014 at 21:03:47 UTC, ddos wrote: struct Vec2 { float[2] vec; public float length() { return sqrt(vec[0]*vec[0]+vec[1]*vec[1]); } } int main(string[] argv) { Vec2 test; Variant v = test; return 0; }
iterate traits ?
Hi, i'm trying to create a dynamic vertex format for opengl, defined at compiletime by a struct e.g. struct Vertex {float[3] position, float[3] normal} i can get the name of all members with this: auto b = [ __traits(allMembers, VertexType) ]; but i can't iterate them at compiletime because there is no static foreach? foreach(e; b) { alias tt = typeof(__traits(getMember, VertexType, e)); // not working writeln(tt.sizeof); } since i need to setup vertexpointers for opengl at runtime my next question? - is it possible to evaluate the traits also at runtime? but i'd also like to know how i can iterate them at compiletime thx in advance :)
Re: iterate traits ?
On Tuesday, 19 August 2014 at 18:25:24 UTC, Justin Whear wrote: On Tue, 19 Aug 2014 18:15:33 +, ddos wrote: since i need to setup vertexpointers for opengl at runtime my next question? - is it possible to evaluate the traits also at runtime? but i'd also like to know how i can iterate them at compiletime thx in advance :) Take a look at this example: http://dpaste.dzfl.pl/2fdea78a49b6 A foreach becomes compile-time whenever the aggregate is a purely compile- time construct such as a tuple. thank you!
static array in templated struct/class
alias Vec4f = TVector!(float,4); alias Vec3f = TVector!(float,3); class TVector(T,int n) { T[n] val; ... TVector as class does work as expected, as a struct i get the following errors, but why? struct Vector.TVector!(float, 4).TVector no size yet for forward reference struct Vector.TVector!(float, 3).TVector no size yet for forward reference
Re: static array in templated struct/class
On Tuesday, 5 August 2014 at 19:13:31 UTC, Marc Schütz wrote: On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote: alias Vec4f = TVector!(float,4); alias Vec3f = TVector!(float,3); class TVector(T,int n) { T[n] val; ... TVector as class does work as expected, as a struct i get the following errors, but why? struct Vector.TVector!(float, 4).TVector no size yet for forward reference struct Vector.TVector!(float, 3).TVector no size yet for forward reference Can you show the complete code? I cannot reproduce this with either latest DMD git, DMD 2.065, or LDC 0.13.0: alias Vec4f = TVector!(float,4); alias Vec3f = TVector!(float,3); struct TVector(T,int n) { T[n] val; } Vec3f a; Vec4f b; http://pastebin.com/34sbffSa thx for your help :) ! i use DMD 2.065 btw
Re: static array in templated struct/class
i wasn't intentionally creating a functionpointer, i just liked the syntax x3 ... but i guess i should read into it now :) thx for you help ! On Tuesday, 5 August 2014 at 19:51:33 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: http://pastebin.com/34sbffSa Your problem comes from lengthSquared: public auto lengthSquared = function () = val.reduce!((a,b) = a + b*b); That's an unusual way to define a method. Any reason why you are using a pointer to a function as a member? Do you need to be able to redefine it at runtime? I guess that in this case, the compiler cannot determine its return type and/or its size? I'd use: public auto lengthSquared () { return val.reduce!((a,b) = a + b*b);}
range foreach lambda
for example i have an array int[] a = [1,2,3,4,5]; and a function auto twice = function (int x) = x * 2; how can i apply the function to each element in a without using a forloop? - is there a function to do this? a.foreach(x = x * 2); a == [2,4,6,8,10]
Re: range foreach lambda
thx alot! its not important to me that the function is not evaluated in place since you gave me such a straight answer i'd like to bother you with another question :) for example i have now two ranges: immutable a = [1,2,3,4]; immutable b = [2,3,4,5]; how do i add the elements in a and b elementwise in a functional style? a+b == [3,5,7,9] usually i'd do something like this: int[4] o; for(int i=0;i4;i++) { o[i] = a[i] + b[i]; }
templates
for example and learning purpose i want to create an arithmetic vector class. for a vector of arbitrary size i defined my opBinary like this: class TVector(T,int n) { T[n] val; . TVector opBinary(string op)(TVector rhs) { auto tmp = zip(val[],rhs.val[]).map!(a[0]~op~a[1])().array; T[n] v = tmp[]; return new TVector!(T,n)(v); } } now assume i do often need TVector!(T,4) in my program, and i want to optimize this implementation, is it possible to write a specialized implementation for methods of TVectors with the specific template parameters? e.g.: (not working) class TVector!(T,4) { TVector4!(T) opBinary(string op)(TVector4!(T) rhs) { static if (op == +) { return new TVector4!T( [val[0]+rhs.val[0], val[1]+rhs.val[1], val[2]+rhs.val[2], val[3]+rhs.val[3]]); } else static assert(0, Operator ~op~ not implemented); } } one possible solution would be a static if, like this: TVector opBinary(string op)(TVector rhs) { static if(n == 4) { // fast impl for n==4 } else { // old impl } } but i'd like to avoid this since it makes the code very ugly to read any suggestions :) ? thx for your help, greetings from vienna, austria :)