|
Boost : |
From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2022-09-30 03:25:31
Is there any interest in C++ Tcl bindings?
I wanted to find out how far I can push boost.describe so I create C++ tcl
binding based on it, PoC is here
https://github.com/klemens-morgenstern/boost.tcl
It's currently a rough PoC so it'd be a lot of work to make this a proper
boost library, hence the question if there's some actual interest,
otherwise it's a nice toy project.
All you need to do is to use boost.describe for your enum or class and then
you can use them in tcl:
// C++
enum test_enum {foo = 1};
BOOST_DESCRIBE_ENUM(test_enum, foo);
struct my_class
{
double foo;
void bar(int);
};
BOOST_DESCRIBE_STRUCT(my_class, (), (foo, bar));
BOOST_TCL_PACKAGE(Test_module, "1.0", mod)
{
auto & cmd = boost::tcl::create_command(mod, "test");
auto & enm = cmd.add_subcommand("enum");
enm.add_enum<test_enum>();
auto & fun = cmd.add_subcommand("add").add_function(+[](int i, int j)
{return i + j;);
auto & cl = cmd.add_subcommand("add")
.add_class<my_class>() // adds all the members based
on boost.describe
.add_constructor<my_class(int, std::string)>();
}
# TCL
# create `test_enum` from it's int valid
set e1 [test enum 1]
# create test_enum from it's name
set e2 [test enum foo]
# call the function - overloading is supported
[test add 1 2]
# create an instance of my_class
set mc [my_class new 1 test-string]
# get a data-member
puts [ *$mc .get foo ]
# call a method
*$mc bar 42
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk