Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread torhu via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear 
wrote:

Hi,

In Java/C# you can create purely static classes.

These are classes whose methods are all static, the classes 
cannot be derived from or instantiated:


```
static class Algo {
void drawLine(Canvas c, Pos from, Pos to) { .. };
}
```

Class in use:

```
Algo.drawLine(new Canvas(), new Pos(5, 3), new Pos(7, 9));
```


But why not have drawLine just be a free function?

```
import bluepandastuff.algo;

auto canvas = new Canvas();

drawLine(canvas, Pos(5, 3), Pos(7, 9));

// Or, using UFCS:
canvas.drawLine(Pos(5, 3), Pos(7, 9));

```

I turned Pos into a struct, seems like a typical value type to me.


Re: Is there such a JSON parser?

2023-01-02 Thread torhu via Digitalmars-d-learn
On Monday, 2 January 2023 at 21:36:10 UTC, Steven Schveighoffer 
wrote:

On 1/1/23 6:28 PM, torhu wrote:
I need to parse some JSON data into various data structures, 
so I'm looking for a parser based on events or ranges. One 
that doesn't just load the file and build a data structure 
that represents the whole thing. So not std.json, at least.


It's pretty rough-edged, but 
https://code.dlang.org/packages/jsoniopipe will do this. It has 
mechanisms to jump to specific object members, and to rewind to 
a cached point. It does not use any intermediate representation.


-Steve


Thank, I can check it out.


Re: Handling CheckBox state changes in DLangUI

2023-01-02 Thread torhu via Digitalmars-d-learn
On Saturday, 31 December 2022 at 02:40:49 UTC, Daren Scot Wilson 
wrote:


The compiler errors I get are, for no '&' and with '&':

Error: function `app.checkbox_b_clicked(Widget source, bool 
checked)` is not callable using argument types `()`


Error: none of the overloads of `opAssign` are callable using 
argument types `(bool function(Widget source, bool checked))`


If checkbox_b_clicked is a non-static nested function or 
non-static method, taking the address of it should result in a 
delegate, not a function pointer.


You can check what it is like this:

writeln(typeid(&checkbox_b_clicked));


Re: Is there such a JSON parser?

2023-01-02 Thread torhu via Digitalmars-d-learn

On Monday, 2 January 2023 at 14:56:27 UTC, SealabJaster wrote:

Are you asking for a SAX-styled parser for JSON?


Yes, I actually want to replace a SAX parser.


Re: Is there such a JSON parser?

2023-01-02 Thread torhu via Digitalmars-d-learn

On Monday, 2 January 2023 at 05:44:33 UTC, thebluepandabear wrote:

You might want to try the following:

https://github.com/libmir/asdf


I had a look at that, but I think it just loads the whole file 
into it's own data structure. And then you can use attributes to 
get it to fill structs with data, but that's too basic for my 
needs.


Is there such a JSON parser?

2023-01-01 Thread torhu via Digitalmars-d-learn
I need to parse some JSON data into various data structures, so 
I'm looking for a parser based on events or ranges. One that 
doesn't just load the file and build a data structure that 
represents the whole thing. So not std.json, at least.


Re: How to use version in dub?

2022-12-13 Thread torhu via Digitalmars-d-learn

On Tuesday, 13 December 2022 at 19:50:15 UTC, torhu wrote:

On Tuesday, 13 December 2022 at 19:28:44 UTC, Leonardo A wrote:

Hello. How to use version in dub?

https://dlang.org/spec/version.html
"The version level and version identifier can be set on the 
command line by the -version"


I tried everything but noting.


In SDL syntax, either at the top level, in a configuration, or 
build type:


```
versions "something" "other"
```


To be more clear: When using dub you need to put this in the dub 
file, dub.sdl or dub.json. If you want to be able to choose from 
the command line, use a configuration:


```
configuration "something" {
versions "something"
}
```

Then you can do:
```
dub build -c=something
```


Re: How to use version in dub?

2022-12-13 Thread torhu via Digitalmars-d-learn

On Tuesday, 13 December 2022 at 19:28:44 UTC, Leonardo A wrote:

Hello. How to use version in dub?

https://dlang.org/spec/version.html
"The version level and version identifier can be set on the 
command line by the -version"


I tried everything but noting.


In SDL syntax, either at the top level, in a configuration, or 
build type:


```
versions "something" "other"
```



Re: aa.keys, synchronized and shared

2022-11-14 Thread torhu via Digitalmars-d-learn

On Monday, 14 November 2022 at 07:57:16 UTC, Kagamin wrote:

This works for me:
```
shared SyncAA!(string,string) saa;
void f()
{
saa=new shared SyncAA!(string,string)("1","2");
saa.keys();
saa["12"]="34";
saa.remove("12");
}
```


The strange error message I got was because I initialized the 
variable at module level, that doesn't work when you have a 
constructor. It worked when I moved it into a module constructor.


Re: aa.keys, synchronized and shared

2022-11-11 Thread torhu via Digitalmars-d-learn

On Friday, 11 November 2022 at 14:19:31 UTC, Kagamin wrote:

Try this:
```



private:
V[K] sharedTable;
ref inout(V[K]) unsharedTable() inout
{
return *cast(inout(V[K])*)&sharedTable;
}
```


Thanks, that worked! Feels like programming in C, though. If I 
could figure out how to initialize the AA explicitly, I could 
also remove the ref here. If I just remove the ref, the AA is 
always null. If I try to initialize it in the constructor, I get 
this:


src\syncaa.d(11,5): Error: `_d_monitorenter` cannot be 
interpreted at compile time, because it has no available source 
code


No idea why, it seems to happen if I try to use the AA in the 
constructor at all. Even when I just do `data_.remove(K.init);`


I also tried DMD 2.101.0-rc.1, using the new `new V[K]` syntax, 
same error there.


Re: aa.keys, synchronized and shared

2022-11-10 Thread torhu via Digitalmars-d-learn

On Thursday, 10 November 2022 at 21:55:26 UTC, torhu wrote:

I'm trying to make a more thread-safe wrapper for AA's:

```
synchronized final class SyncAA(K, V) ///


I chose to fix this by just using `synchronized (this)` inside 
each method instead, for now. Still interested in cleaner 
solutions, but I guess synchronized/shared is a bit of a rabbit 
hole...


aa.keys, synchronized and shared

2022-11-10 Thread torhu via Digitalmars-d-learn

I'm trying to make a more thread-safe wrapper for AA's:

```
synchronized final class SyncAA(K, V) ///
{
///
V opIndex(K key) { return data_[key]; }

///
V opIndexAssign(V value, K key) { return data_[key] = value; }

///
K[] keys() const { return data_.keys; }

///
void remove(K key) { data_.remove(key); }

/// There is no `in` operator, it would not be thread-safe.
V get(K key, lazy V defaultValue=V.init)
{
auto p = key in data_;
return p ? *p : defaultValue;
}

///
int opApply(scope int delegate(inout ref V) dg) const
{
int result = 0;
foreach (value; data_) {
result = dg(value);
if (result)
break;
}
return result;
}

///
int opApply(scope int delegate(K, inout ref V) dg) const
{
int result = 0;
foreach (key, value; data_) {
result = dg(key, value);
if (result)
break;
}
return result;
}

private:
V[K] data_;
}
```

In another file:
`__gshared serverListCache = new SyncAA!(string, ServerList);`

I'm using `keys` in a regular function, this is the error i get:

C:\prog\dmd\windows\bin\..\..\src\druntime\import\object.d(3245,36): Error: 
cannot implicitly convert expression `aa` of type 
`shared(const(ServerList[string]))` to `const(shared(ServerList)[string])`
src\syncaa.d(17,36): Error: template instance 
`object.keys!(shared(const(ServerList[string])), 
shared(const(ServerList)), string)` error instantiating
src\serveractions.d(45,33):instantiated from here: 
`SyncAA!(string, ServerList)`
src\serveractions.d(50,17): Error: `shared` `const` method 
`syncaa.SyncAA!(string, ServerList).SyncAA.keys` is not callable 
using a non-shared mutable object

Error C:\prog\dmd\windows\bin\dmd.exe failed with exit code 1.




Re: Doubt about char.min/max == typeid(char)

2022-10-06 Thread torhu via Digitalmars-d-learn

On Friday, 7 October 2022 at 00:13:59 UTC, matheus wrote:

Hi,

Could anyone please tell me why the properties of min/max of a 
char returns a "char type" and not a value as an int?


Well, why whould the highest and lowest values of a type be of a 
different type..?



```d
import std;

void func(char x) { writeln("It's a char"); }
void func(int x)  { writeln("It's an int"); }
void func(double x)  { writeln("It's a double"); }

