Secrets of CPP Scripting Bindings
Secrets of CPP Scripting Bindings
com/idocpp 1
Secrets of Scripting
Bindings for C++
1 struct S {
2 int get_value(this const S &self);
3 };
4
5 int main() {
6 add(&S::get_value);
7 } https://godbolt.org/z/bv6YdMc8o
1 struct S {
2 int get_value(this const S &self);
3 };
4
5 int main() {
6 add(&S::get_value);
7 } https://godbolt.org/z/bv6YdMc8o
OR…?
OR…?
BOOST_PP and lots of macros (not recommended)
1 Type generic_function(std::span<Type>);
1 Type generic_function(std::span<Type>);
1 Type generic_function(std::span<Type>);
Pro - Works with literally any type that can be copied or moved, user
doesn’t have to specify. “It’s Magic”
Con - If objects are bigger than the small object optimization, you’ll get
a heap allocation inside of the any
or
1 (print (to_string (- 1 (* 3 6))))
or
1 (print (to_string (- 1 (* 3 6))))
Who wants
Copyright toTurner
Jason give it a go? @lefticus emptycrate.com/idocpp 24 . 4
Your Homework