Re: Proper C Pointer Binding

2014-03-26 Thread ralex
On Wednesday, 26 March 2014 at 09:51:04 UTC, Róbert László Páli 
wrote:

I am programming a new GUI widget library based on OpenGL for D.
For that I manually bind the used OpenGL functions to D and 
create

an abstraction layer to draw things, boxes, texts, shapes, etc.

http://palaes.rudanium.org/HueApp/intro.php

The thing compiles nicely with SDL, FreeType, FTGL. But
for the text drawing I use some pretty lame binding currently.
It is a fresh part of the code and want to do it properly:

C Code:

unsigned long loadFont(char * path) {
  FTGLfont * font = FTGLloadFont(path);
  return (unsigned long) font;
}

void drawText(unsigned long font, unsigned size, char * text) {
  // do the text drawing here
}

void destroyFont(unsigned long font) {
  FTGLdestroyFont((FTGLfont * ) font);
}

D Code:

extern (C) ulong loadFont(char * path);

extern (C) void destroyFont(ulong font);

void main() {

  // init screen and OpenGL setup

  auto font = loadFont(cast (char * ) Arial.TTF);

  scope (exit) destroyFont(font);

  // draw some text

  // close OpenGL and SDL with some second delay
}

This works properly, and long is surely large enough to hold
a pointer in it, I could use sizet, I know that would be better.

My problem is that auto font here is an ulong. Could that be
wrapped into a type Font so that it only accepts assignment
from other Font type but no insecure numeric caluclations
and make the loadFont return that Font type, and other
methods use Font as arguments?


You probably want something like this:

struct Font {

  static Font opCall(string path) {
 Font f;
 f.fptr = loadFont(path.toStringz());
return s;
  }

  c_ulong fptr;
}

use it like this:

Font arial = Arial.TTF;

when pasing font to extern functionst that accept ulong use 
arial.fptr, in your (D) functions use Font.


Re: Proper C Pointer Binding

2014-03-26 Thread ralex

  static Font opCall(string path) {
 Font f;
 f.fptr = loadFont(path.toStringz());
return s;
  }


That should be return f; of course.


Re: ddox-generated Phobos documentation is available for review

2014-03-10 Thread ralex
On Monday, 10 March 2014 at 14:56:13 UTC, Andrei Alexandrescu 
wrote:

On 3/10/14, 1:35 AM, Nicolas Sicard wrote:
For me it's a real improvement! One thing: symbol names 
(modules,

functions, etc.) shouldn't be hyphenated, specially in tables.


All: how does one turn off css hyphenation?

Andrei


word-wrap: break-word;
-webkit-hypens: none;
-moz-hypens: none;
-ms-hypens: none;
hypens: none;


should do the trick..