Hi,

I've changed strategy, and now I have made a small wrapper DLL which exposes
a simple API for neko.

Here is the wrapper header:

  // Opens a neko file - returns 0 if succesful.
  __declspec( dllexport ) int neko_init_simpleapi(char const * filename);

  // Calls a static function taking a string, returning a string, using
haXe ABI
  __declspec( dllexport ) char const * neko_static_haxe_call(char const *
className, char const * functionName, char const * parameter);

where neko_static_haxe_call looks like this:

__declspec( dllexport ) char const * neko_static_haxe_call(char const *
className, char const * functionName, char const * parameter) {
   value f;
   value ret;
   value classes;
   value myClass;
   value args[1];
   value exc = NULL;
   char * exception;

   if (vm == 0 || module == NULL) {
       printf("No module loaded\n");
       return NULL;
   }

   classes = val_field(module, val_id("__classes"));
   myClass = val_field(classes, val_id(className));
   f = val_field(myClass, val_id(functionName));
   if ( !val_is_function(f,1)) {
       return NULL;
   }
   args[0] = alloc_string(parameter);
   ret = val_callEx(NULL, f, args, 1, &exc);
   if( exc != NULL ) {
       buffer b = alloc_buffer(NULL);
       val_buffer(b,exc);
       exception = val_string(buffer_to_string(b));
       printf("Uncaught exception - %s\n", exception);
       return NULL;
   }
   if( !val_is_string(ret) )
        return NULL;
   return val_string(ret);
}

I use a simple haXe program like this:

class Test {
   static public function main() {
       neko.Lib.println("Hello world!");
   }

   static public function myFunction(a : String) : String {
       neko.Lib.println("Calling myFunction: " + a);
       if (a.length < 2) {
           return "Short";
       } else {
           return "Long";
       }
   }
}

with the driver being:

#include <stdio.h>

#include "../neko_wrapper/simpleapi.h"

int main( int argc, char *argv[] ) {

   char * result;
   neko_init_simpleapi("Test.n");
   result = neko_static_haxe_call("Test, "myFunction", "Testing");
   printf("Result: %s\n", result);
   return 0;
}

When I run this, it prints "Hello world" as expected, but it throws an
exception at the line with a.length: Invalid field access : length.

If I run the haXe program with neko directly, there is no such problem.

Any ideas?

I can prepare a .zip with all files, if you want to investigate.

Regards,
Asger
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to