From: Thomas Geymayer Date: Mon, 14 Oct 2013 21:03:36 +0000 (+0200) Subject: cppbind: add to_nasal_helper for enums. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b1f865d461986852d42e887af467352c47549912;p=simgear.git cppbind: add to_nasal_helper for enums. --- 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 */