cocos2dx 自己主动绑定js

依照教程把全部资源下载好后.......

找到cocos2dx project下的tools/bindings-generator/test

发现里面有test.sh , test.ini , 去掉simple后缀后的user.cfg  , 与userconf.ini ; 把这四个文件里的路径都改为那些资源的路径

"test.sh"
# options

usage(){
cat << EOF
usage: $0 [options]

Test the C++ <-> JS bindings generator

OPTIONS:
-h	this help

Dependencies :
PYTHON_BIN
CLANG_ROOT
NDK_ROOT

Define this to run from a different directory
CXX_GENERATOR_ROOT

EOF
}

while getopts "dvh" OPTION; do
case "$OPTION" in
d)
debug=1
;;
v)
verbose=1
;;
h)
usage
exit 0
;;
esac
done

# exit this script if any commmand fails
set -e

# find current dir
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# read user.cfg if it exists and is readable

_CFG_FILE=$(dirname "$0")"/user.cfg"
if [ -e "$_CFG_FILE" ]
then
    [ -r "$_CFG_FILE" ] || die "Fatal Error: $_CFG_FILE exists but is unreadable"
    . "$_CFG_FILE"
fi

# paths

if [ -z "${NDK_ROOT+aaa}" ]; then
# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk"
    NDK_ROOT="/Users/tudu/Downloads/android-ndk-r9c"
fi

if [ -z "${CLANG_ROOT+aaa}" ]; then
# ... if CLANG_ROOT is not set, use "$HOME/bin/clang+llvm-3.1"
    CLANG_ROOT="/Users/tudu/Downloads/clang+llvm-3.1-x86_64-apple-darwin11"
fi

if [ -z "${PYTHON_BIN+aaa}" ]; then
# ... if PYTHON_BIN is not set, use "/usr/bin/python2.7"
    PYTHON_BIN="/usr/bin/python2.7"
fi

# paths with defaults hardcoded to relative paths

if [ -z "${CXX_GENERATOR_ROOT+aaa}" ]; then
    CXX_GENERATOR_ROOT="$DIR/.."
fi

echo "CLANG_ROOT: $CLANG_ROOT"
echo "NDK_ROOT: $NDK_ROOT"
echo "CXX_GENERATOR_ROOT: $CXX_GENERATOR_ROOT"
echo "PYTHON_BIN: $PYTHON_BIN"

# Generate bindings for simpletest using Android‘s system headers
echo "Generating bindings for simpletest with Android headers..."
set -x
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${CXX_GENERATOR_ROOT}/test/test.ini -s testandroid -o ./simple_test_bindings
"test.ini"
<pre name="code" class="plain">[testandroid]
name = simple_test
prefix = ttttttt
classes = testbang
cocosdir = /Users/tuyou/Downloads/cocos2d-x-2.2.3

# 从 cocos2dx.ini 等搬过来的
cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT

extra_arguments = %(cocos_headers)s %(cocos_flags)s -D_SIZE_T_DEFINED_ -nostdinc -nostdinc++ -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(clangllvmdir)s/lib/clang/3.1/include -I%(cxxgeneratordir)s/test/simple_test -x c++
#headers = %(cxxgeneratordir)s/test/simple_test/test.h
headers = /Users/tuyou/Downloads/cocos2d-x-2.2.3/tools/bindings-generator/test/simple_test/test.h

target_namespace =
remove_prefix =
skip =
base_objects =
abstract_classes =
classes_have_type_info = no
rename =
rename_functions =
rename_classes =
# classes for which there will be no "parent" lookup
classes_have_no_parents =

# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip =

# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are ‘yes‘ or ‘no‘.
script_control_cpp = yes

</pre><p></p><pre>
"user.cfg"
PYTHON_BIN=/usr/bin/python2.7
"userconf.ini"
[DEFAULT]
androidndkdir=/Users/tudu/Downloads/android-ndk-r9c
clangllvmdir=/Users/tudu/Downloads/clang+llvm-3.1-x86_64-apple-darwin11
cxxgeneratordir=/Users/tudu/Downloads/cocos2d-x-2.2.3/tools/bindings-generator/test

然后执行test.sh

OK了

关于终端打印出的错误提示 , 以下这些warning貌似没影响:

/Library/Python/2.7/site-packages/Cheetah-2.4.4-py2.7.egg/Cheetah/Compiler.py:1509: UserWarning:
You don‘t have the C version of NameMapper installed! I‘m disabling Cheetah‘s useStackFrames option as it is painfully slow with the Python version of NameMapper. You should get a copy of Cheetah with the compiled C version of NameMapper.
  "\nYou don‘t have the C version of NameMapper installed! "
