From b1f865d461986852d42e887af467352c47549912 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 14 Oct 2013 23:03:36 +0200 Subject: [PATCH] cppbind: add to_nasal_helper for enums. --- simgear/nasal/cppbind/cppbind_test.cxx | 9 +++++++++ simgear/nasal/cppbind/detail/to_nasal_helper.hxx | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/simgear/nasal/cppbind/cppbind_test.cxx b/simgear/nasal/cppbind/cppbind_test.cxx index 6d75b966..2a010d38 100644 --- a/simgear/nasal/cppbind/cppbind_test.cxx +++ b/simgear/nasal/cppbind/cppbind_test.cxx @@ -17,6 +17,12 @@ return 1; \ } +enum MyEnum +{ + ENUM_FIRST, + ENUM_ANOTHER, + ENUM_LAST +}; struct Base { naRef member(const nasal::CallContext&) { return naNil(); } @@ -83,6 +89,9 @@ int main(int argc, char* argv[]) using namespace nasal; + r = to_nasal(c, ENUM_ANOTHER); + VERIFY( from_nasal(c, r) == ENUM_ANOTHER ); + r = to_nasal(c, "Test"); VERIFY( strncmp("Test", naStr_data(r), naStr_len(r)) == 0 ); VERIFY( from_nasal(c, r) == "Test" ); diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx index f9e4f235..e6c8a6e4 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx @@ -75,6 +75,16 @@ namespace nasal naRef to_nasal_helper(naContext c, const free_function_t& func); + /** + * Convert an enum value to the according numeric value + */ + template + typename boost::enable_if< boost::is_enum, naRef >::type + to_nasal_helper(naContext c, T val) + { + return naNum(val); + } + /** * Convert a numeric type to Nasal number */ -- 2.39.5