| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b5ce73 commit 96af2b7
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -728,6 +728,10 @@ | |||
| 728 | 728 | "returnNoResults": 1, | |
| 729 | 729 | "returnSuccess": 0, | |
| 730 | 730 | "returnError": -1 | |
| 731 | + }, { | ||
| 732 | + "name": "payload", | ||
| 733 | + "cType": "void *", | ||
| 734 | + "payloadFor": "*" | ||
| 731 | 735 | }] | |
| 732 | 736 | }, | |
| 733 | 737 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + module.exports = function(fields, payloadForField) { | ||
| 2 | + fields = fields || []; | ||
| 3 | + | ||
| 4 | + var result = fields.filter(function (field) { | ||
| 5 | + return field.payloadFor && (field.payloadFor === payloadForField || field.payloadFor === "*"); | ||
| 6 | + }); | ||
| 7 | + | ||
| 8 | + if (result.length > 0) { | ||
| 9 | + return result[0].name; | ||
| 10 | + } | ||
| 11 | + else { | ||
| 12 | + return ""; | ||
| 13 | + } | ||
| 14 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ var filters = { | |||
| 44 | 44 | isPointer: require("./filters/is_pointer"), | |
| 45 | 45 | isDoublePointer: require("./filters/is_double_pointer"), | |
| 46 | 46 | unPointer: require("./filters/un_pointer"), | |
| 47 | + payloadFor: require("./filters/payload_for"), | ||
| 47 | 48 | hasReturnType: require("./filters/has_return_type"), | |
| 48 | 49 | hasReturns: require("./filters/has_returns"), | |
| 49 | 50 | returnsCount: require("./filters/returns_count"), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ NAN_GETTER({{ cppClassName }}::Get{{ field.cppFunctionName }}) { | |||
| 6 | 6 | ||
| 7 | 7 | {{ cppClassName }} *wrapper = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This()); | |
| 8 | 8 | ||
| 9 | - {%if field.hasConstructor | or field.isFunction %} | ||
| 9 | + {%if field.hasConstructor | or field.isFunction | or field.payloadFor %} | ||
| 10 | 10 | NanReturnValue(wrapper->{{ field.name }}); | |
| 11 | 11 | {%elsif field.cppClassName == 'String' %} | |
| 12 | 12 | if (wrapper->GetValue()->{{ field.name }}) { | |
@@ -25,13 +25,19 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) { | |||
| 25 | 25 | ||
| 26 | 26 | {{ cppClassName }} *wrapper = ObjectWrap::Unwrap<{{ cppClassName }}>(args.This()); | |
| 27 | 27 | ||
| 28 | - {%if field.hasConstructor %} | ||
| 28 | + {%if field.hasConstructor | or field.payloadFor %} | ||
| 29 | + wrapper->{{ field.name }}.Dispose(); | ||
| 30 | + wrapper->{{ field.name }}.Clear(); | ||
| 31 | + | ||
| 29 | 32 | wrapper->{{ field.name }} = Persistent<Object>::New(value->ToObject()); | |
| 33 | + {%if field.hasConstructor %} | ||
| 30 | 34 | wrapper->raw->{{ field.name }} = *ObjectWrap::Unwrap<{{ field.cppClassName }}>(value->ToObject())->GetValue(); | |
| 35 | + {%endif%} | ||
| 31 | 36 | {%elsif field.isFunction %} | |
| 32 | 37 | if (value->IsFunction()) { | |
| 38 | + wrapper->{{ field.name }}.Dispose(); | ||
| 39 | + wrapper->{{ field.name }}.Clear(); | ||
| 33 | 40 | wrapper->{{ field.name }} = Persistent<Function>::Cast((Persistent<Value>)value); | |
| 34 | - wrapper->raw->{{ field.name }} = ({{ field.cType }})&{{ cppClassName }}::{{ field.name}}_cppCallback; | ||
| 35 | 41 | } | |
| 36 | 42 | {%elsif field.cppClassName == 'String' %} | |
| 37 | 43 | if (wrapper->GetValue()->{{ field.name }}) { | |
@@ -58,7 +64,9 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) { | |||
| 58 | 64 | ||
| 59 | 65 | {%endeach%} | |
| 60 | 66 | ) { | |
| 61 | - if (!{{ field.name }}->IsFunction()) { | ||
| 67 | + {{ cppClassName }} *instance = ({{ cppClassName }}*)payload; | ||
| 68 | + | ||
| 69 | + if (!instance->{{ field.name }}->IsFunction()) { | ||
| 62 | 70 | {%if field.returnType == "int" %} | |
| 63 | 71 | return {{ field.returnNoResults }}; // no results acquired | |
| 64 | 72 | {%else%} | |
@@ -68,14 +76,17 @@ NAN_SETTER({{ cppClassName }}::Set{{ field.cppFunctionName }}) { | |||
| 68 | 76 | ||
| 69 | 77 | Local<Value> argv[{{ field.args|jsArgsCount }}] = { | |
| 70 | 78 | {%each field.args|argsInfo as arg %} | |
| 71 | - {%if arg.isJsArg %} | ||
| 72 | - Local<Value>::New(NanNew({{ arg.name }})){%if not arg.lastArg %},{%endif%} | ||
| 79 | + {%if arg.name == "payload" %} | ||
| 80 | + {%-- payload is always the last arg --%} | ||
| 81 | + Local<Value>::New(NanNew(instance->{{ fields|payloadFor field.name }})) | ||
| 82 | + {%elsif arg.isJsArg %} | ||
| 83 | + Local<Value>::New(NanNew({{ arg.name }})), | ||
| 73 | 84 | ||
| 74 | 85 | {%endif%} | |
| 75 | 86 | {%endeach%} | |
| 76 | 87 | }; | |
| 77 | 88 | ||
| 78 | - Persistent<Value> result = Persistent<Value>::New(this->{{ field.name }}->Call(Context::GetCurrent()->Global(), {{ field.args|jsArgsCount }}, argv)); | ||
| 89 | + Persistent<Value> result = Persistent<Value>::New(instance->{{ field.name }}->Call(Context::GetCurrent()->Global(), {{ field.args|jsArgsCount }}, argv)); | ||
| 79 | 90 | {{ field.returnType }} resultStatus; | |
| 80 | 91 | ||
| 81 | 92 | {%each field|returnsInfo true false as _return%} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,8 @@ | |||
| 34 | 34 | ||
| 35 | 35 | "WARNING_CFLAGS": [ | |
| 36 | 36 | "-Wno-unused-variable", | |
| 37 | + "-Wint-conversions", | ||
| 38 | + "-Wmissing-field-initializers" | ||
| 37 | 39 | ], | |
| 38 | 40 | } | |
| 39 | 41 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,12 @@ void {{ cppClassName }}::ConstructFields() { | |||
| 52 | 52 | {%each fields|fieldsInfo as field %} | |
| 53 | 53 | {%if field.hasConstructor %} | |
| 54 | 54 | {{ field.name }} = Persistent<Object>::New({{ field.cppClassName }}::New(&this->raw->{{ field.name }})->ToObject()); | |
| 55 | + {%elsif field.isFunction %} | ||
| 56 | + {{ field.name }} = Persistent<Value>::New(NanNull()); | ||
| 57 | + // Set the static method call and set the payload for this function to be | ||
| 58 | + // the current instance | ||
| 59 | + this->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback; | ||
| 60 | + this->raw->{{ fields|payloadFor field.name }} = (void *)this; | ||
| 55 | 61 | {%endif%} | |
| 56 | 62 | {%endeach%} | |
| 57 | 63 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,18 @@ class {{ cppClassName }} : public ObjectWrap { | |||
| 28 | 28 | ||
| 29 | 29 | bool selfFreeing; | |
| 30 | 30 | ||
| 31 | + {%each fields as field %} | ||
| 32 | + {%if not field.ignore %} | ||
| 33 | + {%if field.isFunction %} | ||
| 34 | + static {{ field.returnType }} {{ field.name }}_cppCallback ( | ||
| 35 | + {%each field.args|argsInfo as arg%} | ||
| 36 | + {{ arg.cType }} {{ arg.name}}{%if not arg.lastArg %},{%endif%} | ||
| 37 | + {%endeach%} | ||
| 38 | + ); | ||
| 39 | + {%endif%} | ||
| 40 | + {%endif%} | ||
| 41 | + {%endeach%} | ||
| 42 | + | ||
| 31 | 43 | private: | |
| 32 | 44 | {{ cppClassName }}(); | |
| 33 | 45 | ~{{ cppClassName }}(); | |
@@ -38,15 +50,10 @@ class {{ cppClassName }} : public ObjectWrap { | |||
| 38 | 50 | ||
| 39 | 51 | {%each fields as field%} | |
| 40 | 52 | {%if not field.ignore%} | |
| 41 | - {%if field.hasConstructor %} | ||
| 53 | + {%if field.hasConstructor | or field.payloadFor %} | ||
| 42 | 54 | Persistent<Object> {{ field.name }}; | |
| 43 | 55 | {%elsif field.isFunction %} | |
| 44 | 56 | Persistent<Function> {{ field.name }}; | |
| 45 | - {{ field.returnType }} {{ field.name }}_cppCallback ( | ||
| 46 | - {%each field.args|argsInfo as arg%} | ||
| 47 | - {{ arg.cType }} {{ arg.name}}{%if not arg.lastArg %},{%endif%} | ||
| 48 | - {%endeach%} | ||
| 49 | - ); | ||
| 50 | 57 | {%endif%} | |
| 51 | 58 | static NAN_GETTER(Get{{ field.cppFunctionName }}); | |
| 52 | 59 | static NAN_SETTER(Set{{ field.cppFunctionName }}); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments