Fixed support for floats.
(* Interface to Perl from OCaml.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: perl.ml,v 1.8 2003-10-18 12:36:09 rich Exp $
+ * $Id: perl.ml,v 1.9 2003-10-26 11:22:38 rich Exp $
*)
type t
external int_of_sv : sv -> int = "perl4caml_int_of_sv"
external sv_of_int : int -> sv = "perl4caml_sv_of_int"
-external float_of_sv : sv -> int = "perl4caml_float_of_sv"
-external sv_of_float : int -> sv = "perl4caml_sv_of_float"
+external float_of_sv : sv -> float = "perl4caml_float_of_sv"
+external sv_of_float : float -> sv = "perl4caml_sv_of_float"
external string_of_sv : sv -> string = "perl4caml_string_of_sv"
external sv_of_string : string -> sv = "perl4caml_sv_of_string"
external sv_is_true : sv -> bool = "perl4caml_sv_is_true"
| SVt_PVGV -> "SVt_PVGV"
| SVt_PVMG -> "SVt_PVMG"
+external scalarref : sv -> sv = "perl4caml_scalarref"
+external arrayref : av -> sv = "perl4caml_arrayref"
+external hashref : hv -> sv = "perl4caml_hashref"
+
external deref : sv -> sv = "perl4caml_deref"
external deref_array : sv -> av = "perl4caml_deref_array"
external deref_hash : sv -> hv = "perl4caml_deref_hash"
*
* Copyright (C) 2003 Merjis Ltd.
*
- * $Id: perl.mli,v 1.9 2003-10-18 12:36:09 rich Exp $
+ * $Id: perl.mli,v 1.10 2003-10-26 11:22:38 rich Exp $
*)
type t
*)
val sv_of_int : int -> sv
(** Convert an [int] into a Perl [SV]. *)
-val float_of_sv : sv -> int
+val float_of_sv : sv -> float
(** Convert a Perl [SV] into a float. *)
-val sv_of_float : int -> sv
+val sv_of_float : float -> sv
(** Convert a [float] into a Perl [SV]. *)
val string_of_sv : sv -> string
(** Convert a Perl [SV] into a string. *)
val string_of_sv_t : sv_t -> string
(** Return a printable string for an [sv_t] ([SV] type). *)
+val scalarref : sv -> sv
+(** Given a scalar, this returns a reference to the scalar. Note that
+ * because references are [SV]s, this returns [sv].
+ *)
+val arrayref : av -> sv
+(** Given an array, this returns a reference to the array. Note that
+ * because references are [SV]s, this returns [sv].
+ *)
+val hashref : hv -> sv
+(** Given a hash, this returns a reference to the hash. Note that
+ * because references are [SV]s, this returns [sv].
+ *)
+
val deref : sv -> sv
(** The input is a reference to a scalar. This returns the underlying
* scalar [SV]. If the input is not a reference to a scalar, throws
/* Interface to Perl from OCaml.
* Copyright (C) 2003 Merjis Ltd.
- * $Id: perl_c.c,v 1.8 2003-10-18 12:36:09 rich Exp $
+ * $Id: perl_c.c,v 1.9 2003-10-26 11:22:38 rich Exp $
*/
#include <stdio.h>
}
CAMLprim value
+perl4caml_scalarref (value svv)
+{
+ CAMLparam1 (svv);
+ CAMLlocal1 (rsvv);
+ SV *sv = Sv_val (svv);
+ rsvv = Val_sv (newRV_inc (sv));
+ CAMLreturn (rsvv);
+}
+
+CAMLprim value
+perl4caml_arrayref (value avv)
+{
+ CAMLparam1 (avv);
+ CAMLlocal1 (rsvv);
+ AV *av = Av_val (avv);
+ rsvv = Val_sv (newRV_inc ((SV *) av));
+ CAMLreturn (rsvv);
+}
+
+CAMLprim value
+perl4caml_hashref (value hvv)
+{
+ CAMLparam1 (hvv);
+ CAMLlocal1 (rsvv);
+ HV *hv = Hv_val (hvv);
+ rsvv = Val_sv (newRV_inc ((SV *) hv));
+ CAMLreturn (rsvv);
+}
+
+CAMLprim value
perl4caml_deref (value svv)
{
CAMLparam1 (svv);