Comments (8)
Yes, this is a documentation issue because it is probably never going to work as you had hoped.
I am putting together a talk about this sort of thing for wwx2014, so hopefully I can make this clearer.
from hxcpp.
I have been using @:functionCode a lot... I'm pretty much doing all native extensions through it. It works really well, apart from this small hickup.
Being able to inline c++ code to achieve native performance is really the way to go, and it was a decisive factor for me in using the platform. I hope it continues to be supported somehow! Great job! 👍
from hxcpp.
Should I leave it open? maybe as a reminder to document it?
from hxcpp.
There is a workaround:
public inline function printSomethingInline() {
untyped __cpp__('printf("something inline!\\n");');
}
And in fact I prefer this over @:functionCode
as it is more flexible.
from hxcpp.
Indeed, I understand the metadata on type level, but it seems a bit strange at method level.
from hxcpp.
Hmm, I didn't know about that @andyli ! Very useful! Thanks!
from hxcpp.
Yeah, the @FunctionCode may become deprecated soon, as better solutions emerge.
You still have a big problem with inline functions and arg names. eg:
inline funciton x(aaa:Int) { __cpp__('printf("%d",aaa);')__; }
x(1234)
You will get an error about 'aaa' not being defined, because it is treated as a string. Maybe some macro magic could work now - I am open to suggestions here.
The solution, which may event work today, is to define a "c++" inline function, which the haxe compiler either does not know about, or thinks is "extern". This can be done by injecting at the cpp file or include level. You can then call this, using untyped or extern, and the c++ compiler will inline it for you in the way that c++ compilers do (not the haxe compiler). I will be putting together some stuff for wwx about this.
I will close it now and work on sorting out the best solution. I am also interested in your specific use-cases, so these can be covered too.
from hxcpp.
@hughsando , one way to deal with the problem you mentioned above is to support the following:
inline function x(aaa:Int) { untyped __cpp__('printf("%d",{1};', aaa); }
On the OCaml side, every time you find that __cpp__
has more than one argument, {\d}
patterns will be replaced by their expr_s
conversion.
from hxcpp.
Related Issues (20)
- How to properly shutdown a hxcpp DLL?
- Casts inserted and I don't know why HOT 2
- FreeBSD, Could not find include file "toolchain/null-toolchain.xml" HOT 1
- Strange CPP error HOT 2
- Pointer_obj::ofArray changes length of empty array from 0 to 1
- Allow using system sqlite?
- Linking issue on HXCPP_MINGW under MSYS2 HOT 2
- Cannot have an array of pointers HOT 2
- hxcpp does not quote -I paths with spaces
- Explicitly allow c++14
- Abstract wrapping extern cannot find the extern
- thread count discrepancy in extern-use test
- @:generic ignores @:unreflective HOT 5
- Reflect.field(String, "fromCharCode") doesnt work
- Calling a method from an array of classes causes "this" to be null HOT 6
- Errors where function named Array returns Generic of Array
- Mac CI takes an age to run HOT 7
- HXCPP_CXX_STANDARD Define
- Conflicts when static linking a library that uses mbedtls HOT 2
- Unable to compile after reinstalling Visual Studio HOT 2
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 hxcpp.