[jsc-dev] How to use JSExport and JavascriptCore in C++

Alexis Barra alexis.barra at gmail.com
Thu Oct 26 09:27:13 PDT 2017


I found this article in the internet that was a great help to start coding.

https://karhm.com/JavaScriptCore_C_API/



On 25 October 2017 at 17:19, Alexis Barra <alexis.barra at gmail.com> wrote:

> I'm thinking on JavaScriptCore’s C API .. Do you have an idea how
> to tackle it? I'm checking the API at this moment but I'm not clear how to
> use it.
>
> On 25 October 2017 at 16:53, Geoffrey Garen <ggaren at apple.com> wrote:
>
>> Hi Alexis.
>>
>> You’ll either need to convert your C++ objects to Objective-C objects,
>> wrap your C++ objects in Objective-C objects, or use JavaScriptCore’s C API.
>>
>> Regards,
>> Geoff
>>
>> On Oct 25, 2017, at 4:39 PM, Alexis Barra <alexis.barra at gmail.com> wrote:
>>
>> I'm working with JavascriptCore in a C++ project and I don't know how to
>> expose a C++ class to javascript. For example in Objective-C is something
>> like this:
>>
>> @protocol MyPointExports <JSExport>@property double x;@property double y;- (NSString *)description;- (instancetype)initWithX:(double)x y:(double)y;+ (MyPoint *)makePointWithX:(double)x y:(double)y;@end
>> @interface MyPoint : NSObject <MyPointExports>- (void)myPrivateMethod;  // Not in the MyPointExports protocol, so not visible to JavaScript code. at end
>> @implementation MyPoint// ... at end
>> JSContext *context = [[JSContext alloc] init];
>> // export MyPoint class
>> context[@"MyPoint"] = [MyPoint class];
>>
>> But I have not idea how to translate JSExport and protocol into C++.
>>
>> --
>> Alexis Barra.
>>
>> _______________________________________________
>> jsc-dev mailing list
>> jsc-dev at lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/jsc-dev
>>
>>
>>
>
>
> --
> Alexis Barra.
>
>


-- 
Alexis Barra.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/jsc-dev/attachments/20171026/cf2bb776/attachment-0001.html>


More information about the jsc-dev mailing list