void main(){
func(char.min);
}
```



Re: Replacing tango.text.Ascii.isearch

2022-10-06 Thread torhu via Digitalmars-d-learn

On Thursday, 6 October 2022 at 21:36:48 UTC, rassoc wrote:

And what kind of testing was that? Mind to share? Because I did 
the following real quick and wasn't able to measure a "two 
orders of magnitude" difference. Sure, the regex version came 
on top, but they were both faster than the ruby baseline I 
cooked up.


Originally I just loaded a one megabyte file and searched the 
whole thing. I changed it to split it into (40 000) lines 
instead, regex is about ten times faster then. I compile with 
-release -O -inline. Here is the second version:


```d
import std;
import std.datetime.stopwatch;

enum FILE = "test.lst";
string text;
string needle;

void test(bool delegate(string haystack) dg)
{

auto sw = StopWatch(AutoStart.yes);
int counter = 0;
foreach (line; lineSplitter(text)) {
if (dg(line))
counter++;
}
sw.stop();
writefln("%s", sw.peek());
writefln("counter: %s", counter);
}

void main(char[][] args)
{
enforce(args.length > 1, "Need a needle argument.");

text = cast(string)read(FILE);
needle = args[1].idup;
auto re = regex(to!string(escaper(needle)), "i");
string needleLower = needle.toLower();

test((h) => !!h.matchFirst(re));
test((h) => h.asLowerCase().canFind(needleLower));
}
```



Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread torhu via Digitalmars-d-learn
On Wednesday, 5 October 2022 at 17:29:25 UTC, Steven 
Schveighoffer wrote:



```d
bool isearch(S1, S2)(S1 haystack, S2 needle)
{
import std.uni;
import std.algorithm;
return haystack.asLowerCase.canFind(needle.asLowerCase);
}
```

untested.

-Steve


I did some basic testing, and regex was two orders of magnitude 
faster. So now I know, I guess.


Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread torhu via Digitalmars-d-learn

On Wednesday, 5 October 2022 at 20:45:55 UTC, torhu wrote:

On Wednesday, 5 October 2022 at 20:40:46 UTC, torhu wrote:



Am I doing something wrong here?


Right, you can instantiate structs without arguments. It's been 
ten years since I last used D, I was thinking of structs like 
if they were classes.


I think there should be sensible default here, seems like an easy 
trap to remove.


Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread torhu via Digitalmars-d-learn

On Wednesday, 5 October 2022 at 20:40:46 UTC, torhu wrote:



Am I doing something wrong here?


Right, you can instantiate structs without arguments. It's been 
ten years since I last used D, I was thinking of structs like if 
they were classes.


Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread torhu via Digitalmars-d-learn
On Wednesday, 5 October 2022 at 17:29:25 UTC, Steven 
Schveighoffer wrote:

[...]


I wanted to do some quick benchmarking to figure out what works.

When I run this:

```d
import std.stdio;
import std.datetime.stopwatch;

void main()
{
auto sw = StopWatch();  
sw.stop();
writeln(sw.peek().toString());
}
```

It prints this:
2 weeks, 6 days, 9 hours, 34 minutes, 43 secs, 214 ms, 946 ╬╝s, 
and 7 hnsecs


Am I doing something wrong here?


Replacing tango.text.Ascii.isearch

2022-10-05 Thread torhu via Digitalmars-d-learn
I need a case-insensitive check to see if a string contains 
another string for a "quick filter" feature. It should 
preferrably be perceived as instant by the user, and needs to 
check a few thousand strings in typical cases. Is a regex the 
best option, or what would you suggest?


Re: Template function alias that leaves out the last type parameter

2022-09-28 Thread torhu via Digitalmars-d-learn

On Wednesday, 28 September 2022 at 12:43:52 UTC, rassoc wrote:

On 9/28/22 02:04, torhu via Digitalmars-d-learn wrote:

Thank you, works like a charm!


It does? How are you formatting `info("foo", 'a', 42)` inside 
the template if I may ask?


It works like writefln, so that example would not compile. I 
forgot to make the format string explicit, I probably should have 
done that.


```
private template _messageBox(string title, int style)
{
void _messageBox(T...)(T args)
{
messageBox(format(args), title, style);
}
}
```



Re: Template function alias that leaves out the last type parameter

2022-09-27 Thread torhu via Digitalmars-d-learn

On Tuesday, 27 September 2022 at 23:18:06 UTC, Adam D Ruppe wrote:

On Tuesday, 27 September 2022 at 22:39:52 UTC, torhu wrote:
How would I achieve something like this, do I have to turn the 
aliases into functions?


You can write it out long-form with two steps like this:



Thank you, works like a charm!


Re: Template function alias that leaves out the last type parameter

2022-09-27 Thread torhu via Digitalmars-d-learn

On Tuesday, 27 September 2022 at 22:39:52 UTC, torhu wrote:
How would I achieve something like this, do I have to turn the 
aliases into functions?


```d
void _messageBox(string title, int style, T...)(T args)
{
string s = format(args);
/* etc... */
}

alias _messageBox!(APPNAME, SWT.ICON_INFORMATION) info;
alias _messageBox!("Warning", SWT.ICON_WARNING) warning;
alias _messageBox!("Error", SWT.ICON_ERROR) error;
```


I should mention that I am really looking for a Phobos 2 way of 
achieving what I currently do, which is this:

```d
void _messageBox(string title, int style)(...)
{
char[] msg;
void f(dchar c) { encode(msg, c); }
doFormat(&f, _arguments, _argptr);
messageBox(cast(string)msg, title, style);
}
```


Template function alias that leaves out the last type parameter

2022-09-27 Thread torhu via Digitalmars-d-learn
How would I achieve something like this, do I have to turn the 
aliases into functions?


```d
void _messageBox(string title, int style, T...)(T args)
{
string s = format(args);
/* etc... */
}

