当前位置:网站首页>New d reflection generates ABI of C for class
New d reflection generates ABI of C for class
2022-06-29 04:50:00 【fqbqrr】
mixin template CWrapper(Type) {
import std.traits;
export extern(C):
pragma(mangle, "create_" ~ __traits(identifier, Type))
void* creator(Parameters!(Type.__ctor) args) {
return cast(void*)new Type(args);
}
mixin(() {
string ret;
foreach(m; __traits(allMembers, Type)) {
static if (m != "__ctor" && m != "__dtor" && isFunction!(__traits(getMember, Type, m))) {
ret ~= `ReturnType!(__traits(getMember, Type, "` ~ m ~ `")) ` ~ __traits(identifier, Type) ~ `_` ~ m ~ `(void* obj, Parameters!(__traits(getMember, Type, "` ~ m ~ `")) args) { return (cast(Type)obj).` ~ m ~ `(args); }`;
}
}
return ret;
}());
}
class Foo {
int x;
this(int x) { this.x = x; }
int getX() { return x; }
}
mixin CWrapper!(Foo);
// GENERATED CODE:
extern(C) {
void* create_Foo(int); // returns void* to Foo instance
int Foo_getX(void*); // takes void* to Foo instance
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
by arbitrarily D class Generate C Of ABI.
边栏推荐
- Open a new ecological posture | use WordPress remote attachment to store to Cos
- Test content
- Airflow 2.2.3 containerized installation
- [code Capriccio - dynamic planning] longest common subsequence
- Cucumber test practice
- Complete collection of necessary documents for project management: you can't write these 14 project documents yet?
- Mediator pattern
- 仿真与烧录程序有哪几种方式?(包含常用工具与使用方式)
- 轻松入门自然语言处理系列 专题7 基于FastText的文本分类
- Composite pattern
猜你喜欢

Complete collection of necessary documents for project management: you can't write these 14 project documents yet?

Iterator pattern

Untitled

See how I do it step by step (I)

笔记本访问台式机的共享磁盘

Memo pattern

How to quickly change the database name in MySQL

泰克TDS3054B示波器技术指标

Live broadcast appointment AWS data everywhere series activities

What are the MySQL database constraint types
随机推荐
Satellite navigation time service related terms Collection Edition
Research Report on the overall scale, major manufacturers, major regions, products and applications of power battery laser welding machines in the global market in 2022
Visitor pattern
How to use the select statement of MySQL
[code random entry - hash table] T15, sum of three numbers - double pointer + sort
Gbase 8s must be a DBSA. Solution to failure to start due to path change
What are the ways to simulate and burn programs? (including common tools and usage)
Domain name hack
LabVIEW displays Unicode characters
【代码随想录-动态规划】最长公共子序列
Memo pattern
How to write MySQL scheduled backup script in Linux
20年秦皇島D - Exam Results(二分+思維,附易錯數據)
2022-2028 global and Chinese industrial digital electronic blasting detonator Market Status and future development trend
Easy to get started naturallanguageprocessing series topic 7 text classification based on fasttext
How to test electronic components with a multimeter
Use typescript compiler parameter 'skiplibcheck' - usage of the typescript compiler argument'skiplibcheck'
Research Report on the overall scale, major manufacturers, major regions, products and application segments of 5g modules of the Internet of things in the global market in 2022
Proxy mode (proxy)
Cloud native annual technology inventory is released! Ride the wind and waves at the right time