Skip to content

Commit

Permalink
refactor: break lib in more files
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleff13 committed Jul 17, 2023
1 parent 231759e commit 897c7ec
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
20 changes: 6 additions & 14 deletions Stack/cpp/stack.addon.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
"use strict";
exports.__esModule = true;
var ffi = require("ffi-napi");
//import c++ lib
var stackLib = ffi.Library("./stack.so", {
"createStack": ['pointer', []],
'deleteStack': ['void', ['pointer']],
"push": ['void', ['pointer', 'string']],
"pop": ['void', ['pointer']],
"peek": ['string', ['pointer']]
});
var stack_lib_1 = require("./stack.lib");
var Stack = /** @class */ (function () {
function Stack() {
this.obj = stackLib.createStack();
this.obj = stack_lib_1["default"].createStack();
}
Stack.prototype.push = function (value) {
stackLib.push(this.obj, value);
stack_lib_1["default"].push(this.obj, value);
};
Stack.prototype.pop = function () {
return stackLib.keyToHash(this.obj);
return stack_lib_1["default"].keyToHash(this.obj);
};
Stack.prototype.peek = function () {
return stackLib.peek(this.obj);
return stack_lib_1["default"].peek(this.obj);
};
Stack.prototype.destructor = function () {
stackLib.deleteStack(this.obj);
stack_lib_1["default"].deleteStack(this.obj);
};
return Stack;
}());
Expand Down
11 changes: 1 addition & 10 deletions Stack/cpp/stack.addon.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
const ffi = require("ffi-napi")

//import c++ lib
const stackLib = ffi.Library("./stack.so", {
"createStack": ['pointer', []],
'deleteStack': ['void', ['pointer']],
"push": ['void', ['pointer', 'string']],
"pop": ['void', ['pointer']],
"peek": ['string', ['pointer']],
});
import stackLib from './stack.lib';

class Stack {
obj: any;
Expand Down
12 changes: 12 additions & 0 deletions Stack/cpp/stack.lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
exports.__esModule = true;
var ffi = require("ffi-napi");
//import c++ lib
var stackLib = ffi.Library("../cpp/stack.so", {
"createStack": ['pointer', []],
'deleteStack': ['void', ['pointer']],
"push": ['void', ['pointer', 'string']],
"pop": ['void', ['pointer']],
"peek": ['string', ['pointer']]
});
exports["default"] = stackLib;
11 changes: 11 additions & 0 deletions Stack/cpp/stack.lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const ffi = require("ffi-napi")
//import c++ lib
const stackLib = ffi.Library("../cpp/stack.so", {
"createStack": ['pointer', []],
'deleteStack': ['void', ['pointer']],
"push": ['void', ['pointer', 'string']],
"pop": ['void', ['pointer']],
"peek": ['string', ['pointer']],
});

export default stackLib
19 changes: 9 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 897c7ec

Please sign in to comment.