Djinni 是一个用来生成跨语言的类型声明和接口绑定的工具,主要用于 C++ 和 Java 以及 Objective-C 间的互通。
示例接口定义文件:
1 # Multi-line comments can be added here. This comment will be propagated 2 # to each generated definition. 3 my_enum = enum { 4 option1; 5 option2; 6 option3; 7 } 8 9 my_record = record { 10 id: i32; 11 info: string; 12 store: set<string>; 13 hash: map<string, i32>; 14 15 values: list<another_record>; 16 17 # Comments can also be put here 18 19 # Constants can be included 20 const string_const: string = "Constants can be put here"; 21 const min_value: another_record = { 22 key1 = 0, 23 key2 = "" 24 }; 25 } 26 27 another_record = record { 28 key1: i32; 29 key2: string; 30 } deriving (eq, ord) 31 32 # This interface will be implemented in C++ and can be called from any language. 33 my_cpp_interface = interface +c { 34 method_returning_nothing(value: i32); 35 method_returning_some_type(key: string): another_record; 36 static get_version(): i32; 37 38 # Interfaces can also have constants 39 const version: i32 = 1; 40 } 41 42 # This interface will be implemented in Java and ObjC and can be called from C++. 43 my_client_interface = interface +j +o { 44 log_string(str: string): bool; 45 }
使用方法:
1 @import "relative/path/to/filename.djinni"
github地址:https://github.com/dropbox/djinni
时间: 2024-11-02 03:33:31