get started
Tangram edited this page Jul 24, 2015
·
4 revisions
- 1.Prepare a json file that describe the native class or globals. ex:
{
"className":"Point",
"functions": [
{
"name":"move",
"returnType" : "int",
"args" : [
{"name":"x", "type":"int32_t"},
{"name":"y", "type":"int32_t"}
]
},
{
"name":"add",
"returnType" : "string",
"args" : [
{"name":"x", "type":"int32_t"},
{"name":"y", "type":"int32_t"}
]
},
{
"name":"copy",
"returnType" : "bool",
"args" : [
{"name":"x", "type":"int32_t"},
{"name":"y", "type":"int32_t"}
]
},
{
"name":"copy",
"returnType" : "bool",
"args" : [
{"name":"other", "type":"Point*"}
]
}
],
"attributes" : [
{"name":"x", "type":"int32_t"},
{"name":"y", "type":"int32_t"},
{"name":"magic", "type":"string"}
],
"constants" : [
{"name":"DEFAULT_NAME", "type":"string", "value":"jim"},
{"name":"DEFAULT_X", "type":"int32_t", "value":10},
{"name":"DEFAULT_Y", "type":"int32_t", "value":100}
]
}
- 2.run the script gen-v8-binding.js(make sure you installed node)
mkdir -p output
node gen-v8-binding.js samples/point.json
This will generate 4 files:
-
1).output/PointBinding.h : the header file of the binding functions.
-
2).output/PointBinding.cpp : the implementation file of the binding functions.
-
3).output/Point.h : the header file of the real class.
-
4).output/Point.cpp : the implementation file of the real class.
-
3.call the binding init function in your v8 project.
v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentContext();
Handle<Object> global = context->Global();
PointInitBinding(global);