nbind
nbind copied to clipboard
Support for shared pointer const references.
Hi all,
Firstly, I'd like to congratulate you all for the exceptional work on nbind!
I'm about to wrap some of my native modules to be called from node. Unfortunately, I have a constraint that some of the methods in my native API receive shared_ptr
as const references. I was getting misterious Unbound type
errors until I notice the problem is on those const shared_ptr<>&
. Passing the shared_ptrs by value works fine. Is there any way to make nbind work for both value and const shared_ptr<>&
types?
Here is my minimal example:
C++
#include <iostream>
#include "nbind/nbind.h"
class Arg
{
public:
virtual ~Arg() = default;
virtual void run() = 0;
};
class Test
{
public:
static std::shared_ptr<Test> create()
{
return std::make_shared<Test>();
}
void run(const std::shared_ptr<Arg> & arg) /* got `Error: Unbound type` */
//void run(std::shared_ptr<Arg> arg) <- IT WORKS
{
arg->run();
}
};
class ArgWrapper: public Arg
{
public:
static std::shared_ptr<ArgWrapper> create()
{
return std::make_shared<ArgWrapper>();
}
void run() override
{
std::cout << "HAHA" << std::endl;
}
};
NBIND_CLASS(Arg)
{
method(run);
}
NBIND_CLASS(Test)
{
method(run);
method(create);
}
NBIND_CLASS(ArgWrapper)
{
inherit(Arg);
method(create);
method(run);
}
Typescript
import * as nbind from 'nbind';
import * as LibTypes from './lib-types';
var binding = nbind.init<typeof LibTypes>();
const lib = binding.lib;
const test = lib.Test.create();
test.run(
lib.ArgWrapper.create()
)
I have the same question!