| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1c563e7 commit 2bf45b3
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,7 +162,6 @@ | |||
| 162 | 162 | "clone_options": { | |
| 163 | 163 | "cType": "git_clone_options", | |
| 164 | 164 | "isStruct": true, | |
| 165 | - "isPublicStruct": true, | ||
| 166 | 165 | "dependencies": [ | |
| 167 | 166 | "../include/checkout_options.h", | |
| 168 | 167 | "../include/remote_callbacks.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,7 +92,7 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { | |||
| 92 | 92 | ||
| 93 | 93 | // Write out all the classes. | |
| 94 | 94 | enabled.forEach(function(idef) { | |
| 95 | - if (idef.isPublicStruct) { | ||
| 95 | + if (idef.hasConstructor) { | ||
| 96 | 96 | file.write("../src/" + idef.name + ".cc", templates.struct_content.render(idef)); | |
| 97 | 97 | file.write("../include/" + idef.name + ".h", templates.struct_header.render(idef)); | |
| 98 | 98 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,9 @@ NAN_GETTER({{ cppClassName }}::Get{{ field.cppFunctionName }}) { | |||
| 6 | 6 | ||
| 7 | 7 | {{ cType }} *raw = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue(); | |
| 8 | 8 | ||
| 9 | - {%if field.cppClassName == 'String' %} | ||
| 9 | + {%if field.hasConstructor %} | ||
| 10 | + NanReturnValue(NanNew(new {{ field.cppClassName }}(&raw->{{ field.name }}))); | ||
| 11 | + {%elsif field.cppClassName == 'String' %} | ||
| 10 | 12 | NanReturnValue(NanNew<String>(raw->{{ field.name }})); | |
| 11 | 13 | {%elsif field.cppClassName|isV8Value %} | |
| 12 | 14 | NanReturnValue(NanNew<{{ field.cppClassName }}>(raw->{{ field.name }})); | |
@@ -19,7 +21,10 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) { | |||
| 19 | 21 | ||
| 20 | 22 | {{ cType }} *raw = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue(); | |
| 21 | 23 | ||
| 22 | - {%if field.cppClassName == 'String' %} | ||
| 24 | + {%if field.hasConstructor %} | ||
| 25 | + {{ field.cType }}* wrappedStruct = ObjectWrap::Unwrap<{{ field.cppClassName }}>(value->ToObject())->GetValue(); | ||
| 26 | + memcpy(&raw->{{ field.name }}, wrappedStruct, sizeof({{ field.cType }})); | ||
| 27 | + {%elsif field.cppClassName == 'String' %} | ||
| 23 | 28 | if (raw->{{ field.name }}) { | |
| 24 | 29 | //free(raw->{{ field.name }}); | |
| 25 | 30 | } | |
@@ -28,14 +33,12 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) { | |||
| 28 | 33 | raw->{{ field.name }} = strdup(*str); | |
| 29 | 34 | {%elsif field.isCppClassIntType%} | |
| 30 | 35 | if (value->IsNumber()) { | |
| 31 | - raw->{{ field.name }} = value->field.cppClassName}}Value(); | ||
| 36 | + raw->{{ field.name }} = value->{{field.cppClassName}}Value(); | ||
| 32 | 37 | } | |
| 33 | - {%elsif field.cppClassName == 'Number' %} | ||
| 38 | + {%else%} | ||
| 34 | 39 | if (value->IsNumber()) { | |
| 35 | - raw->{{ field.name }} = value->Int32Value(); | ||
| 40 | + raw->{{ field.name }} = ({{ field.cType }}) value->Int32Value(); | ||
| 36 | 41 | } | |
| 37 | - {%else%} | ||
| 38 | - raw->{{ field.name }} = ({{ field.cType }}) value; | ||
| 39 | 42 | {%endif%} | |
| 40 | 43 | ||
| 41 | 44 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,6 +124,18 @@ fileNames.forEach(function(fileName, index) { | |||
| 124 | 124 | cFile.fields = descriptor[fileName].fields || structFile.fields || []; | |
| 125 | 125 | } | |
| 126 | 126 | ||
| 127 | + // This should turn 'git_clone_options' into 'git_clone_init_options' | ||
| 128 | + var initFnName = ["git"].concat(fileName.split('_')); | ||
| 129 | + | ||
| 130 | + initFnName.splice(-1, 0, "init"); | ||
| 131 | + initFnName = initFnName.join('_'); | ||
| 132 | + | ||
| 133 | + // Does this struct contain an init function? If so then we can create one publicly | ||
| 134 | + // to pass into functions and other structs | ||
| 135 | + file.hasConstructor = structFile.used && structFile.used.needs.some(function (fnName) { | ||
| 136 | + return fnName === initFnName; | ||
| 137 | + }); | ||
| 138 | + | ||
| 127 | 139 | // Doesn't actually exist. | |
| 128 | 140 | if (cFile.functions.indexOf(file.freeFunctionName) === -1) { | |
| 129 | 141 | delete file.freeFunctionName; | |
@@ -190,6 +202,22 @@ fileNames.forEach(function(fileName, index) { | |||
| 190 | 202 | field.jsFunctionName = camelCase(field.name); | |
| 191 | 203 | field.cppClassName = typeMap[field.cType].cpp; | |
| 192 | 204 | field.jsClassName = typeMap[field.cType].js; | |
| 205 | + | ||
| 206 | + var struct = structs[field.cType]; | ||
| 207 | + | ||
| 208 | + // This should turn 'git_clone_options' into 'git_clone_init_options' | ||
| 209 | + var initFnName = field.cType.split('_'); | ||
| 210 | + | ||
| 211 | + initFnName.splice(-1, 0, "init"); | ||
| 212 | + initFnName = initFnName.join('_'); | ||
| 213 | + | ||
| 214 | + // Does this struct contain an init function? If so then we can create one publicly | ||
| 215 | + // to pass into functions and other structs | ||
| 216 | + field.hasConstructor = struct && struct.used && struct.used.needs.some(function (fnName) { | ||
| 217 | + return fnName === initFnName; | ||
| 218 | + }); | ||
| 219 | + | ||
| 220 | + field.isEnum = struct && struct.type === "enum"; | ||
| 193 | 221 | } catch (ex) { | |
| 194 | 222 | console.error(file.filename, field.cType + " is missing a definition."); | |
| 195 | 223 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,12 @@ using namespace node; | |||
| 22 | 22 | memcpy(this->raw, &wrappedValue, sizeof({{ cType }})); | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | + {{ cppClassName }}::{{ cppClassName }}({{ cType }}* raw) { | ||
| 26 | + {{ cType }} wrappedValue = *raw; | ||
| 27 | + this->raw = ({{ cType }}*) malloc(sizeof({{ cType }})); | ||
| 28 | + memcpy(this->raw, &wrappedValue, sizeof({{ cType }})); | ||
| 29 | + } | ||
| 30 | + | ||
| 25 | 31 | {{ cppClassName }}::~{{ cppClassName }}() { | |
| 26 | 32 | // This is going to cause memory leaks. We'll have to solve that later | |
| 27 | 33 | // TODO: Clean up memory better | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ using namespace v8; | |||
| 17 | 17 | ||
| 18 | 18 | class {{ cppClassName }} : public ObjectWrap { | |
| 19 | 19 | public: | |
| 20 | - | ||
| 20 | + {{ cppClassName }}({{ cType }}* raw); | ||
| 21 | 21 | static Persistent<Function> constructor_template; | |
| 22 | 22 | static void Initialize (Handle<v8::Object> target); | |
| 23 | 23 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments