D
D
Dmitry2210602018-12-24 16:11:52
C++ / C#
Dmitry221060, 2018-12-24 16:11:52

How to modify a package?

I have a "node-images" package and I need to add a function to it that draws a black pixel at the given coordinates. I manually downloaded this package from GitHub and modified the following files:
index.js - added the lines

71. drawDot: function(x, y) {
72.     this._handle.dot(x, y);
72. },

src/Image.h - Added lines
207. 
208.     static void DrawDot(const v8::FunctionCallbackInfo<v8::Value> &args);

src/Image.cc - Added lines
106. NODE_SET_PROTOTYPE_METHOD(tpl, "dot", DrawDot);
...
422.
423. void Image::DrawDot(const FunctionCallbackInfo<Value> &args) { // {{{
424. 
425.     Image *dst;
426.     uint32_t x, y;
427.     Pixel *cp;
428. 
429.     dst = node::ObjectWrap::Unwrap<Image>(args.This());
430. 
431.     x = args[0]->Uint32Value();
432.     y = args[1]->Uint32Value();
433.     
434.     cp = &color;
435.     cp->R = 0;
436.     cp->G = 0;
437.     cp->B = 0;
438.     cp->A = 0xFF;
439. 
440.     dst->pixels->data[x][y] = cp;
441. 
442.     args.GetReturnValue().Set(v8::Undefined(args.GetIsolate()));
443. } // }}}

After that, I entered npm i while in the directory with the package and tried to execute the following code
const images = require("images");
images(300, 300).drawDot(10,10);

But I got an error:
"TypeError: this._handle.dot is not a function"
Question: What did I do wrong and how can I add this function?
It may be useful:
1. After installing the package, the /vendor/.../binding.node file appears. If you open it as a binary file, then at 0006d390 you can find an enumeration of function names, but the dot function is not among them.
2. If you enter the function name manually, the package will crash on startup without giving an error.
3. If you change the name of any function in the arguments of NODE_SET_PROTOTYPE_METHOD (src/Image.cc), then when you try to call this function, an error will occur, i.e. editing src/Image.cc affects the package.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question