eolian-js: Added reading integer and double parameters

This commit is contained in:
Felipe Magno de Almeida 2014-10-29 15:53:24 -02:00
parent 182bb33b42
commit 0be5f1aa49
3 changed files with 34 additions and 7 deletions

View File

@ -40,8 +40,10 @@ struct constructor_caller
template <typename T>
void operator()(T function) const
{
aux(function, eina::make_index_sequence<std::tuple_size
<typename eina::_mpl::function_params<T>::type>::value>());
std::size_t const parameters
= std::tuple_size<typename eina::_mpl::function_params<T>::type>::value;
aux(function, eina::make_index_sequence<parameters>());
*current += parameters;
}
template <typename U, std::size_t I>
@ -57,7 +59,6 @@ struct constructor_caller
void aux(T function, eina::index_sequence<I...>) const
{
function(get_value<T, I>((*args)[I + *current])...);
std::cout << " should call " << typeid(function).name() << std::endl;
}
std::size_t* current;

View File

@ -1,6 +1,10 @@
#ifndef EFL_EO_JS_GET_VALUE_HH
#define EFL_EO_JS_GET_VALUE_HH
#include <v8.h>
#include <type_traits>
namespace efl { namespace eo { namespace js {
template <typename T>
@ -9,13 +13,28 @@ struct value_tag
typedef T type;
};
inline int get_value_from_javascript(v8::Local<v8::Value> v, value_tag<int>)
template <typename T>
inline int get_value_from_javascript
(v8::Local<v8::Value> v, value_tag<T>
, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
if(v->IsInt32())
return v->Int32Value();
else if(v->IsUint32())
return v->Uint32Value();
else
std::abort();
return 0;
}
inline double get_value_from_javascript(v8::Local<v8::Value> v, value_tag<double>)
template <typename T>
inline double get_value_from_javascript
(v8::Local<v8::Value> v, value_tag<T>
, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
{
return 0.0;
if(v->IsNumber())
return v->NumberValue();
else
std::abort();
}
} } }

View File

@ -9,6 +9,8 @@
#include "constructor_method_class.eo.h"
#include <check.h>
struct _Constructor_Method_Class_Data
{
Eina_Bool one, two;
@ -24,11 +26,17 @@ static void _constructor_method_class_eo_base_constructor(Eo *obj, Constructor_M
static void _constructor_method_class_constructor1(Eo *obj, Constructor_Method_Class_Data *pd, int one)
{
fprintf(stderr, "one == %d\n", one);
fflush(stderr);
ck_assert(one == 5);
pd->one = 1;
}
static void _constructor_method_class_constructor2(Eo *obj, Constructor_Method_Class_Data *pd, double two)
{
fprintf(stderr, "two == %f\n", two);
fflush(stderr);
ck_assert(two == 10.0);
pd->two = 1;
}
@ -37,7 +45,6 @@ static Eo * _constructor_method_class_eo_base_finalize(Eo *obj, Constructor_Meth
if(!pd->one || !pd->two)
return NULL;
eo_do_super(obj, EO_BASE_CLASS, eo_finalize());
return obj;
}