Comments (3)
Just for an update, I've figured out how to mix the old C API with the new more limited Swift-specific APIs. I haven't yet made sure I'm not leaking memory, but it looks like I've found what I needed, hopefully.
In case you ever wanted to know:
@objc protocol JSMemoryExports: JSExport {
// note that I'm returning an optional
static func Uint8ArrayMake(_ count : JSValue) -> JSValue?
}
class JSMemory: NSObject, JSMemoryExports {
class func UInt8ArrayMake(_ count : JSValue) -> JSValue? {
guard !count.isUndefined && !count.isNull else {
return nil
}
let ref : JSValueRef = JSObjectMakeTypedArray(
JS_Controller.js.ctx.jsGlobalContextRef!,
kJSTypedArrayTypeUint8Array,
Int(count.toInt32()),
nil
)!
// if you want to modify the data
// let ptr = JSObjectGetTypedArrayBytesPtr(
// JS_Controller.js.ctx.jsGlobalContextRef!, ref, nil
// )
return JSValue(jsValueRef: ref, in: JS_Controller.js.ctx)
}
}
from ejecta.
I'm sorry, I don't think I can help you much. I don't know anything about Swift and very little about JSC's newer APIs.
Are you sure the APIs supports exporting static class methods? A quick google search at least returned an article that explains how to bind a Swift class and instantiate it in JS - with instance methods and all: https://nshipster.com/javascriptcore/
Just for reference, the EJ_BIND_*
macros define a static objc class method that returns a function pointer to the actual implementation (the body of the macro), that is later collected by EJClassLoader and handed over to JSCs JSClassCreate()
. EJClassLoader (and all the rest of Ejecta) uses JSCs older C API, listed here under Legacy JavaScriptCore APIs, not the newer ObjC API.
from ejecta.
Hmmm, yes I'm sure that static functions are supported. The link you have there shows the following:
// Protocol must be declared with `@objc`
@objc protocol PersonJSExports: JSExport {
var firstName: String { get set }
var lastName: String { get set }
var birthYear: NSNumber? { get set }
var fullName: String { get }
// Imported as `Person.createWithFirstNameLastName(_:_:)`
static func createWith(firstName: String, lastName: String) -> Person
}
That is basically what I am doing. I've found several examples online of passing back and forth custom classes, but none showing how to pass raw data such as a TypedArray or JSValueRef, which is what seems to cause issues.
So now I'm wondering what the proper way of passing byte data back and forth without copying is. It's admittedly frustrating not to see any real examples of this.
Also, I wasn't aware that there WAS a newer Objective C API. Everything's bunched together. It's possible that I'm mixing some old and new API functionality in some invalid way.
from ejecta.
Related Issues (20)
- Errors with In App Purchases - purchasing, restoring purchases, etc
- how can I use ejecta in nativescript?
- EXC_BAD_ACCESS Error (on iOS) when using Stream HOT 1
- Font weight not supported HOT 1
- Ballistic Defence - Available on App Store
- Future of Ejecta revisited in 2019 HOT 5
- IAPManager - no response & no error message
- html element combination HOT 1
- Does Ejecta support tvOS 13? HOT 3
- Why not use <JSExport> protocol to bind API? HOT 5
- Legacy ImpactJS HOT 8
- Can't build version 2.0 for iOS9 device when using xcode11.
- (2020)Can this project still run in Tvos?
- force the user to swipe twice to open notification center HOT 1
- Callback function problem with sandbox test user (IAP) HOT 2
- background image in main.js does not show in latest Ejecta version
- Black screen
- Gamepad support no longer working on tvOS simulator HOT 1
- Community effort for Metal support HOT 1
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 ejecta.