python: Named argument support
Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
parent
f5bfd557b6
commit
30f0c582e4
@ -241,6 +241,7 @@ void init_python(const char *executable, bool first)
|
|||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
if (first)
|
if (first)
|
||||||
PyImport_ImportModule(TOSTRING(MODULE_NAME));
|
PyImport_ImportModule(TOSTRING(MODULE_NAME));
|
||||||
|
PyRun_SimpleString("from " TOSTRING(MODULE_NAME) " import *");
|
||||||
} catch (boost::python::error_already_set const &) {
|
} catch (boost::python::error_already_set const &) {
|
||||||
// Parse and output the exception
|
// Parse and output the exception
|
||||||
std::string perror_str = parse_python_exception();
|
std::string perror_str = parse_python_exception();
|
||||||
|
@ -250,6 +250,11 @@ template <typename Class, typename FuncT, FuncT fn, typename arg1_conv> struct f
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, Ta a = arg("arg1"))
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Two parameters, one return
|
// Two parameters, one return
|
||||||
@ -267,6 +272,11 @@ template <typename Class, typename FuncT, FuncT fn, typename arg1_conv, typename
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Three parameters, no return
|
// Three parameters, no return
|
||||||
@ -286,6 +296,11 @@ struct fn_wrapper_3a_v
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Four parameters, no return
|
// Four parameters, no return
|
||||||
@ -309,6 +324,11 @@ struct fn_wrapper_4a_v
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Five parameters, no return
|
// Five parameters, no return
|
||||||
@ -333,6 +353,11 @@ struct fn_wrapper_5a_v
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Six parameters, no return
|
// Six parameters, no return
|
||||||
@ -358,6 +383,11 @@ struct fn_wrapper_6a_v
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }
|
||||||
|
|
||||||
|
template <typename WrapCls, typename Ta> static void def_wrap(WrapCls cls_, const char *name, const Ta &a)
|
||||||
|
{
|
||||||
|
cls_.def(name, wrapped_fn, a);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wrapped getter
|
// Wrapped getter
|
||||||
|
@ -30,6 +30,7 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
void arch_wrap_python()
|
void arch_wrap_python()
|
||||||
{
|
{
|
||||||
using namespace PythonConversion;
|
using namespace PythonConversion;
|
||||||
|
|
||||||
auto arch_cls = class_<Arch, Arch *, bases<BaseCtx>, boost::noncopyable>("Arch", init<ArchArgs>());
|
auto arch_cls = class_<Arch, Arch *, bases<BaseCtx>, boost::noncopyable>("Arch", init<ArchArgs>());
|
||||||
auto ctx_cls = class_<Context, Context *, bases<Arch>, boost::noncopyable>("Context", no_init)
|
auto ctx_cls = class_<Context, Context *, bases<Arch>, boost::noncopyable>("Context", no_init)
|
||||||
.def("checksum", &Context::checksum)
|
.def("checksum", &Context::checksum)
|
||||||
|
Loading…
Reference in New Issue
Block a user