From 590905f4b3333291a7d0a8b23b330f8a4a19852e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 2 Dec 2016 20:32:47 -0700 Subject: [PATCH] Add notes on base_class conversions --- cheatsheet.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cheatsheet.md b/cheatsheet.md index 6bde03fe..a4f74384 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -92,6 +92,7 @@ chai.add(chaiscript::user_type(), "MyClass"); User defined type conversions are possible, defined in either script or in C++. + ### ChaiScript Defined Conversions Function objects (including lambdas) can be used to add type conversions @@ -115,6 +116,21 @@ Calling a user defined type conversion that takes a lambda chai.add(chaiscript::type_conversion([](const TestBaseType &t_bt) { /* return converted thing */ })); ``` +### Class Hierarchies + +If you want objects to be convertable between base and derived classes, you must tell ChaiScritp about the relationship. + +``` +chai.add(chaiscript::base_class()); +``` + +If you have multiple classes in your inheritance graph, you will probably want to tell ChaiScript about all relationships. + +``` +chai.add(chaiscript::base_class()); +chai.add(chaiscript::base_class()); +chai.add(chaiscript::base_class()); +``` ### Helpers