cocos2d / cocos2d-js

cocos2d-x for JS
http://www.cocos2d-x.org
MIT License
1.86k stars 490 forks source link

How to call js from Objective-C? #1093

Closed IgorMats closed 9 years ago

IgorMats commented 9 years ago

Hi. Tell me please how to call javascript from Objective-C, because on the references page i did not found this information. Thanks.

jianglong0156 commented 9 years ago

I found a doc about call Objective-C functions using js, Is is useful? http://cocos2d-x.org/docs/manual/framework/html5/v3/reflection-oc/en

pandamicro commented 9 years ago

@jianglong0156 What @IgorMats want is the inverse. There is no direct way to call js from objective-c, you need to use C++ APIs. Please refer to ScriptingCore.h API.

IgorMats commented 9 years ago

@pandamicro not cool. Is this feature exists in road map?

pandamicro commented 9 years ago

In fact, it's quite simple, you can write a Objective-C class with a .mm file so that it can contain C++ code. In this way, you will be able to use ScriptingCore APIs

IgorMats commented 9 years ago

I got it! Thanks!