@:lib("m")
class NativeMath extends ffi.lib.EasyLibrary {
public function cos(x:Float):Float;
public function tan(x:Float):Float;
public function sin(x:Float):Float;
public function acos(x:Float):Float;
public function atan(x:Float):Float;
public function asin(x:Float):Float;
public function sqrt(x:Float):Float;
public function cbrt(x:Float):Float;
public function pow(x:Float, y:Float):Float;
public function round(x:Float):Float;
public function llround(x:Float):Int64;
}
@:struct(Person => {
var name:String;
var age:UInt16;
})
@:lib("test/test.so")
class Tests extends ffi.lib.EasyLibrary {
public function make_person(name:String, age:UInt16):Pointer;
}
...
var person:Person = t.make_person("Tom", 234).get(Person.TYPE);
new Person("Bobaffet", 23);
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
@back2dos
I got curious into how HxSL did it. It's hacky, but pretty.
Also, that's what 'get' does, but 'getValue' is meant to get the pointer as a Neko value. I'll rename it to getAsNekoValue to make it clearer. It's only really there because it can be and it will be useful for the future.
For example -- @Cauê -- could this be used to make to port the native webview for Croxit desktop across Windows/Mac/Linux?
Struct<String, UInt16>
@:structs([
CString => String,
Person => {
var name:CString;
var age:UInt16;
},
Player => {
var nick:CString;
var score:UInt;
}
])
I am reliant on this library and this feature is broken. If anyone has any idea on what is causing this, please, please, please specify. Relevent ExternalInterface.ccp portion:
case FFI_TYPE_STRUCT: {
const unsigned int size = t -> size;
uintptr_t v = (uintptr_t) malloc(size);
ffi_type** elem = t -> elements;
unsigned int i = 0;
while(*elem != NULL) {
const ffi_type* curr = *elem;
const size_t size = curr -> size;
uintptr_t nptr = (uintptr_t) to_pointer(val_array_i(val, i), *elem);
memcpy((void*) v, (void*) nptr, size);
v += size;
elem++;
i++;
}
return (void*) v;
}
As you can imagine all of the segfault have been quite vexxing.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int i;
} St_n;
char* test(St_n st) {
char res[1024];
sprintf(res,"st %d",st.i);
return res;
}
package;
import ffi.lib.EasyLibrary;
@:struct(St_n=>{
var i:Int;
})
@:lib("libntv.so")
class Ntv extends EasyLibrary {
public static function main():Void {
var lib:Ntv=new Ntv();
trace(lib.test(new St_n(100)));
}
public function test(st:St_n):String;
}