Comments (8)
I have started documenting things here https://github.com/HaxeFoundation/hashlink/wiki
Tell me if you have more questions, I'll add more documentation as I get more questions ;)
from hashlink.
This is something I'm keen to do too, I'll planning to have go at it over the weekend
It'll be good to hear what @ncannasse 's thoughts are on this - if there's mechanism how this is handled already or if it's an area to investigate (I'm keen to contribute here if I can!)
A hack in the short term might be to just look at the C function signatures generated by haxe and call those directly from your C code - if you search through the generated C source code you'll find a function that corresponds to test(foo:Int)
(just not with exactly the same name!)
However, for a more robust solution you'd want to control how those signatures are generated, perhaps in a similar way the @:expose
metadata is used for the javascript target.
from hashlink.
I did a small investigation, and if I understood correctly, it's impossible to call function by name, because functions stored by function id. So we should store name of functions in sort of key-value storage.
The solution that I use now, to call haxe functions from native code, is that I'm passing a pointer to a function and than just call it. It's more hack than a real solution
from hashlink.
Btw, is it possible to create hl native function at runtime? To avoid module loading(I don't wanna one more dll)
from hashlink.
A Haxe function would be represented as a vclosure*
on C side. You can call it dynamically with hl_dyn_call
. ATM there is no way for the C code to "resolve" a function from its path. You will have to pass it from Haxe to C by doing something such as registerFunction(Test.test) which can store the vclosure and reuse it later.
You also need to store it in some root if you don't want it to be GC'ed
from hashlink.
One other solution to implement such method resolution is to do write the following:
function resolveStaticMethod( className hl.Bytes, methodName : hl.Bytes ) : Dynamic {
var c = Type.resolveClass(@:privateAccess String.fromUTF8(bytes));
return Reflect.field(c, @:privateAccess String.fromUTF8(methodName));
}
You can then share this method to C
from hashlink.
A Haxe function would be represented as a vclosure* on C side. You can call it dynamically with hl_dyn_call.
I do use vclosure->fun pointer to avoid hl_dyn_call, is it ok?
It's probably not safe, but it should be faster
You also need to store it in some root if you don't want it to be GC'ed
how is it can be done? and how is the memory can be prevented from being GC'ed?
And what is the differences between hl_gc_alloc_noptr
, hl_gc_alloc
and hl_gc_alloc_dyn
?
@ncannasse btw, when the new HashLink in depth blogpost will be released? 👍
from hashlink.
Also want to know what is the differences between hl_gc_alloc_noptr, hl_gc_alloc, hl_gc_alloc_raw
?
from hashlink.
Related Issues (20)
- macOS libhl.dylib path causes crash HOT 1
- The Hashlink profiler causes an exception in Process.stdout.readLine
- The Hashlink GC can block the main thread if sys.thread.Thread is used HOT 1
- Get live objects from a specific type
- JIT ERROR 0 mixing hl.UI8 and Float HOT 2
- Explicit constant Float to Int type conversion HOT 1
- Game controller not recognized HOT 10
- --debug is faster to run than non debug. HOT 2
- HL thread hangs when using trace() and semaphores HOT 2
- Can't run any .hl file on Mac M1 - Segmentation Fault HOT 2
- Unexpected value conversion when using an abstract class with type param
- Any way to get hl.Bytes from an hl.NativeArray? HOT 1
- Single and hl.F32 function args for callMethod stack issue HOT 1
- With SDL backend on Windows, adding an element to a SpriteBatch can cause a large lag spike HOT 2
- src/module.c(567) : FATAL ERROR : Failed to load function sdl@gl_polygon_offset HOT 3
- Macbook M1 Support HOT 2
- JIT/VM calls incorrect method HOT 3
- Unable to build C output on Windows gcc HOT 2
- Hashlink access violation/segfault, when abstract is used as inerface HOT 11
- Warnings when compiling mysql module (implicit declaration of function `gethostbyname_r`) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashlink.