Re: I want to introduce boost_asio to dlang
On Thursday, 5 March 2015 at 07:38:35 UTC, ketmar wrote: On Thu, 05 Mar 2015 06:05:55 +, zhmt wrote: But I am not familiar with dlang this is the root of the problem. please, make yourself familiar before starting to wrap boost crap. Unwarranted tone imo. Let's play nice.
Derelict Assimp not loading mesh properly? (Maybe index buffer)
I wrote a custom OBJ file importer which worked fairly well however was not robust enough to support everything. I've decided to give AssImp a shot. I followed some tutorials and have set up my code to read in the vertices, tex coords, normals, and indices of an OBJ cube model that I have had success loading with my custom importer. The cube model's faces do not render properly, instead only rendering a few tri's of the cube. The way AssImp handles the data is obviously a bit different than my solution because the normals, positions/vertices, tex coords, and indices do not match my custom solution. I would very much appreciate some insight into why I'm having issues as all of the tutorials I've found have matched my approach. If a picture of the faulty rendered cube would be helpful I can work on getting a screenshot up. Thank you. My Asset importing class is at: http://codebin.org/view/4d2ec4d3 The rest of my code is at (Mesh Class is in source/graphics): https://github.com/BennetLeff/PhySim
Re: I want to introduce boost_asio to dlang
Thanks for all the suggestions and pointing the right direction,I will learn and try vibe.d, try to use it in my gameserver.
Re: Int to float?
On Thursday, 5 March 2015 at 23:50:28 UTC, Jesse Phillips wrote: I think I read somewhere you don't want to use unions like this, but I think it is more because you generally don't want to reinterpret bits. It is non-portable, since some hardware architectures may use different representations (e.g. different byte order on int and float). D claims to follow C, so using unions for type punning is ultimately implementation defined. In C++ using unions for type punning is illegal/undefined behaviour, so in C++ you should use memcpy. Memcpy also has the advantage of explicitly copying thus avoiding some aliasing issues.
Re: how to write a string to a c pointer?
On 03/05/2015 03:25 PM, ketmar wrote: unicode sux[1]. [1] http://file.bestmx.net/ee/articles/uni_vs_code.pdf Thanks. I enjoyed the article and I agree with everything said in there. It made me happy that I was not the only person who has been ruminating over "alphabet" as the crucial piece in this whole Unicode story. I've been giving the example of if I have a company name as the string "ali & jim", the uppercase of it should be "ALİ & JIM" because the different letter 'i's belong to different alphabets. Anyway... Here is how I attempted to define an alphabet with its implied collation orders. For example, for the Turkish alphabet: https://code.google.com/p/trileri/source/browse/trunk/tr/alfabe.d#796 Unfortunately, the code itself is in Turkish, has never been finished, bad and older D code, and is abandoned at this point. :-/ Ali
Re: Int to float?
On Thursday, 5 March 2015 at 20:06:55 UTC, Taylor Hillegeist wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); ahh of course! lol :) I think I read somewhere you don't want to use unions like this, but I think it is more because you generally don't want to reinterpret bits. import std.stdio; void main() { union Fi { float f; int i; } Fi fi; fi.i = 65; writeln(fi.f); }
Re: how to write a string to a c pointer?
On Thu, 05 Mar 2015 16:36:35 +0100, FG wrote: > Damn those composite characters! or invisible ones. or RTL switch. unicode sux[1]. [1] http://file.bestmx.net/ee/articles/uni_vs_code.pdf signature.asc Description: PGP signature
Is std.signals deprecated?
Seems barely maintained and there was a proposed replacement claiming it was broken(http://wiki.dlang.org/Review/std.signal) that never got approved. Is std.signals worth using over a dub package?
Re: Int to float?
On Thursday, 5 March 2015 at 20:32:20 UTC, anonymous wrote: That's not really simpler, though. Maybe, but I think the union is a bit nicer because then the compiler is responsible for more of the details. For example, it should work with class objects without the complication of dealing with the fact that they are already pointers under the hood. Either way works though and should compile to the same instructions, just if I was doing it as a generic library, I think I'd use the union method.
Re: Int to float?
On Thursday, 5 March 2015 at 20:21:18 UTC, badlink wrote: On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); The cast(void*) isn't necessary. Actually even the cast is unecessary, just use a uniform. union N { int i; float f; } http://dpaste.dzfl.pl/58b6eddcf725 That's not really simpler, though.
Re: Object as function argument
On Thursday, 5 March 2015 at 19:51:09 UTC, Max Klyga wrote: If you really need the actual pointer to object data you can use `*cast(void**)&myObject`. Compiler cannot cast object reference to `void*` but we can trick it ;) It can, actually. A class can define its own cast(void*) though, so the reinterpret way may be more robust. Also, I'm not sure if any of this is specified. So watch out for undefined (or underspecified) behaviour.
Re: Int to float?
On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); The cast(void*) isn't necessary. Actually even the cast is unecessary, just use a uniform. union N { int i; float f; } http://dpaste.dzfl.pl/58b6eddcf725
Re: Int to float?
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); The cast(void*) isn't necessary.
Re: Object as function argument
On Thursday, 5 March 2015 at 20:08:08 UTC, Chris Sperandio wrote: Is it clean to write this code below ? yup. Though remember all the downsides of null - if you try to use a null object like accessing a member, the program will be terminated.
Re: Object as function argument
Ok... So, in D when I work with Object, it's like if I work with only pointers. Thus, I can return null from a function which returns an Item instance. Is it clean to write this code below ? static Item nullReturn(Item item) { // ... // and for some cases return null; }
Re: Int to float?
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); ahh of course! lol :)
Int to float?
How to I cast a Int to float without changing its binary representation?
Re: Int to float?
Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue);
Re: Object as function argument
On Thursday, March 05, 2015 19:35:34 Chris Sperandio via Digitalmars-d-learn wrote: > Hi, > > I'm a developer coming from C and I've a question about class > instance as method or function parameter. > In the book "The D Programming Language", I read the instance was > passed by reference to functions (in the opposite of structures). > I understood that it was the same object in the function and the > caller. But I'm think, I was wrong because when I print the > addresses of an object before the function call and inside the > function, they're not the same but the changes from the function > are kept in the instance. > If I use the "ref" qualifier in the function declaration, the 2 > addresses are the same. > > How do the changes work in the function? Is there a copy ? Or a > "magic" trick :) ? MyClass c; is a reference to an object. So, if you do &c, you're taking the address of the reference, not the object. So, it's like if you had MyClass* c; in C/C++ and you did &c. So, if you have void bar() { auto c1 = new MyClass; foo(c1); } void foo(MyClass c2) { } then c1 and c2 have different addresses just like if they would if they were explictly pointers. Changing foo to void foo(ref MyClass c2) { } means that you're passing the reference itself by ref, making it essentially equivalent to void foo(MyClass*& c2) { } in C++. So, c2's address is going to be the same as c1, because they're essentially the same reference/pointer at that point. If you want the address of the object itself rather than its reference, then you need to cast it to void*. e.g. this code will print the same value for c1 and c2: import std.stdio; class MyClass {} void main() { auto c1 = new MyClass; writeln(cast(void*)c1); foo(c1); } void foo(MyClass c2) { writeln(cast(void*)c2); } - Jonathan M Davis
Re: Object as function argument
Below the code: module item; import std.stdio; class Item { ulong count; static void call1(Item item) { writeln("(call1) Addr: ", &item); } static void call2(ref Item item) { writeln("(call2) Addr: ", &item); } static Item call3(Item item) { writeln("(call3) Addr: ", &item); return item; } static Item call4(Item item) { // Here, I change the count item.count = 100; return item; } } void main() { auto item = new Item(); writeln("(main) Addr item=", &item); Item.call1(item); Item.call2(item); auto res3 = Item.call3(item); writeln("(main) res3 item=", &res3); auto res4 = Item.call4(item); writeln("(main) res4 item=", &res4); assert(item.count == 100); } I get: (main) Addr item=7FFF5D797818 (call1) Addr: 7FFF5D7977F8 (call2) Addr: 7FFF5D797818 (call3) Addr: 7FFF5D7977F8 (main) res3 item=7FFF5D797820 (main) res4 item=7FFF5D797828 On Thursday, 5 March 2015 at 19:48:38 UTC, w0rp wrote: On Thursday, 5 March 2015 at 19:35:35 UTC, Chris Sperandio wrote: Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of structures). I understood that it was the same object in the function and the caller. But I'm think, I was wrong because when I print the addresses of an object before the function call and inside the function, they're not the same but the changes from the function are kept in the instance. If I use the "ref" qualifier in the function declaration, the 2 addresses are the same. How do the changes work in the function? Is there a copy ? Or a "magic" trick :) ? Chris If you share your code, I'll be happy to take a look. Classes are reference types, so passing T for a class should pass the reference to the object.
Re: Object as function argument
On 2015-03-05 19:35:34 +, Chris Sperandio said: Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of structures). I understood that it was the same object in the function and the caller. But I'm think, I was wrong because when I print the addresses of an object before the function call and inside the function, they're not the same but the changes from the function are kept in the instance. If I use the "ref" qualifier in the function declaration, the 2 addresses are the same. How do the changes work in the function? Is there a copy ? Or a "magic" trick :) ? Chris When you write `auto myObject = new MyObject();` `myObject` is actually a pointer to object in GC memory. Its roughly equivalent to `struct MyObject *myobject` in C. So when you take a pointer you actually take a pointer to reference on the stack and thats why its different in the function - variable is higher up the stack. `ref` qualifyer guaranties that you get the pointer to the same reference. If you really need the actual pointer to object data you can use `*cast(void**)&myObject`. Compiler cannot cast object reference to `void*` but we can trick it ;)
Re: Object as function argument
On Thursday, 5 March 2015 at 19:35:35 UTC, Chris Sperandio wrote: Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of structures). I understood that it was the same object in the function and the caller. But I'm think, I was wrong because when I print the addresses of an object before the function call and inside the function, they're not the same but the changes from the function are kept in the instance. If I use the "ref" qualifier in the function declaration, the 2 addresses are the same. How do the changes work in the function? Is there a copy ? Or a "magic" trick :) ? Chris If you share your code, I'll be happy to take a look. Classes are reference types, so passing T for a class should pass the reference to the object.
Object as function argument
Hi, I'm a developer coming from C and I've a question about class instance as method or function parameter. In the book "The D Programming Language", I read the instance was passed by reference to functions (in the opposite of structures). I understood that it was the same object in the function and the caller. But I'm think, I was wrong because when I print the addresses of an object before the function call and inside the function, they're not the same but the changes from the function are kept in the instance. If I use the "ref" qualifier in the function declaration, the 2 addresses are the same. How do the changes work in the function? Is there a copy ? Or a "magic" trick :) ? Chris
Re: Getting the socket information from HTTP and DNS sessions
On 03/04/2015 11:46 PM, Kadir Erdem Demir wrote: I have been ask to write a test tool which initiates DNS-HTTP-HTTPS-TCP sessions. And ofcourse I wrote this with D. For HTTP I used std.net like "m_HTTP = HTTP(m_url);m_HTTP.perform();" For DNS I simply used "getAddressInfo(m_domainName);" Than tool makes some simple checks which are npt subjects of this thread and the tool works well, But now I need to make an improvement. I need to get sourceIP(ip which program runs), sourcePort( eg: 53212 not 80), destIP, destPort(most probably 80) from the session which I initiated. I need functions like std.socket.localAddress, std.socket.remoteAddress for HTTP-DNS but couldn't managed to find them. Is there any way that I can get socket info in HTTP and DNS sessions which I initiated? Regards Kadir Erdem std.net is implemented in terms of libcurl but does not expose all of its functionality. I could not find a way of extracting curl-related information from it. I found the following Socket example in my stash of code where it's easy to get the address information with remoteAddress() and localAddress(). But of course Socket is lower level than std.net. :-/ import std.stdio; import std.socket; void main() { Socket server = new TcpSocket(); server.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, true); server.bind(new InternetAddress(8080)); server.listen(1); while(true) { Socket client = server.accept(); writefln("client Socket connected on %s", client.remoteAddress); char[1024] buffer; auto received = client.receive(buffer); writefln("The client said:\n%s", buffer[0.. received]); enum header = "HTTP/1.0 200 OK\nContent-Type: text/html; charset=utf-8\n\n"; string response = header ~ "Hello World!\n"; client.send(response); client.shutdown(SocketShutdown.BOTH); client.close(); } } Ali
Re: how to write a string to a c pointer?
On 2015-03-05 at 15:18, Kagamin wrote: On Thursday, 5 March 2015 at 13:57:45 UTC, FG wrote: void main() { string s = "ąćęłńóśźż"; Try with string s = "ąc\u0301ęłńóśźż"; Yeah, I see your point: ą, ąc (missing diacritic), ąć, ąćę, ... Damn those composite characters!
Re: how to write a string to a c pointer?
On Thursday, 5 March 2015 at 13:57:45 UTC, FG wrote: void main() { string s = "ąćęłńóśźż"; Try with string s = "ąc\u0301ęłńóśźż";
Re: how to write a string to a c pointer?
On 2015-03-05 at 10:42, Kagamin wrote: string s; char[] b = cast(char[])asArray(); b[0..s.length] = s[]; It's a bit more complicated than that if you include cutting string for buffers with smaller capacity, doing so respecting UTF-8, and adding a '\0' sentinel, since you may want to use the string in C (if I assume correctly). The setString function does all that: import std.stdio, std.range, std.c.stdlib; class Buffer { private void *ptr; private int size; private int _cap; public this(int cap) { ptr = malloc(cap); this._cap = cap; } public ~this() { free(ptr); } public ubyte[] asArray() { ubyte[] ret = (cast(ubyte*)ptr)[0..cap]; return ret; } public void* getPtr() { return ptr; } public int cap() { return _cap; } } int setString(Buffer buffer, string s) { assert(buffer.cap > 0); char[] b = cast(char[])buffer.asArray(); int len = min(s.length, buffer.cap - 1); int break_at; // The dchar is essential in walking over UTF-8 code points. // break_at will hold the last position at which the string can be cleanly cut foreach (int i, dchar v; s) { if (i == len) { break_at = i; break; } if (i > len) break; break_at = i; } len = break_at; b[0..len] = s[0..len]; // add a sentinel if you want to use the string in C b[len] = '\0'; // you could at this point set buffer.size to len in order to use the string in D return len; } void main() { string s = "ąćęłńóśźż"; foreach (i; 1..24) { Buffer buffer = new Buffer(i); int len = setString(buffer, s); printf("bufsize %2d -- strlen %2d -- %s --\n", i, len, buffer.getPtr); } } Output of the program: bufsize 1 -- strlen 0 -- -- bufsize 2 -- strlen 0 -- -- bufsize 3 -- strlen 2 -- ą -- bufsize 4 -- strlen 2 -- ą -- bufsize 5 -- strlen 4 -- ąć -- bufsize 6 -- strlen 4 -- ąć -- bufsize 7 -- strlen 6 -- ąćę -- bufsize 8 -- strlen 6 -- ąćę -- bufsize 9 -- strlen 8 -- ąćęł -- bufsize 10 -- strlen 8 -- ąćęł -- bufsize 11 -- strlen 10 -- ąćęłń -- bufsize 12 -- strlen 10 -- ąćęłń -- bufsize 13 -- strlen 12 -- ąćęłńó -- bufsize 14 -- strlen 12 -- ąćęłńó -- bufsize 15 -- strlen 14 -- ąćęłńóś -- bufsize 16 -- strlen 14 -- ąćęłńóś -- bufsize 17 -- strlen 16 -- ąćęłńóśź -- bufsize 18 -- strlen 16 -- ąćęłńóśź -- bufsize 19 -- strlen 16 -- ąćęłńóśź -- bufsize 20 -- strlen 16 -- ąćęłńóśź -- bufsize 21 -- strlen 16 -- ąćęłńóśź -- bufsize 22 -- strlen 16 -- ąćęłńóśź -- bufsize 23 -- strlen 16 -- ąćęłńóśź --
Re: I want to introduce boost_asio to dlang
On Thursday, 5 March 2015 at 09:38:27 UTC, zhmt wrote: On Thursday, 5 March 2015 at 08:22:33 UTC, Jack Applegame wrote: On Thursday, 5 March 2015 at 06:05:56 UTC, zhmt wrote: I am a gameserver developer, my programming lang is java now. I want to change java to dlang, and I like boost_asio and it's coroutine, so, I want to create a binding of boost_asio. But I am not familiar with dlang, so I want to find someone help me, or develope this binding with me. I will put the asio binding on github, and opensource, and free. Anybody help or join? There is no need to do it. Just use http://vibed.org/ instead of boost::asio. It sounds like a good choice, is it as good as boost::asio? Having used both, it's better. Atila
Re: I want to introduce boost_asio to dlang
On Thu, 05 Mar 2015 07:46:04 +, zhmt wrote: > I have studied for half a year, so I want to learn it in work, > in solving problems. that's a good way to learn. but starting from writing wrappers for something is not a good way. ;-) if you want a wrapper for something, it's always better to ask if D needs it at all. i.e. the proper question is something like: "i want to do async I/O in the spirit of boost::asio, are there any libraries for D that does such thing?" and you will immideately be pointed at vibe.d. ;-) signature.asc Description: PGP signature
Re: I want to introduce boost_asio to dlang
On Thu, 05 Mar 2015 09:38:25 +, zhmt wrote: >> There is no need to do it. Just use http://vibed.org/ instead of >> boost::asio. > It sounds like a good choice, is it as good as boost::asio? no. it's alot better. signature.asc Description: PGP signature
Re: how to write a string to a c pointer?
On Thursday, 5 March 2015 at 09:42:53 UTC, Kagamin wrote: string s; char[] b = cast(char[])asArray(); b[0..s.length] = s[]; Thank you very much. I should stop my developing , and read the dlang tutorial again.
Re: how to write a string to a c pointer?
string s; char[] b = cast(char[])asArray(); b[0..s.length] = s[];
Re: I want to introduce boost_asio to dlang
On Thursday, 5 March 2015 at 08:22:33 UTC, Jack Applegame wrote: On Thursday, 5 March 2015 at 06:05:56 UTC, zhmt wrote: I am a gameserver developer, my programming lang is java now. I want to change java to dlang, and I like boost_asio and it's coroutine, so, I want to create a binding of boost_asio. But I am not familiar with dlang, so I want to find someone help me, or develope this binding with me. I will put the asio binding on github, and opensource, and free. Anybody help or join? There is no need to do it. Just use http://vibed.org/ instead of boost::asio. It sounds like a good choice, is it as good as boost::asio?
Re: I want to introduce boost_asio to dlang
On Thursday, 5 March 2015 at 06:05:56 UTC, zhmt wrote: I am a gameserver developer, my programming lang is java now. I want to change java to dlang, and I like boost_asio and it's coroutine, so, I want to create a binding of boost_asio. But I am not familiar with dlang, so I want to find someone help me, or develope this binding with me. I will put the asio binding on github, and opensource, and free. Anybody help or join? There is no need to do it. Just use http://vibed.org/ instead of boost::asio.