Binding Help

Started by gudenau, August 20, 2017, 02:27:18

Previous topic - Next topic

spasi

Yes. Examples:

// C
typedef struct libusb_foo libusb_foo;
void func(libusb_foo *foo);
// Kotlin
val libusb_foo_p = "libusb_foo".p

// C
typedef struct libusb_foo *libusb_foo;
void func(libusb_foo foo);
// Kotlin
val libusb_foo = "libusb_foo".opaque_p

gudenau

Quote from: spasi on October 03, 2017, 08:43:38
Yes. Examples:

// C
typedef struct libusb_foo libusb_foo;
void func(libusb_foo *foo);
// Kotlin
val libusb_foo = "libusb_foo".p

// C
typedef struct libusb_foo *libusb_foo;
void func(libusb_foo foo);
// Kotlin
val libusb_foo = "libusb_foo".opaque_p


Would the first example then be:
// C
void doAThing(libusb_thing* thing);

// Kotlin
void("doAThing", ""
    
    libusb_thing.IN("thing", "")
)
[code]

or

[code]
// C
void doAThing(libusb_thing* thing);

// Kotlin
void("doAThing", ""
    
    libusb_thing.p.IN("thing", "")
)
[code]

I am leaning towards the first, but I am unsure.

spasi

I've edited my previous reply, it should be:

val libusb_foo_p = "libusb_foo".p // note the extra _p


So, in your example:

// C
typedef struct libusb_thing libusb_thing;
void doAThing(libusb_thing* thing);

// Kotlin
val libusb_thing_p = "libusb_thing".p
void(
    "doAThing",
    "",

    libusb_thing_p.IN("thing", "")
)


So, yes, the first one, but with _p so that it's clear what's happening.

gudenau

Quote from: spasi on October 03, 2017, 16:50:31
I've edited my previous reply, it should be:

val libusb_foo_p = "libusb_foo".p // note the extra _p


So, in your example:

// C
typedef struct libusb_thing libusb_thing;
void doAThing(libusb_thing* thing);

// Kotlin
val libusb_thing_p = "libusb_thing".p
void(
    "doAThing",
    "",

    libusb_thing_p.IN("thing", "")
)


So, yes, the first one, but with _p so that it's clear what's happening.

Fair enough, now to look at the other bindings and get the native stuff working.

gudenau

Issue with the build process, it is attempting to grab a required dll from your server. Seeing as the binding is not done how can I tell it to not do that and maybe even grab it from a local source?

spasi

Setting/exporting LWJGL_BUILD_OFFLINE=true will make the build skip all downloads.

gudenau

Okay, mostly done with this. Just need to make sure all the documentation is in there, compare the code styling I used to the repo, test all the stuff I can, and maybe make some basic tests and port the example code.

Probably a couple more days, everything is well documented and has links to everything else that is relevant.

gudenau

Odd problem, checks are happening where they should not be for a function.

I have tried this:
    size_t(
        "libusb_get_device_list", "",

        optional..libusb_context_p.IN("ctx", ""),
        Check("1")..libusb_device_p.p.p.OUT("list", "")
    )


and this

    size_t(
        "libusb_get_device_list", "",

        nullable..libusb_context_p.IN("ctx", ""),
        Check("1")..libusb_device_p.p.p.OUT("list", "")
    )


A null ctx tells the library to use the default one.

spasi

nullable.. should remove the check.

edit: btw, you can do Check(1) instead of Check("1").

gudenau

Quote from: spasi on October 04, 2017, 20:26:49
nullable.. should remove the check.

edit: btw, you can do Check(1) instead of Check("1").

I'll double check that I did not mess that up then, and I will change all of those Check statements.

Edit:
Seems that it was just me being stupid like normal. Go figure.

gudenau

It has been a while, things came up and this ended up being forgotten for a while. My bad.

Now that I am trying to get the documentation fleshed out I am not seeing a way to add the return info to a method definition in the Kotlin files. Is this supported?

Edit:
While I am at it, is the See Also stuff supported?

spasi

The generator supports @return, @see and @since. You use Kotlin named parameters to specify them, for example:

int(
    "functionName",
    "javadoc",

    // vararg parameters
    int.IN("paramA", ""),
    float.IN("paramB", ""),
    // ...,

    // named parameters after varargs
    returnDoc = "an int",
    since = "version M.n",
    see = arrayOf("refA", "refB"/* , ... */)
)

gudenau

Quote from: spasi on December 06, 2017, 08:38:39
The generator supports @return, @see and @since. You use Kotlin named parameters to specify them, for example:

int(
    "functionName",
    "javadoc",

    // vararg parameters
    int.IN("paramA", ""),
    float.IN("paramB", ""),
    // ...,

    // named parameters after varargs
    returnDoc = "an int",
    since = "version M.n",
    see = arrayOf("refA", "refB"/* , ... */)
)


Thanks, I went through all the decelerations and could not find those.

gudenau

How about deprecation? There is a deprecated method in here that is superseded by something else.

spasi

I usually skip such functions. If we need it in the future for backwards compatibility, it can be added trivially.