alias _messageBox!(APPNAME, SWT.ICON_INFORMATION) info;
alias _messageBox!("Warning", SWT.ICON_WARNING) warning;
alias _messageBox!("Error", SWT.ICON_ERROR) error;
```



Re: D1: Passing 0x00000000 value to a Windows COM function

2012-08-21 Thread torhu

On 20.08.2012 00:43, jicman wrote:


Greetings.

I am trying to pass a (I think) dchar value to a Windows COM
function and it does not work.  Imagine this situation...

dchar test()
{
   dchar val = 0x;
   return val
}

void main()
{
   ...lots of code excluded
   SomeWindowsComCall(test); // this call does not work
   SomeWindowsComCall(0x); // this call works
}

Any idea how I can create a function to be able to return values
such as 0x .. 0x?


Returning a dchar works just fine when I try it, there is probably a bug 
in your code.


What is the argument type of SomeWindowsComCall?  That's the type you 
should, and it's probably not a dchar.  Look at the MSDN docs for the 
function to see what type it wants.


Re: D1: Passing 0x00000000 value to a Windows COM function

2012-08-21 Thread torhu

On 20.08.2012 18:22, jicman wrote:
...


dchar GetSourceLanguageEnumaration(char[] lang)
{
  // *** STaggerF.SourceLanguage Enumeration ***
   dchar sl = 0x;
   lang = std.string.tolower(lang);
   //msgBox(lang);
   switch(lang)
   {
 case "sq", "sq-al": // stfTargetLanguageAlbanian = 0x,


I don't think that will work, try this instead:

case "sq": case "sq-al":


Re: D1: Passing 0x00000000 value to a Windows COM function

2012-08-20 Thread torhu

On 20.08.2012 00:43, jicman wrote:


Greetings.

I am trying to pass a (I think) dchar value to a Windows COM
function and it does not work.  Imagine this situation...

dchar test()
{
   dchar val = 0x;
   return val
}

void main()
{
   ...lots of code excluded
   SomeWindowsComCall(test); // this call does not work
   SomeWindowsComCall(0x); // this call works
}

Any idea how I can create a function to be able to return values
such as 0x .. 0x?


It's easier to help if you post an actual, compilable example.  As small 
as possible. Because the code you posted doesn't show any real 
possibility of bugs, barring compiler bugs.


Re: FYI my experience with D' version

2012-07-30 Thread torhu

On 28.07.2012 22:55, Adam D. Ruppe wrote:

After some experience, I've come to the conclusion that
using D's version() with custom things is usually a mistake.
Not always - I think it is still good for platform like tweaks,
version(X86) or version(Windows), or even version(Custom_Library),
(note, it is often smart to put an "else static assert(0)" at the
end of platform version lists, so it doesn't pass silently on new
one)

But using it to enable or disable particular named features or
other kind of custom configuration things is a mistake. Every
time I've done it for that, I've gone back and changed it.


The reason is it is too easy to get it wrong:

module a:
version = Foo;

module b:
import a;
version(Foo) { this doesn't actually execute }


version is good for global options that you set with -version on the 
command line.  And can also be used internally in a module, but doesn't 
work across modules.  But it seems you have discovered this the hard way 
already.


I think there was a discussion about this a few years ago, Walter did it 
this way on purpose.  Can't remember the details, though.


Re: WinAPI LowLevel Keyboard Hooks

2012-07-21 Thread torhu

On 19.07.2012 13:45, DLimited wrote:

Hello everyone,

I had this great idea of writing a Program that intercepts all
keyboard presses and modifies them in certain cases.
I want to use it as some kind of global makro program to run in
the background and for example allow me to easily post unicode
smileys.


If you don't want make your own program, you can go here instead:
http://www.autohotkey.com

But you probably knew about it.


Re: About File.rawWrite

2011-11-29 Thread torhu

On 29.11.2011 16:00, Denis Shelomovskij wrote:


Your OS is Windows, right? On Windows, rawWrite and rawRead always
flushes stream, sets binary mode, reads/writes, flushes stream again,
sets previous mode. This is definitely unnecessary slow - at least it
should change mode only if needed (the file is opened in a text mode).
The better solution is to change all other functions so the file mode
will be changed lazily (for a text file, raw* functions will change file
mode and leave file in this mode until a call of a function, that really
needs a file to be in a text mode).

By the way, why this changing mode behaviour is Windows only? Yes, it is
clearly documented that this is the case, but it isn't documented _why_
this is the case.


Text mode means that \n in strings is translated to \r\n when writing, 
and the other way when reading. That way you can use only LF (\n) to get 
linefeeds on all platforms, even if Windows uses CRLF.


Re: Memory leak with BufferedFile?

2011-08-29 Thread torhu

On 28.08.2011 01:00, Leon wrote:

I'm writing a simple program which uses merge sort to sort very large text
files. I split the text file into several temporary files which are sorted and
merged together.

The trouble I'm having is that the BufferedFile class seems to have a memory
leak. The memory usage of the process slowly goes up until it throws an out of
memory exception. I can fix the memory leak by switching to the File class,
but that makes the program much slower.

Calling GC.collect() didn't help, and neither did explicitly deleting the
BufferedFile object.


You could try just using the functions in std.stdio instead.


Re: Symbol undefined due to import statement

2011-08-15 Thread torhu

On 15.08.2011 10:15, Andre wrote:
...

I compile the application with command:
dmd -IC:\Projects\Reusuable main.d

This works, but if I now edit the http.d file
and add an import statement like "import std.stdio;"
then the linker will output following error:

   main.obj(main)
   Error 42: Symbol Undefined _D3net4http12__ModuleInfoZ

Where is my error?


You need to add all your project's files to the command line:

dmd -IC:\Projects\Reusuable main.d net\http.d



Re: Replacing hex values in a string (v1.0)

2011-08-12 Thread torhu

On 12.08.2011 18:19, jicman wrote:


Greetings and salutations.

Hi.  I am reading a file into a string,

char[] text = cast(string) f0.read();

and I want to replace every non-breaking space in the string.  I know that the 
hex value for that is A0, but when I do this call,

text = std.string.replace(text,x"A0"," ");

It does takes it out, but it adds (or leaves) a little square to it.  
Apparently, it leaves something else, there.  It would be nice if std.string 
had a function to go from hex to decimal and back.

Any ideas?


Is the file UTF-8? In that case, try "\u00A0" instead, as "A0" won't be 
correct then.


Re: DMD's kernel32.lib missing symbols?

2011-07-30 Thread torhu

On 30.07.2011 11:43, simendsjo wrote:

On 29.07.2011 22:06, Simon wrote:

 On 29/07/2011 19:27, simendsjo wrote:

 On 29.07.2011 19:13, Simon wrote:

 On 29/07/2011 11:14, simendsjo wrote:

 Not sure how I can search for symbols in the library, but it seems the
 library is missing functions.
 I've tried using coffimplib on kernel32.lib from the Windows SDK,
 but it
 neither produces a new library or give me an error.

 What Windows version is the library based on?
 How can I check what symbols exists?
 Is there a way to convert WinSDK's library to omf?


 Shows how to make your own import lib for windows system dll:

 http://www.sstk.co.uk/d.php

 Been ages since I did that though so let me know if you have problems.



 I've tried using implib too, but replacing dmd's own kernel32.lib seems
 to create problems.


 What sort of problems? It's worked perfectly for me so far.



PTLINK (R) for Win32  Release 8.00.12
opyright (C) Digital Mars 1989-2010  All rights reserved.
ttp://www.digitalmars.com/ctg/optlink.html
:\dmd\windows\bin\..\lib\phobos.lib(dmain2)
Error 42: Symbol Undefined _LocalFree@4
:\dmd\windows\bin\..\lib\phobos.lib(dmain2)
Error 42: Symbol Undefined _WideCharToMultiByte@32

etc..

I tried to replace kernel32.lib like this:
c:\dmd\windows\lib>implib /system kernel32.lib
\Windows\system32\kernel32.dll

As this didn't work, I recompiled druntime and phobos with the new
kernel32.lib, but I get the same errors.


Both those symbols are definitely present in the kernel32.lib that comes 
with DMD 2.053.  Just grep for them and you'll see.  There is something 
going on with either your DMD install or the command line passed to the 
linker.


Re: std.date / std.datetime

2011-01-18 Thread torhu

On 18.01.2011 12:34, Richard Chamberlain wrote:

Hello,

I'm in the process of learning D, and to do so I'm converting some older code.

I need to print out the current local date and time, which is causing
some difficulties because std.date doesn't seem adequate in this
respect. I understand there is soon to be a replacement, std.datetime,
which I suspect will be much easier.

When are we likely to see a new release which includes std.datetime?

If not relatively soon I presume the easiest thing to do is to download
it myself and recompile the phobos library to include it. In which case
there seems to be already a std.datetime with different functionality,
is this used elsewhere in phobos? i.e. if I replace it with the new
std.datetime is that OK?


You could always use the C functions, if you import core.stdc.time.  The 
ctime and strftime functions should do the trick.


http://cplusplus.com/reference/clibrary/ctime/


Re: Asian characters are not printed propely in console

2011-01-05 Thread torhu

On 04.01.2011 10:47, Jun wrote:

I'm sorry for posting in the wrong place.

I attached screenshot of my code and the result.

As you can see, Korean letters get changed after compilation.

This problem doesn't happen with user input(from readln() method).

Should I use different type and prefix or suffix similary to C++?


If you save the file as utf-8, and set the console to CP 65001 (which is 
utf-8), it should work.  Providing your console font suppports the 
characters, of course.


You can add the suffixes 'w' or 'd' to get utf-16 or utf-32, 
respectively.  But then you need to save the file in that encoding, and 
change the console code page accordingly.  It all has to match up.


But I would expect it to work with other character sets too, as long as 
the file encoding and the console match.


Re: Bemused by this build error

2010-11-18 Thread torhu

On 14.11.2010 20:26, Bob Cowdery wrote:

Hi

I copied a module because I am changing its form. The original is still
in the build but is a different package and class name. The closest
thing I can think it might be talking about is this line:

x_points[] =
(x_average[0][]+x_average[1][]+x_average[2][]+x_average[3][]+x_average[4][]+x_average[5][]+x_average[6][]+x_average[7][]+x_average[8][]+x_average[9][])/10;

I changed the name and it made no difference. How does one diagnose this
kind of problem?


Did you try doing a complete rebuild?


Re: Cannot find symbol using wine

2010-10-25 Thread torhu

On 25.10.2010 08:06, Jonathan M Davis wrote:
[...]

It looks liking adding advapi32.lib to the compilation command does the trick,
but I don't know why I've never needed to do that before with other Windows
functions.


Just guessing, but it might be that dmd doesn't add advapi32.dll to the 
linker's command line by default.  You can probably verify that by 
passing -v to dmd, to see the linker commands being used.


Re: writef: How to output hex byte?

2010-08-28 Thread torhu

On 29.08.2010 07:06, Nick Sabalausky wrote:

ubyte myByte = 0x09;
writef("%%%.2X", myByte);
writef("%%%02X", myByte);


On codepad.org (DMD 1.026 last time I checked), this prints this:
%09%09

So it's probably a bug in the new formatting code.  I assume it's 
supposed to follow the C behavior in this case.


Re: built-in string hash ?

2010-08-28 Thread torhu

On 28.08.2010 16:37, Kevin Bailey wrote:

So I have a class containing two strings:

class Foo
{
string s1, s2;

...

and I'd like to add a toHash() member, but I can't find
the built-in string hash function. These don't work:

s1.toHash()
s1.toHash
s1.hash
s1.hash()
hash(s1)

yet strings can clearly be the key in a map.

I see that xml.d writes its own string hash function
but that just doesn't seem right.

Is there a way to get to the built-in ?


You can get to it through TypeInfo:
http://www.digitalmars.com/d/2.0/phobos/object.html#getHash

string a = "abc";

auto hash = typeid(a).getHash(&a);


Re: Compiling Windows GUI-application

2010-08-27 Thread torhu

On 28.08.2010 00:58, Andrej Mitrovic wrote:

Try compiling with -L/SUBSYSTEM:WINDOWS:



-L/subsystem:windows:4 is better, maybe that's what you meant. Optlink 
defaults to an older version, which means some widgets don't work properly.


Re: Can't get D calling C to build.

2010-08-27 Thread torhu

On 23.08.2010 23:24, Bob Cowdery wrote:

Addendum: The plot thickens. If I build a dll with my VC++ Express 2010
then I can convert the import library and it actually works from D.
However if I build with MinGW GCC it doesn't even recognise the library
even though it is COFF format. My preferred route unfortunately is GCC.
I just got 'The D Programming Language' book and that devotes a whole
half page to this very important topic. This seems to be rather a
minefield and so far there only seems to be one route through it.


If you've got a DLL, you can usually generate an import library directly 
from that using the implib tool, download link below.


ftp://ftp.digitalmars.com/bup.zip

This obviously fails for DLLs that only export by ordinal, but those are 
not that common.  You need to use the /s switch to get correct name 
mangling.


Re: const(type) vs. const type

2010-07-20 Thread torhu

On 21.07.2010 00:57, Mike Linford wrote:

I'm playing with QtD, and I tried to override a QWidget's sizeHint()
function, which is declared as const QSize sizeHint(). I tried to
override it by declaring my function as override const(QSize) sizeHint
() . I got a compiler error that it was "not covariant" with const QSize,
and when I changed it to that it worked fine. I've skimmed through the
documentation but don't understand what the difference is. Any help?


In the first case, it's the function itself that ends up being const, 
not its return value.  It's like putting 'const' after the parameter 
list in C++.In the second case, only the return value is const.


Re: Extending the lifetime of scope objects

2010-07-20 Thread torhu

On 20.07.2010 21:54, Ali Çehreli wrote:

What are all the cases that extend the lifetime of scoped objects?

Binding a delegate to a scope object extends the lifetime of that
object, which would normally end upon exiting that scope. The lifetime
of i is extended here:

int delegate(int) make_delegate()
{
  int i;// lives as long as the returned delegate lives

  return (int param) {
  return i + param; // uses i
  };
}

void main()
{
  auto del = make_delegate();
  del(42);  // uses i
}

I was surprised to discover that, the same does not apply to struct
objects, *if* the struct has a destructor:

struct S
{
  int i;

  ~this()  // prevents life extension
  {}
}

int delegate(int) make_delegate()
{
  auto s = S();

  return (int param) {
  return s.i + param;
  };
}

void main()
{
  auto del = make_delegate();
  del(42);
}

Error: variable deneme.make_delegate.s has scoped destruction, cannot
build closure

Are the "life extending" cases short and simple? What are they? :)


When a local variable in a function (or delegate) is part of a nested 
delegate's context, that variable is heap allocated.  Which just means 
the GC will collect it sometime after the last reference is gone.  In 
your first example, it's like you did int* i = new int;


What is supposed to happen with your struct example doesn't seem to be 
documented, neither in the docs or TDPL.  Could be just an accident that 
it doesn't work.  Or it could be on purpose, but there's no way of 
knowing without asking Walter or Andrei.  There's a slight chance taking 
a reference to the struct itself instead of just a member will work.  I 
guess you just hit a marginal case here.


Re: monitor condition variables?

2010-07-20 Thread torhu

On 20.07.2010 19:21, Trass3r wrote:

So synchronized implements mutual exclusion.
http://www.digitalmars.com/d/2.0/class.html#synchronized-functions

What about condition variables:
http://en.wikipedia.org/wiki/Monitor_(synchronization)#Waiting_and_signaling
Is there any standard way to do that?


I think everything from tango.core.sync is included in the dmd download, 
it's just not in the docs yet.  Condition variables are then in 
core.sync.condition.


You can use the Tango docs for now:
http://www.dsource.org/projects/tango/docs/current/


Re: Is there a way to create compile-time delegates?

2010-07-19 Thread torhu

On 19.07.2010 21:06, Simen kjaeraas wrote:

Yeah, what the subject says.

I want to have a default delegate for a struct, and without a default
constructor, this has to be a compile-time constant. Now, logically,
there should be nothing wrong with storing the function pointer and a
null context pointer at compile-time, but it seems there is. Any ideas?

struct foo {
  void delegate( ) dg = () {}; // Error: non-constant expression
   // __dgliteral1
}



I wasn't able to make it work.  The compiler probably sees delegates as 
something that just can't be created at compile time, since no runtime 
contexts exist then.  Which is reasonable.


Maybe one of those templates that turn functions into delegates will 
work?  Otherwise I guess you're back to using a factory function for 
initializing instances.


Maybe just checking for null pointers before calling those delegates 
ends up being the easiest solution.


Re: Equivalent of scanf

2010-07-17 Thread torhu

On 18.07.2010 01:21, Michael Koehmstedt wrote:


So there is no scanf equivalent, but there is also nothing similar to C++ cin 
with
the<<  operator?



Equivalents of those are available in std.stream and std.cstream, but 
those modules will probably go away in a while.


Re: Equivalent of scanf

2010-07-17 Thread torhu

On 18.07.2010 00:41, Michael Koehmstedt wrote:

I'm having trouble figuring out how to do formatted console input, something
like C scanf() or C++ templated stream input. Unfortunately, console input
isn't covered in much detail in TDPL book. There doesn't appear to be much
discussion about the standard library at all, which was a bit disappointing.

But anyway, what different ways are there to properly do input from the
console? Fetching a string with readln() is easy enough, but how could I
fetch, say, an integer value? Conversely, what is the preferred method for
converting string into integer or floating point values?


The standard library (Phobos) is getting overhauled, which is probably 
why there's not a lot of detail about it in the book.  It's still quite 
limited and buggy.  Up until now, most real D work has probably been 
done using D1 and the Tango library.


There's a scanf implementation in the works, but it's not released yet. 
 You can probably get by with the to() and parse() functions in 
std.conv. C's isdigit() will probably come in handy too, it's defined in 
core.stdc.ctype.


Re: CT usage only in executable

2010-07-17 Thread torhu

On 15.07.2010 02:29, strtr wrote:

Not that the memory is really significant compared to the rest of my program,
but I have a few fairly large arrays I use only in compile time and I was
wondering why dmd still includes those in the executable (simple text search
dug them up).


As a workaround you could try putting those arrays in a separate module 
which you don't link into your executable.  If you use a build tool like 
xfbuild, you can exclude files with the -X switch.  CTFE would still work.


Re: Best practice and module declarations

2010-07-15 Thread torhu

On 15.07.2010 23:28, Rory McGuire wrote:

On Thu, 15 Jul 2010 23:08:07 +0200, torhu  wrote:


 On 15.07.2010 21:59, Rory McGuire wrote:

From what I remember in TDPL:
 Can be used to rename a module if you have it in a different directory
 structure than how you use it. E.g. implementation and "headers" in
 separate folders.


 If you use *.di files (headers), you would normally just keep the
 directory structure, but put the whole thing in a different root
 directory.  Just having *.d and *.di files in the same directory works
 too, as the compiler prefers the *.di files.



Andrei's use case was if you had multiple teams of programmers with some
allowed to work on
interfaces and others only allowed to work on the implementations.




 Can be used to rename module when a filename is not a valid D symbol.


 That would fool the D-specific build tools, and DMD itself too.  In most
 cases it's easier to just rename the file too.  It can be made to work
 using a *.di file if you really have to.


Andrei's example had hyphens in the file name, sometimes policy comes
first? yes no. Not that I
can think of a reason for the policy off hand perhaps GTK naming
convention.


Seem a bit far fetched those examples, but ok ;)


Re: Best practice and module declarations

2010-07-15 Thread torhu

On 15.07.2010 21:59, Rory McGuire wrote:

  From what I remember in TDPL:
Can be used to rename a module if you have it in a different directory
structure than how you use it. E.g. implementation and "headers" in
separate folders.


If you use *.di files (headers), you would normally just keep the 
directory structure, but put the whole thing in a different root 
directory.  Just having *.d and *.di files in the same directory works 
too, as the compiler prefers the *.di files.



Can be used to rename module when a filename is not a valid D symbol.


That would fool the D-specific build tools, and DMD itself too.  In most 
cases it's easier to just rename the file too.  It can be made to work 
using a *.di file if you really have to.


Re: Best practice and module declarations

2010-07-14 Thread torhu

On 15.07.2010 00:22, Jonathan M Davis wrote:

I was wondering what the general consesus was (if there is one) on whether it's
valuable to always put module declarations in each module.

Obviously, if you need the module to have a name other than the file name, then
you need to have the module declaration. However, is it necessarily desirable to
have it when the module name matches the file name? Or would there even be a
reason for it to be desirable _not_ to have the module declaration?

I can't think of any particularly strong reasons to have it or not to have it.
My first reaction is to just always use it, but thinking about it, I'm not sure
that there's really much point if the file name and the module name already
match. Does anyone have reasons why it would matter other than personal
preference?


Some of the D build tools complain if you don't use module declarations. 
 And IIRC, modules in subdirectories (packages) need to have them.  So 
I end up adding them for anything but single-file test programs.


Re: Recommended way to do RAII cleanly

2010-07-12 Thread torhu

On 13.07.2010 00:09, bearophile wrote:

Jonathan M Davis:

 There are lots of cases where using scope(exit) makes sense, and it's a great
 construct. But there are also plenty of cases where using plain old RAII with a
 single declaration is better. It works fine in D as long as the struct in
 question doesn't need a default constructor. But if it does, then it becomes a
 problem.


Can't you use a static opCall (also suggested by Jacob Carlborg)?

Bye,
bearophile


I think that's supposed to go away, but I'm not 100% sure.  Would make 
sense, since it was added as a sort of stopgap measure when there were 
no struct literals.


Re: Recommended way to do RAII cleanly

2010-07-12 Thread torhu

On 12.07.2010 08:25, Jonathan M Davis wrote:

Okay. There are cases where you want a constructor to do something when the
class/struct is created, and you want the destructor to do something when the
class/struct goes out of scope. A classic example would be an autolock for a
mutex. Another would be the hourglass in MFC - it's displayed when the object is
created and disappears when the object is destroyed (so all you have to do is
declare the object it at the beggining of the function and it automatically is
displayed and then disappears). This is classic RAII.

Obviously, because classes are reference types with infinite lifetime while
structs are value types with their lifetime restricted to their scope, structs
would be the better choice for RAII. I have noticed a bit of a snag however:
structs can't have default constructors.

After reading TDPL, I completely understand that structs can't have default
constructors due to how the init property works. However, the classic case where
you want to simply declare an object and have it do what it does through RAII
then falls apart. Ideally, you'd have something like this

struct S
{
 this()
 {
 /* do something */
 }

 ~this()
 {
/* undo what you did before or do whatever clean up is required for it 
*/
 }
}

void main()
{
 auto s = S();
/* whatever the rest of main() does */
}


Thanks to the lack of default constructor, you can't do that. Therefore, I see 2
options:

1.  Create a nonsensical constructor that takes an argument of _some_ kind which
is totally ignored.

2. Create a factory function to create the struct, and it does whatever would
have been in the default constructor.


Out of those two options, the second seems the best, but it seems to me that
there have got to be more options than that. So, the question is what would be
the best option (be it one of those or another that I haven't though of) to do
RAII in the general case? What would be "best practice" for D when dealing with
structs intended for RAII without any arguments to their constructor when you
can't have a default constructor?

- Jonathan M Davis


Appender in std.array has the same issue, and solves it with a static 
assert and a factory function:

http://www.dsource.org/projects/phobos/changeset/

Well, except that Appender doesn't have a destructor.

But other than that, wouldn't most structs that use RAII have a 
constructor that at least requires some kind of handle as an argument?


For you hourglass example, wouldn't you need to call two methods anyway? 
I googled for "MFC hourglass". Then it'd look like this:


BeginWaitCursor();
scope (exit) EndWaitCursor();

The Mutex in Phobos is a class, so you'd have to do basically the same 
thing. But if you only need a local mutex, you'd probably use a 
synchronized statement instead.


I think the conclusion is that RAII is less important in D than in C++. 
 In D you use scope (exit), or even finally, like in Java or Python. 
The other use of scope, as a storage class, is supposed to go away, and 
I suspect I'm not the only one who's going to miss it.


Re: How do I make an extern function?

2010-06-28 Thread torhu

On 29.06.2010 02:51, Simen kjaeraas wrote:


module a;

extern void foo( );

void bar( ) {
  foo( );
}

module b;

import std.stdio;

void foo( ) {
  writeln( "Hi!" );
}


The above does not work (Error 42: Symbol Undefined _D1a3fooFZv). Adding
extern to foo in module b changes nothing. extern( C ) works, but seems
like a hack. Better ideas?


Using extern (C) is the only way I've seen this done.  I don't know of 
any way to make the symbols match up otherwise.  There's probably some 
hack that works, but is uglier than the more straightforward solutions. 
 You could always create a b.di file, if that doesn't defeat the purpose.


Re: setMaxMailboxSize

2010-06-17 Thread torhu

On 17.06.2010 23:31, Byron Heads wrote:

is setMaxMailboxSize not implemented yet or is it bugged?


It's just an empty function currently.  If you want to see for yourself, 
it's in dmd2/src/phobos/std/concurrency.d.




Re: Replacement for din.readf

2010-06-16 Thread torhu

On 16.06.2010 23:23, Ali Çehreli wrote:

I've been using din.readf to read from the standard input. Now that
streams are being retired (some or all?), what is the best replacement?

Thank you,
Ali


Try readln, lines, or rawRead from std.stdio.


Re: Yet more OPTLINK woes

2010-06-15 Thread torhu

On 15.06.2010 01:34, torhu wrote:

On 13.05.2010 21:07, torhu wrote:

On 13.05.2010 10:39, Daniel Keep wrote:

Attached both regular and decaffeinated^Hgutted versions.


Most likely DMD turns VisitorCtfe.d into an invalid object file.
But since you don't need to link with objects that contain only
ctfe functions...


http://d.puremagic.com/issues/show_bug.cgi?id=4315


Linker bug is http://d.puremagic.com/issues/show_bug.cgi?id=4324


Re: Yet more OPTLINK woes

2010-06-14 Thread torhu

On 13.05.2010 21:07, torhu wrote:

On 13.05.2010 10:39, Daniel Keep wrote:

Attached both regular and decaffeinated^Hgutted versions.


Most likely DMD turns VisitorCtfe.d into an invalid object file. But
since you don't need to link with objects that contain only ctfe
functions...


http://d.puremagic.com/issues/show_bug.cgi?id=4315


Re: build problem with xfbuild

2010-06-10 Thread torhu

On 11.06.2010 00:46, Richard Webb wrote:

If i try to use DMD 2.047 and xfbuild to compile a file which just contains

module arraytest;
import std.array;

I get the error:

F:\development\DTesting\dmd2\windows\bin\..\..\src\phobos\std\format.d(1882):
Error: template std.array.Appender!(string).Appender.put(U) if
(isImplicitlyConvertible!(U,T) || isSomeChar!(T)&&  isSomeChar!(U)) does not
match any function template declaration


F:\development\DTesting\dmd2\windows\bin\..\..\src\phobos\std\format.d(1882):
Error: template std.array.Appender!(string).Appender.put(U) if
(isImplicitlyConvertible!(U,T) || isSomeChar!(T)&&  isSomeChar!(U)) cannot
deduce template function from argument types !()(char[])



Try excluding phobos from the build with +xstd +xcore, at least the 
first one.


Re: lifetime of dynamically allocated memory

2010-05-31 Thread torhu

On 31.05.2010 22:27, dave wrote:

I'm trying to figure out if a dynamically allocated memory in D is getting
collected with this simple test (using tango):

class Foo {
 ~this() {
 // destructor
 }
}

struct Item {
 Foo a;
}

Item[] items;
items.length = 1;
items[0] = Item();
items[0].a = new Foo();

items = null;

GC.collect();

I assume that calling GC.collect(); forces gc to go through and free up memory
for any unreferenced objects. It seems that the destructor for Foo isn't being
called. I'm not sure if the reference is still used somewhere or do I have to
explicitly call 'delete items[0].a' to ensure that the memory is freed?


I'm not sure why it doesn't work.  But it's always better to post the 
code you're actually using, since now we can't be sure that you're not 
doing something else then what you think you're doing.  If you know what 
I mean. :)


Re: Yet more OPTLINK woes

2010-05-13 Thread torhu
Seems I've got an older version of optlink, 8.00.1.  With 8.00.2 I get 
the same behavior you did, but it still works if you don't link with 
VisitorCtfe.obj.


When running 8.00.2 in the msvc debugger, it just looks like optlink 
successfully exits.  No crash or anything.  But no useful output either.


So I guess this is two bug reports, not just one...


Re: Yet more OPTLINK woes

2010-05-13 Thread torhu

On 13.05.2010 10:39, Daniel Keep wrote:

Attached both regular and decaffeinated^Hgutted versions.


Most likely DMD turns VisitorCtfe.d into an invalid object file. But 
since you don't need to link with objects that contain only ctfe 
functions...


Here's what I get:
--
d:\prog\test\D\matheval>dmd -c AstTest.d Ast.d AstDumpVisitor.d Lexer.d 
Location.d Parser.d Source.d StructuredOutput.d Tokens.d TokenStream.d 
VisitorCtfe.d


d:\prog\test\D\matheval>dmd -ofAstTest.exe *.obj -v
binaryd:\prog\dmd\bin\dmd.exe
version   v1.060
configd:\prog\dmd\bin\sc.ini
d:\prog\dmd\bin\..\..\dm\bin\link.exe 
"*","AstTest.exe",,user32+kernel32/noi;

OPTLINK (R) for Win32  Release 8.00.1
Copyright (C) Digital Mars 1989-2004  All rights reserved.
VisitorCtfe.obj(VisitorCtfe)  Offset 004D8H Record Type 009D
 Error 16: Index Range
--- errorlevel 1

d:\prog\test\D\matheval>del VisitorCtfe.obj

d:\prog\test\D\matheval>dmd -ofAstTest.exe *.obj -v
binaryd:\prog\dmd\bin\dmd.exe
version   v1.060
configd:\prog\dmd\bin\sc.ini
d:\prog\dmd\bin\..\..\dm\bin\link.exe 
"*","AstTest.exe",,user32+kernel32/noi;


d:\prog\test\D\matheval>AstTest.exe
Can't initialize the TangoTrace LGPL stuff
Usage: AstTest.exe CODE

d:\prog\test\D\matheval>YAY



Re: Export values (enum, int, char[]...) for DLL

2010-05-13 Thread torhu

On 13.05.2010 18:23, Nrgyzer wrote:

Nrgyzer Wrote:
dmd now exports all values successfully. But when I try to export a class, I 
get the following errors:

"Error 42: Symbol Undefined _D5mydll1t7__ClassZ
Error 42: Symbol Undefined _D5mydll1t5_ctorMFZC11mydll1t"

Source of mydll.d is:

export class t {

export this();

}

Source of mydll2.d is:

import std.stdio: writefln;

export class t {

export this() {
writefln("hello world!");
}
}

Source of test.d:

pragma(lib, "mydll.lib");
import mydll;

void main() {

t myTest = new t();

}

When I export D5mydll1t7__ClassZ in my def-File, I can compile it but when I 
try to create a new instance of t, I get an access violation :(.


Never tried exporting a class, but there's some info on this page:

http://prowiki.org/wiki4d/wiki.cgi?BestPractices/DLL


Re: Yet more OPTLINK woes

2010-05-12 Thread torhu

On 12.05.2010 13:22, Daniel Keep wrote:


That's right, it's time for everyone's favourite [1] game: guess why
OPTLINK's not working! [2]

*sigh*  I'm writing a math eval library.  There are two test
applications.  LexerTest only touches part of the code.  AstTest touches
everything.

Now, the following works and creates an executable:

dmd -ofLexerTest (appropriate .d files)

So far, so good.  I get LexerTest.map, LexerTest.obj and LexerTest.exe.
  Let's try the other one...

dmd -ofAstTest (more .d files)

This creates a legitimate-looking AstTest.obj and a completely empty
AstTest.map file.

That's it.

No executable, no error message, no register dump, nothing.



Post the source and I'll try to help. I like debugging weird problems. :)


Re: Export values (enum, int, char[]...) for DLL

2010-05-06 Thread torhu

On 06.05.2010 16:06, Nrgyzer wrote:

Thanks, but doesn't work :(

My files contain:

mydll.d:

module mydll;
export extern int i;

mydll2.d:

module mydll;
export int i = 7;

test.d:

import mydll;
import std.stdio;

void main() {
writefln(i);
}

I can compile the dll, but when I compile test.d, I get the following error: "Error 
42: Symbol Undefined _D5mydll1ii"


It seems that export doesn't work for data, only functions.  If you 
build with -map, you'll see that i is not exported.  I got it working by 
using this .def file:


LIBRARY "mydll.dll"
EXETYPE NT
EXPORTS
D5mydll1ii


Then create the import lib with:
implib /s mydll.lib mydll.dll

/s adds the underscores.


If you use extern (C) the symbols will be a lot simpler to read and 
write, though.  Look at the .map file to see what the actual symbols are.


Re: Export values (enum, int, char[]...) for DLL

2010-05-05 Thread torhu

On 04.05.2010 21:46, Nrgyzer wrote:

Hello everybody,

I'm trying to create a (very) simple DLL by using D. Now I want export values - 
is there any way do this...


Off the top of my head, I think it goes like this:

To export from a DLL:
export int i = 7;

To export from a DLL, with C name mangling:
export extern (C) int i = 7;


To import from a DLL:
export extern int i;

To import from a DLL with a C interface:
export extern extern (C) int i;


I'm not sure if I recall the export part correctly, it's been a while 
since I actuall tried this.


Re: Undefined __moduleUnitTests

2009-12-21 Thread torhu

On 21.12.2009 3:45, Brian Eyster wrote:

I am running the compiler located in C:\dmd2\windows\bin\.
In the readme.txt file it gives the following info for the
compiler: "dmd.exe  D compiler
http://www.digitalmars.com/d/2.0/dmd-windows.html";
In the sc.ini file in the same directory is gives: "[Version]
version=7.51 Build 020"
If neither of these is not the version that you are looking for,
you will have to direct me to where it can be found.


DMD prints the version at the top of the usage instructions.

But here's what you need to do:

Replace _moduleUnitTests with runModuleUnitTests.

And add this declaration somewhere above WinMain:
extern (C) bool runModuleUnitTests();


It seems the sample wasn't updated to work with druntime.


Re: Undefined __moduleUnitTests

2009-12-19 Thread torhu

On 18.12.2009 8:23, Brian Eyster wrote:

I get the following message when trying to compile the winsamp.d
code:
OPTLINK (R) for Win32  Release 8.00.2
Copyright (C) Digital Mars 1989-2009  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
winsamp.obj(winsamp)
  Error 42: Symbol Undefined __moduleUnitTests
--- errorlevel 1

Am I missing something?

The function was probably renamed.  Which compiler version are you using?


Re: Help needed to actualizing allegro bindings (or this bindings are complex and I am dumb)

2009-11-15 Thread torhu

On 15.11.2009 08:53, g wrote:

I have been trying to actualize the http://www.dsource.org/projects/dallegro 
binings to the lastest D2 version.
The main problems are:
*TLS
*volatile isn't here anymore ( neither with -d )



You can remove volatile by just building with -version=NoVolatile.  But 
I suppose it won't work unless you add __gshared to all the non-const 
globals.  Or something, I'm not using D 2 myself.



One of the most hard things to understand was things like:

mixin(_volatile("int", "key_shifts"));
and  _volatile_setter things.



It's to make it easy to build both with and without volatile.  Most of 
this stuff is explained in the readme or somewhere in the code itself.



Especially when you have things like:

char* allegro_id;

and  then:

import allegro.internal.dintern;
static this() {
allegro_id = allegro.internal.dintern.allegro_id.ptr;
allegro_error = allegro.internal.dintern.allegro_error.ptr;
cpu_vendor = allegro.internal.dintern.cpu_vendor.ptr;
//_system_driver_list = allegro.misc._system_driver_list.ptr;
}
A strange way of wraping.

So...
Are there other bindings to allegro?
Does anyone has actualized this bindings?
Is Someone interested in helping?
Should i abdicate?

g


I know there's someone working on allegro 5 bindings, but I don't think 
they're done yet.  No announcement has been made.  But if you want to 
update dallegro, I'll try to answer questions at least.


Re: error linking to my own custom module

2009-11-10 Thread torhu

On 11.11.2009 04:57, Sean Fennell wrote:

I'm very green to D, just learning it now.
I have a module that I wrote.  Its pretty simple, just helper functions to get 
input from user as certain data types
GetInt()
GetString()
GetChar()
etc...

I compiled the module using dmd -lib mymod.d which output mymod.a

Now I've imported my module into ask.d to test it and I get the folliowing 
linking error when I try to compile:

ask.o:(.data+0x4c): undefined reference to `_D4mymod12__ModuleInfoZ`
My dir structure looks like this:

project/
---ask.d
---lib/
--mymod.d
--mymod.a

and my import line is:

import lib.mymod;

Anyone seen this before? Using linux dmd v2.036

Thanks!



You have to hand all the files to the compiler, otherwise there will be 
missing symbols when the compiler runs the linker.


Like this:
dmd ask lib/mymod

Compiling to a library first, like you did, will work too.  But you have 
to hand the compiler everything when you want to create the actual 
executable:


dmd ask lib/mymod.a

There are build tools, like dsss, that will automate this for you.


Re: Problems linking C and D code

2009-10-24 Thread torhu

On 24.10.2009 16:17, Jan Stępień wrote:

On Sat, 24 Oct 2009 15:56:05 +0200
torhu  wrote:

 On 24.10.2009 15:02, Jan Stępień wrote:
 >  Hi all,
 >
 >  I've got a problem with linking two object files on Windows with an
 >  external *.lib file. First one is compiled C code, second one is in D.
 >  I'm using D2.
 >
 > $ dmc -c first.c -I path/to/SDL/include
 > $ dmd -c second.d
 >
 >  First two commands create two *.obj file. After running
 >
 > $ dmd first.obj second.obj path/to/SDL.lib -ofout.exe
 >
 >  no "out.exe" file is created but the command returns 0. An "out.map"
 >  file is created, though. Where am I doing something wrong?
 >
 >  Cheers,

 Make sure there's a D main function define somewhere.  With SDL you're
 probably supposed to link with SDLmain.lib.


Thanks for the reply.

There is int main(string[] args) function in second.d. I tried linking
in both combinations, with SDLmain.lib only and with both SDL.lib and
SDLmain.lib - results are the same, unfortunately.

I also tried linking with SDL.dll instead of SDL.lib, but dmd exited
with a message "unrecognized file extension dll".

Cheers,


The Derelict project has D bindings for SDL, and seems to be a popular 
choice.


http://www.dsource.org/projects/derelict

Other than that, maybe out.exe is a special file name for the linker, or 
something.  You could try another name, just in case.


Re: Problems linking C and D code

2009-10-24 Thread torhu

On 24.10.2009 15:02, Jan Stępień wrote:

Hi all,

I've got a problem with linking two object files on Windows with an
external *.lib file. First one is compiled C code, second one is in D.
I'm using D2.

   $ dmc -c first.c -I path/to/SDL/include
   $ dmd -c second.d

First two commands create two *.obj file. After running

   $ dmd first.obj second.obj path/to/SDL.lib -ofout.exe

no "out.exe" file is created but the command returns 0. An "out.map"
file is created, though. Where am I doing something wrong?

Cheers,


Make sure there's a D main function define somewhere.  With SDL you're 
probably supposed to link with SDLmain.lib.


Re: D2 Win API Problem

2009-09-21 Thread torhu

On 21.09.2009 17:11, A Bothe wrote:

I solved the problem!

I've to make the function pointer to be extern(C),
so I will have

extern(C)
{
int function(...) tfunc;
}


MessageBoxA is definitely stdcall, so extern (Windows) is correct.  So 
the problem has to be something else.


Re: D2 Win API Problem

2009-09-20 Thread torhu

On 20.09.2009 20:11, A Bothe wrote:

Hello guys,
I got a problem with the following code. I can compile it successfully but when I want to 
start it, there is just this "object.AccessVialotion"!
Even GetLastError() returns 0 so the problem cannot be found in  
wrong-written names...

Thanks in advance!

import std.loader, std.c.windows.windows;

int function(HWND hwnd,char* text,char* title, uint style) tfunc=null;



Try adding "extern (Windows)" before the function pointer declaration. 
That'll select the stdcall calling convention, which most of the Windows 
API uses.


Re: Execute process and read its stdout/stderr asynchronously

2009-07-22 Thread torhu

On 22.07.2009 10:41, kkll wrote:

I'm trying out D2+phobos on OSX and would like to write wrapper around few 
shell commands.

I've found only very basic exec() and system() in std lib, but I need to launch 
few things at once and get all their output.

Is there something like Cocoa's NSTask in D?


For phobos 1, there's Regan Heath's old pipestream.d and process.d. 
Maybe you could port it to D 2. IIRC not all of it is in working condition.


It's here:
http://code.google.com/p/monsterbrowser/source/browse/monsterbrowser/tags/v03d/lib/


Re: There is not std.stdio.flush

2009-07-20 Thread torhu

On 20.07.2009 17:01, Haruki Shigemori wrote:

uhmm...
I think std.c.stdio is a port of the C language library,
std.stdio must has flush or fflush as the D language library.


It's not a port, it _is_ the std C library. std.stdio just adds 
functionality on top of what C provides.  That's what Phobos IO is, it's 
meant to be possible to use it interchangeably with C IO.


Tango IO is different, it uses the lowlevel OS APIs instead.


Re: Tango Jake or other build system for Linux

2009-06-14 Thread torhu

On 14.06.2009 17:16, Michal Minich wrote:

I would like to compile programs on Linux using LDC and Tango using
similar tool as is bundled with Windows version of Tango - jake.exe. This
build tool is not included in Linux version of Tango and I'm not able to
find it's source code anywhere.

Is there any tool for Linux that can parse imports of files and invoke
compiler with all project files? (And preferably one which does not
require any configuration, except choosing compiler).

I'm also curious why the jake.exe is not available for Linux and why it
does not have available source code.

Thanks.


Have you tried using rebuild?

http://dsource.org/projects/dsss/wiki/Rebuild


Re: dmd 2.029 gtkD weird error.

2009-04-21 Thread torhu

On 22.04.2009 01:03, zkp0s wrote:

|||Ups, wrong newsgroup.|||
um.. anyway, is there any rules or whatever about the newsgroups.¿What to do if 
you post on a wrong newsgroup?


Just post again, no the right newsgroup.  If possible, delete the post 
first.


Re: minimal evaluation

2009-04-06 Thread torhu

On 06.04.2009 13:30, Qian Xu wrote:

Hi All,

Is minimal evaluation always enabled in D?

I want to write a function IsNull(), so that I can check the precondition as
follows:

   if (isNull(foo) ||
   isNull(foo.getBar) ||
   isNull(foo.getBar.getBar2)
   {
 return false;
   }
   // normal code goes here

If an argument is null, the IsNull() will return false. Internally it will
be logged to console as well.

But I am not sure, if dmd-compiler generates code without minimal evaluation
in some cases. If minimal evaluation is not always enabled. I cannot do
precodition check in my way.

--Qian


If you mean short-circuit evalutation, I'm pretty sure that's always 
what the compiler does.


Re: Can somebody explain this memory usage

2009-04-03 Thread torhu

On 03.04.2009 11:34, Saaa wrote:

What is the resident set size called in winXP taskmanager (Or: which other 
application should I use to check memory usage)?
How can I chek memory stats? D1-phobos
Thanks



I believe 'Mem usage' is the resident size.

I often use Process Explorer for tracking memory usage, where resident 
size is called 'working set'.  Freely available from sysinternals.com. 
It's a great tool for performance tuning and general poking around.  I 
can also recommend Process Monitor, for tracking system calls and 
various other stuff.


Re: New to D: Building multiple files

2009-03-29 Thread torhu

On 29.03.2009 17:04, chris wrote:

Alright so I'm not too familiar with building D or having to build
multiple files from the command line (Java usually takes care of
that). Basically I have a small game I put together as  a test
project. Here's the structure:

clo/clo.d
clo/Main.d
clo/common/GameState.d

clo is in module clo , while GameState is in module clo.common.

Main.d imports both clo and clo.common

I'm using the latest 'Easy D' installation on windows (so I've been
building simple single files with dsss build (filename). I'm just
assuming building Main.d would grab the other stuff and build that
(like Java or C#), but I get the following.


[...]


C:\Users\me\Projects\clo>  dsss build -v Main.d clo.d commo
n\GameState.d


I don't know if dsss supports building without a config file.  Just 
doing 'rebuild Main.d' should work.  Or 'dmd Main.d clo.d 
common\GameState.d'.


Make sure that Gamestate.d has a 'module common.GameState;' declaration.


Re: No map file?

2009-03-23 Thread torhu

On 23.03.2009 10:02, Frank Benoit wrote:

How can i make DMD (link/optlink) not to generate a map file?

-L/NOM or -LNOMAP

both seem not work.


I don't know, but bud manages this somehow, so Derek Parnell might know.


Re: How to reduce compile times?

2009-03-21 Thread torhu

On 21.03.2009 19:50, grauzone wrote:

Christopher Wright wrote:

 grauzone wrote:

 PS: another thing that possibly would bring a speed gain would be to
 make dsss compile the whole project in one run, instead of invoking a
 new dmd process for each source file. How do I need to change the
 rebuild configuration to achieve this?


 oneatatime = [yes|no]

 You want 'no'. This will occasionally produce issues with ModuleInfo not
 being defined with some dmd versions, I think. Or something like that.


Yes, this causes random linker errors.



Those errors shouldn't happen if you compile one file at a time, I 
believe.  On the other hand, dsss' incremental compilation feature never 
seems to work for me.



What I need is to make dsss completely recompile the project, even if
only a single source file was modified. This way, no errors should
occur, and it would still be faster than with oneatatime=yes.

(Damn that crappy support for incremental compilation.)


I use bud, which builds everything with a single run of dmd, but uses 
incremental compilation.  If I get linker errors, I just run my cleanup 
script and try again.  Or add -full to bud's command line.


Re: Dear toolchain...

2009-03-10 Thread torhu

On 10.03.2009 19:38, Simen Haugen wrote:

Jarrett Billingsley wrote:

 On Tue, Mar 10, 2009 at 1:45 PM, Simen Haugen  wrote:

 I'm waist deep in problems, and have no idea how to get up.

 I have a program that uses d1, dmd, tango, ddbi, dwt and dwin. Some time ago
 I discovered that the program would no longer compile, and I have several
 features and bugfixes long overdue.

 It seems the problem happens during linking, but as I get no error what so
 ever it's a bit hard for me to track down. The project is about 30kloc.

 I've tried both dsss and rebuild. Dsss at least says rebuild exits with a
 status code 1, but still no hints on where the error might be.
 My guess is that this is a bug with lib.exe or link.exe, but I might be far
 off...

 I'm using D for several other programs, but don't keep a log for what
 versions I used when the projects last compiled... I've tried several
 different versions of both the compiler and the various libs, but as I said,
 I keep no log, so it's kind of a shot in the dark...

 I've spent at least 8 hours so far trying to locate the error with no luck.
 Does anyone have any good ideas how I can proceed?
 Or perhaps a pointer in the direction for narrowing down my search?



 Verbose flags!  That should help narrow down where the
 compilation/linking fails.


I've tried that. Rebuild keeps compiling files until I get the command
prompt with no message. I don't see any message showing the linking
begins, but if I exclude the last file from my project, the same thing
happens (in other words - I know all the files compiles correctly).
X-Files ...


You can use dsss to build a lib from dwt and the other libs you use. 
Then do a fully manual compile and link, on thing at a time. Run the 
linker directly or through dmd, not through rebuild and/or dsss.  That 
should narrow it down.


Re: how to initialize an array of struct

2009-02-12 Thread torhu

On 12.02.2009 15:16, Frits van Bommel wrote:

bearophile wrote:

 westcity Wrote:

 But, the compiler report "Error: array initializers as expressions are not 
allowed".
 Then, how do I initialize an array of struct ?


 Move the definition out of main (note that ; after the struct isn't required):

 struct Point {
 float x, y, z;
 }

 Point[3] pts = [{1.0, 0.0, 0.0},
 {0.0, 1.0, 0.0},
 {0.0, 0.0, 1.0}];

 void main () {}


The fact that *does* compile just makes the error message all the more
crazy...


It should compile inside of main if declared static.  It's just the 
error message that's a bit off.


Re: Example Attached

2009-02-11 Thread torhu

On 10.02.2009 19:51, Heinz wrote:

Heinz Wrote:

I attached a rar file with the sources just to see what i'm talking about. The example is from the 
DMD site. Included is the extern D (ok) and the extern C (fails). To compile open 
"compile.bat" and to run the programs use "run.bat".


Try this:
alias extern (C) void function(void*) MyDLL_Initialize_fp;
alias extern (C) void function() MyDLL_Terminate_fp;
alias extern (C) MyClass function() getMyClass_fp;


Re: long compile time 2.023 (few lines of code)

2009-01-23 Thread torhu

On 23.01.2009 18:49, Saaa wrote:

The following code takes too long to compile (I kill link.exe to stop it)
dmd 2.023 bud -full - cleanup

--
module project.main;

import project.bug;

void main()
{

}
--
module project.bug;

struct Struct
{
  uint number;
  int[6] array;
  byte[9] array2;
}
Struct structs[1_000_000];
--

Multiple variations on the struct seem to have the long compile time
effect.. allignment problem?




From http://www.digitalmars.com/d/1.0/arrays.html :

"The total size of a static array cannot exceed 16Mb. A dynamic array 
should be used instead for such large arrays."


It's an optlink limitation, so it's not likely to get fixed either.


Re: druntime

2009-01-16 Thread torhu

On 16.01.2009 15:39, Hoenir wrote:

Are there any information about druntime?
The D2.0 changelog states Phobos was split with v2.020 but there are no
information about that for D1.

I'm especially interested in using a library based on Tango while using
Phobos in the application itself (e.g. using the new DWT)


Druntime is only used for phobos 2 currently, not for 1.  So there won't 
be any further phobos/tango compatibility until tango is ported to D 
2.0.  And then dwt has to be ported too.


The closest you can get is using tangobos, which phobos modified to run 
on top of tango.  Probably better to just learn tango.


Re: .bat file to help compile easier - dmd/build

2009-01-03 Thread torhu

On 02.01.2009 22:21, Jarrett Billingsley wrote:

On Fri, Jan 2, 2009 at 2:17 PM, Michael P.  wrote:

 Okay, so right now, I'm making a small game(Mario) using DAllegro. I use 
build, and every time, I have to type this in to compile my progress:

 build mario alleg.lib

 Now, I know it's not a lot of typing. But considering I type mario wrong every 
so often, and I generally want to execute it after, assuming there is not 
compiler errors, it takes time.


Maybe you know this, but here goes. You can just press the up and down 
arrow keys to access command history.  Or F7 for a list.  make sure you 
use cmd.exe, not command.com.



 In a .bat file right now, I have this:

 build mario alleg.lib
 mario


build mario alleg.lib&&  mario


build supports this directly:
build mario alleg.lib -exec


Re: Cyclic Dependencies

2008-12-09 Thread torhu

Ellery Newcomer wrote:
When I first started learning D I decided that a good way to learn it 
would be by porting a popular java api (mind, I didn't say intelligent), 
which came complete with a few cyclic dependencies. At the moment, I'm 
using GDC, and it refuses to swallow cyclic dependencies. The compiler 
doesn't complain, but it throws a runtime exception. I can break the 
dependency loops and GDC will work just fine, but what I'm wondering is 
whether it is standard that the dependency hierarchy be acyclic, or is 
this some quirk of GDC, or is it more likely that there is something 
weird going on in my java-to-D translation.




You can't use module constructors (static this) in modules that import 
each other.


Re: Getting environment variables?

2008-11-23 Thread torhu

Christopher Wright wrote:

Hey all,

How do I get environment variables in a D program? I specifically want 
the path to a user's home folder.


Ta muchly.


I think the 'correct' way on Windows is to use SHGetSpecialFolderPathA.

Something like this:

char[MAX_PATH] buf;
SHGetSpecialFolderPathA(null, buf.ptr, CSIDL_PERSONAL, false);
char[] dir = toString(buf.ptr);

or CSIDL_APPDATA, etc.


Re: GLchar** problem

2008-10-30 Thread torhu

Saaa wrote:


Assuming the C code works, here's what you do in D.

GLuint shader;
shader=glCreateShader(GL_FRAGMENT_SHADER);
char[] file=cast(char[])read(`program.frag`);
char* filep = toStringz(file);
glShaderSource(f, 1, &filep,null);



erm.. ok, thanks :)
Thought I tried this already.
But, how is filep now an char** ? 


It's not filep that's a char**, it's &filep. You're taking the address 
of a pointer, so you end up with a pointer to a pointer.


If this code doesn't work, then something else is the matter.


Re: GLchar** problem

2008-10-30 Thread torhu

Saaa wrote:
glshaderSource needs a GLchar** and all I get from cast(char[]) 
read(filename) is a single *


How do I get this extra pointer ? :D

The C code is:

char *file;
shader = glCreateShader(GL_FRAGMENT_SHADER);
file = textFileRead("program.frag");
const char * filep = file;
glShaderSource(f, 1, &filep,NULL);
free(filep);

my D attempt:

char[] file;
GLuint shader;
shader=glCreateShader(GL_FRAGMENT_SHADER);
file=cast(char[])read(`program.frag`);
glShaderSource(f, 1, cast(char **) toStringz(file),null);
//let gc collect file

Error: Access Violation :)




Assuming the C code works, here's what you do in D.

GLuint shader;
shader=glCreateShader(GL_FRAGMENT_SHADER);
char[] file=cast(char[])read(`program.frag`);
char* filep = toStringz(file);
glShaderSource(f, 1, &filep,null);



Re: linker errors with class

2008-10-26 Thread torhu

Mike Parker wrote:
...

Denis Koroskin wrote:
No, it shouldn't. You may implement function bodies in other modules 
and/or languages (in C, for example, just make sure names have proper 
mangling).


Right, but it just feels wrong to me for constructors & destructors 
since they are a required part of the class. Either you implement one or 
you don't, but simply declaring one without an implementation feels like 
an error to me.


Without this feature, .di files wouldn't work.  The advantage is that 
functions without bodies are faster for the compiler to parse, when it 
it's not going to compile them anyway.  You can also use it for hiding 
implementation, if you don't want your source to be available.