Thread overview
ImportC is becoming usable for some things
Oct 22, 2023
Imperatorn
Oct 25, 2023
Adam Wilson
Oct 25, 2023
Imperatorn
October 22, 2023

Let's take a look at a simple example (this example is without using .di-files):
https://github.com/Mashpoe/c-hashmap

Clone it and put the files somewhere convenient.

Now, let's try using it.

In this example map.c and app.d are located in the same directory.

import std.stdio : writeln;

// Use map.c
import map;

import std.string : toStringz;

alias c = toStringz;

void main()
{
	hashmap* m = hashmap_create();

	string key = "hello";

	hashmap_set(m, key.c, key.length, 400);

	uintptr_t result;

	if (hashmap_get(m, key.c, key.length, &result))
	{
		writeln(key, " = ", cast(int) result);
	}
	else
	{
		writeln("Could not locate entry ", key);
	}
}

If you have your paths setup correctly, you can now run

dmd map.c app.d

dmd has now produced an executable. Run it and see the results.

ImportC

Nice. Now if we also could get autocompletion etc it would be even better. It's probably possible with some tweaks already, but I didn't look into it.

October 25, 2023

On Sunday, 22 October 2023 at 17:29:49 UTC, Imperatorn wrote:

>

Let's take a look at a simple example (this example is without using .di-files):
https://github.com/Mashpoe/c-hashmap

[...]

Auto-complete works if you can build a DI file out of it.

October 25, 2023

On Wednesday, 25 October 2023 at 00:33:03 UTC, Adam Wilson wrote:

>

On Sunday, 22 October 2023 at 17:29:49 UTC, Imperatorn wrote:

>

Let's take a look at a simple example (this example is without using .di-files):
https://github.com/Mashpoe/c-hashmap

[...]

Auto-complete works if you can build a DI file out of it.

Yeah, it works. Would just be nice.