Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the fully corrected C++ code :</p> <pre><code>#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 &lt;hx/CFFI.h&gt; #include &lt;stdio.h&gt; /* 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); </code></pre> <p>What's important is that every value given as an argument to a primitive or returned by a primitive must be of the type <code>value</code>. That's why your parameter and return didn't work.</p> <p><code>val_int</code> is used to convert a <code>value</code> into a native C type, so your printing code was correct. But your return was wrong : you can't return a C <code>int</code> type when the function expects you to return a <code>value</code> to Haxe. You need to create a new Haxe <code>Int</code> type and return it. This is done with the help of <code>alloc_int</code>.</p> <p>Here's the Haxe part of the code as a reference :</p> <pre><code>class Main { static var hello = cpp.Lib.load("myLib", "hello", 1); static function main() { var myReturnedInt:Int = hello(1); } } </code></pre> <p>A few helpful links :</p> <ul> <li><a href="http://nekovm.org/doc/ffi">Neko C FFI</a></li> <li><a href="http://haxe.org/doc/neko/ffi">Neko FFI tutorial</a></li> <li><a href="http://haxe.org/doc/cpp/ffi">CPP FFI notes</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload