Raefaldhi Amartya
Raefaldhi Amartya

Reputation: 73

Array of struct in C to D

So i've tried to make my own PAWN sdk for D Programming Language, i know there are already PAWN sdk for D but i just want to try to make it by myself.

I got strange problem when i convert this C code to D:

struct tagAMX;
typedef cell (*AMX_NATIVE)(struct tagAMX *amx, cell *params);

typedef struct tagAMX_NATIVE_INFO {
const char *name;
AMX_NATIVE func;
} AMX_NATIVE_INFO;

And i've convert it to D code:

struct AMX;
alias AMX_NATIVE = cell function(AMX* amx, cell* params);

struct AMX_NATIVE_INFO {
    immutable(char)* name;
    AMX_NATIVE func;
}

Do i wrote it right?, if that code look fine, just ignore it.

The main problem is here: in C

AMX_NATIVE_INFO PluginNatives[] =
{
    {"HelloWorld", HelloWorld},
    {0, 0}
};

How do i write that on D? i tried with:

AMX_NATIVE_INFO[] NativeInfo =
[
    ["HelloWorld", HelloWorld],
    [0, 0] 
];

It just give me error:

function test.HelloWorld (AMX* amx, int* params) is not callable using argument types ()
cannot implicitly convert expression ([0, 0]) of type int[] to AMX_NATIVE_INFO

Upvotes: 2

Views: 116

Answers (1)

sigod
sigod

Reputation: 6486

Try

AMX_NATIVE_INFO[] NativeInfo =
[
    AMX_NATIVE_INFO("HelloWorld", &HelloWorld),
    AMX_NATIVE_INFO(null, null)
];

or

AMX_NATIVE_INFO[] NativeInfo =
[
    {"HelloWorld", &HelloWorld},
    {null, null}
];

Read this for more details on structs.

Upvotes: 4

Related Questions