====
Errors in parsing headers:
1. <severity = Warning,
    location = <SourceLocation file None, line 0, column 0>,
    details = "argument unused during compilation: ‘-nostdinc++‘">
====

假设有severity = error就要检查一番了 , 之前的error一般都能够通过改动上面那些路径而解决

自己主动绑定的问题 :

1 . 不能绑定继承的第二个类 , 一个类继承多个类的时候 , 仅仅有被继承的第一个类被绑定了 ,原因是 "JS_InitClass"这个函数的形參列表中仅仅能接受一个父类.以下是形參列表:

JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
             JSClass *clasp, JSNative constructor, unsigned nargs,
             JSPropertySpec *ps, JSFunctionSpec *fs,
             JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
时间: 2024-08-02 16:01:24

cocos2dx 自己主动绑定js的相关文章

超链接标签绑定JS事件&amp;&amp;不加&quot;javascript:;&quot;导致的杯具

很久以来,在写Html和JS时,经常会给超链接<a>标签,绑定JS事件. 我们经常看到这样的写法,<a href="javascript:;" onclick="doAction()" >Click</a>. 我原来一直有个疑问,干嘛非要加上"javascript:;" .原来,我很"老实",每次都会加上.今天,又手敲了类似的代码,本着"老子就是不加,你咬我"的得瑟心态,

几种自己主动运行js代码的方式

近期在看jquery,发现他竟然能自己主动运行js代码,于是就查了下.收集了几种经常使用的实现方法 jquery的方法 使用场景:不论什么须要运行的js特效 $(document).ready(function(){ alert("你好"); }); 简写方式: $(function(){ alert("你好"); }); }); 说明: 就只只须要载入全部的DOM结构,在浏览器把全部的HTML放入DOM tree之前就运行js效果.包含在载入外部图片和资源之前.

cocos2dx 关于lua 绑定的环境配置官方文档翻译与 将自定义的方法绑定到lua的的方法

//网上有好多写怎样讲自定义的方法绑定到lua的文章,其中都只对环境配置做了简单的介绍,看到有的帖子写在绑定中遇到了各种各样的error,大部分是由于环境配置//不正确导致的,以下是官方的文档有标准的说明,所有的开发引擎都会有自己的说明文档.下面就是cocos2dx 官方文档 //怎样使用 bindings-generator How to Use bindings-generator ================== //windows 环境下 On Windows: ----------

cocos2dx——lua自动和手动绑定

[自动绑定] 参考:http://my.oschina.net/skyhacker2/blog/298397 主要是通过引擎自带的tools/tolua,主要步骤如下: 1.编写好要导出的c++类,如果是libcocos2d里添加,需要添加导出标记:class CC_DLL Test 2.到tolua目录根据README.mdown配置好环境: * Make sure that you have installed `android-ndk-r9b`. * Download python2.7.

在js对象上绑定js数组原生方法

在js对象上绑定数组方法会给当前对象添加一个lenght:0属性 例: var o = {}; [].pop.call(o) console.log(o)//返回结果Object {length: 0}

ASP.Net 在Update Panel局部刷新后 重新绑定JS方法

我们知道Asp.Net中的Update Panel可以完成页面的局部刷新(实质上是Ajax),但是局部刷新完后,此区域的控件上所绑定的JS方法就会失效,因为我们用如下方法来重新绑定. var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function () { // re-bind your jQuery events here }); 更多详细信息请看如下链接: http://stackove

javascript 自动绑定JS callback 的方法函数

自己写的一个javascript 智能绑定callback 并且调用执行的函数,主要用于异步请求的 ajax中: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <script> /** * @author [email 

使自定义事件支持多绑定 js

<script language="JavaScript" type="text/javascript"> <!-- //定义类class1 function class1(){ //构造函数 } //定义类成员 class1.prototype={ show:function(){ //show的代码 //... //如果有事件绑定则循环onshow数组,触发该事件 if(this.onshow){ for(var i=0;i<this.o

cocos2dx手写js绑定C++

这两天连续查阅了js绑定c++的非常多文章  , 有手动与自己主动两种方式 . 本来想用自己主动绑定的 , 可是NDK一直下载不下来.....就给算了 . 以下总结一下手动绑定的实现过程 : 一共三步 : 1 . 写原始 C++ 类 ( 一般放在自己定义类库里 ) 2.  用 C++ 逐个写 成员函数相应 的 绑定代码 ( 在自己定义类库中建立的manual_binding目录里) 3.  注冊所绑定过的函数( 在AppDelegate.cpp中 加入注冊函数 ) 4.  写js代码測试效果 1