Skip to content

Commit 128a89d

Browse files
committed
Possible solution for #385.
1 parent 56645a6 commit 128a89d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/core/utilities/wrap_macros.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,32 @@ T cached_property(T cls, const char *szName)
173173
//---------------------------------------------------------------------------------
174174
// Use this template to create variadic class methods
175175
//---------------------------------------------------------------------------------
176+
struct raw_method_dispatcher
177+
{
178+
public:
179+
raw_method_dispatcher(object func):
180+
func(func)
181+
{
182+
}
183+
184+
object operator()(object args, object kwargs)
185+
{
186+
object self = args[0];
187+
args = boost::python::tuple(args.slice(1, _));
188+
return func(self, args, kwargs);
189+
}
190+
191+
private:
192+
object func;
193+
};
194+
176195
template<class T>
177-
object raw_method(T method)
196+
object raw_method(T func, int min_args = 0)
178197
{
179-
return eval("lambda method: lambda *args, **kw: method(args[0], args[1:], kw)")(make_function(method));
198+
return raw_function(
199+
raw_method_dispatcher(make_function(func)),
200+
min_args + 1
201+
);
180202
}
181203

182204
//---------------------------------------------------------------------------------

0 commit comments

Comments
 (0)