Neko Dlls in Haxe C ++ target

I am trying to use a Neko DLL (written in C ++) with a C ++ target for Haxe. I can call functions in haxe but cannot pass values.

This is C ++ code -

value Hello(value h)
{
    cout << val_int(h);
    return val_int(1);
}DEFINE_PRIM(Hello, 1);

This is the Haxe code -

class Main
{
     var load = cpp.Lib.loadLazy( "ndll" , "Hello", 1 );
     static function main()
     {
          load(1);
     }
 }

It is executed only if the function does not accept parameters. In addition, the value returned by the C ++ function for Haxe is equal null.

This code works fine when I compile for the neko target, but it does not work with the cpp target.

Any help is appreciated.

+3
source share
2 answers

For this to work, you need to add the cpp file header:

#define IMPLEMENT_API
#include <hx/CFFI.h>

(instead of neko headers) If you want ndll to run on both neko and hxcpp, you should also add

#define NEKO_COMPATIBLE

before including hx / CFFI.h.

, , , Build.xml ndll, include lib hxcpp. Build.xml: http://pastebin.com/X9rFraYp

hxcpp CFFI : http://haxe.org/doc/cpp/ffi

+1

++:

#define IMPLEMENT_API

/* Will be compatible with Neko on desktop targets. */
#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
    #define NEKO_COMPATIBLE
#endif

#include <hx/CFFI.h>
#include <stdio.h>

/* Your hello function. */
value hello(value h)
{
    printf("%i\n", val_int(h));
    return alloc_int(1);
}
DEFINE_PRIM(hello, 1);

/* Main entry point. */
extern "C" void mylib_main()
{
    // Initialization code goes here
}
DEFINE_ENTRY_POINT(mylib_main);

, , , value. .

val_int value C, . : C int, , value Haxe. Haxe int . alloc_int.

Haxe :

class Main
{
    static var hello = cpp.Lib.load("myLib", "hello", 1);

    static function main()
    {
        var myReturnedInt:Int = hello(1);
    }
}

:

+8

All Articles