cppbind: add to_nasal_helper for enums.
This commit is contained in:
parent
8e75c6be50
commit
b1f865d461
@ -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" );
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user