#include "mlp_perl.h" SV *mlp_perl_allocate_SV(mlp_perl_runtime *rt, mlp_type t, mlp_value *v){ PerlInterpreter *my_perl = rt->_get_my_perl() ; if (v == NULL){ return &PL_sv_undef ; } switch (t){ case MLP_INT: return newSViv(v->to_int()) ; case MLP_LONG: return newSViv(v->to_long()) ; case MLP_DOUBLE: return newSVnv(v->to_double()) ; case MLP_STRING: const char *s = v->to_string() ; if (s == NULL){ return &PL_sv_undef ; } return newSVpv(s, 0) ; case MLP_OBJECT: const mlp_object *o = v->to_object() ; if (o == NULL){ return &PL_sv_undef ; } return sv_setref_pv(sv_newmortal(), "mlp::object", (void *)o) ; } } mlp_value *mlp_perl_allocate_mlp_value(mlp_perl_runtime *rt, mlp_type t, SV *sv){ PerlInterpreter *my_perl = rt->_get_my_perl() ; if (! SvOK(sv)){ return new mlp_value((const char *)NULL) ; } switch (t){ case MLP_INT: return new mlp_value(SvIV(sv)) ; case MLP_LONG: return new mlp_value(SvIV(sv)) ; case MLP_DOUBLE: return new mlp_value(SvNV(sv)) ; case MLP_STRING: return new mlp_value(SvPV_nolen(sv)) ; case MLP_OBJECT: return NULL ; // TODO: Wrap whatever is on the stack into an mlp_perl_object } }