Skip to content

Commit dbbd918

Browse files
committed
work
1 parent 0b092b5 commit dbbd918

19 files changed

Lines changed: 167 additions & 26 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ deno.lock
55
package-lock.json
66
node_modules/
77
NativeScript for macOS.app/
8+
/napi.c
9+
/napi.js
10+
/napi.node
11+
*.dylib

‎include/bridged_class.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class BridgedClass {
1515
napi_ref constructor;
1616
napi_ref prototype;
1717

18+
BridgedClass() {}
1819
BridgedClass(napi_env env, std::string name);
1920
};
2021

‎include/class.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "node_api_util.h"
55
#include "stdlib.h"
66

7+
NAPI_FUNCTION(registerClass);
78
NAPI_FUNCTION(getClass);
89

910
#endif /* class_h */

‎include/node_api_util.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
status = expr; \
3535
if (status != napi_ok) { \
3636
NAPI_ERROR_INFO \
37-
NSLog(@"Node-API returned error: %d\nException: %s\n\n %s\n ^^^^\n\n " \
38-
@"at %s:%d", \
39-
status, error_info->error_message, #expr, __FILE__, __LINE__); \
37+
std::cout << "Node-API returned error: " << status \
38+
<< "\nException: " << error_info->error_message << "\n\n " \
39+
<< #expr << "\n ^^^^\n\n " \
40+
<< "at " << __FILE__ << ":" << __LINE__ << std::endl; \
4041
} \
4142
if (status != napi_ok)
4243

@@ -55,7 +56,7 @@
5556
napi_value JS_##name(napi_env env, napi_callback_info cbinfo)
5657

5758
#define NAPI_FUNCTION_DESC(name) \
58-
{ #name, NULL, JS_##name, NULL, NULL, NULL, napi_default, NULL }
59+
{ #name, NULL, JS_##name, NULL, NULL, NULL, napi_enumerable, NULL }
5960

6061
static inline napi_ref make_ref(napi_env env, napi_value value) {
6162
napi_ref ref;

‎include/objc_bridge_data.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ObjCBridgeData {
2626
BridgedClass *getBridgedClass(napi_env env, std::string class_name);
2727
MethodCif *getMethodCif(Method method);
2828
napi_value getObject(napi_env env, id object);
29+
void registerClass(napi_env env, napi_value constructor);
2930
};
3031

3132
#endif /* OBJC_BRIDGE_DATA_H */

‎include/type_conv.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#ifndef type_conv_h
99
#define type_conv_h
1010

11+
#include "ffi.h"
1112
#include "node_api.h"
1213
#include "objc/runtime.h"
1314
#include <iostream>
1415

15-
typedef napi_value (*js_from_native)(napi_env, void *);
16+
typedef napi_value (*js_from_native)(napi_env, void *, ffi_type *);
1617
typedef void (*js_to_native)(napi_env, napi_value, void *, bool *, bool *);
1718
typedef void (*js_free)(napi_env, void *);
1819

@@ -21,7 +22,7 @@ js_to_native getConvToNative(const char *encoding);
2122
js_free getNativeFree(const char *encoding);
2223

2324
#define JS_FROM_NATIVE(name) \
24-
napi_value js_from_##name(napi_env env, void *value)
25+
napi_value js_from_##name(napi_env env, void *value, ffi_type *type)
2526
#define JS_TO_NATIVE(name) \
2627
void js_to_##name(napi_env env, napi_value value, void *result, \
2728
bool *shouldFree, bool *shouldFreeAny)

‎index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ const classes = new Proxy({}, {
1010
},
1111
});
1212

13-
export { classes, classes as default, objc };
13+
export { classes, objc };
14+
export * from "./inline_functions.js";

‎inline_functions.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function NSMakeRect(x, y, width, height) {
2+
return new Float64Array([x, y, width, height]);
3+
}
4+
5+
export function NSMakeSize(width, height) {
6+
return new Float64Array([width, height]);
7+
}

‎metadata/deps.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "https://raw.githubusercontent.com/DjDeveloperr/clang_metagen_deno/work/mod.ts";

‎metadata/main.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { generateFrameworkMetadata } from "./deps.ts";
2+
3+
const _metadata = generateFrameworkMetadata({
4+
framework: "Foundation",
5+
sdk:
6+
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk",
7+
});

0 commit comments

Comments
 (0)