cppbind: add to_nasal_helper for enums.

This commit is contained in:
Thomas Geymayer 2013-10-14 23:03:36 +02:00
parent 8e75c6be50
commit b1f865d461
2 changed files with 19 additions and 0 deletions

View File

@ -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<int>(c, r) == ENUM_ANOTHER );
r = to_nasal(c, "Test");
VERIFY( strncmp("Test", naStr_data(r), naStr_len(r)) == 0 );
VERIFY( from_nasal<std::string>(c, r) == "Test" );

View File

@ -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<class T>
typename boost::enable_if< boost::is_enum<T>, naRef >::type
to_nasal_helper(naContext c, T val)
{
return naNum(val);
}
/**
* Convert a numeric type to Nasal number
*/