Fixed undef handling.
[perl4caml.git] / perl.mli
index 73270d2..831d69b 100644 (file)
--- a/perl.mli
+++ b/perl.mli
@@ -2,7 +2,7 @@
   *
   * Copyright (C) 2003 Merjis Ltd.
   *
-  * $Id: perl.mli,v 1.8 2003-10-16 13:41:06 rich Exp $
+  * $Id: perl.mli,v 1.10 2003-10-26 11:22:38 rich Exp $
   *)
 
 type t
@@ -14,10 +14,8 @@ type sv
 type av
 (** Perl array value. *)
 
-(*
 type hv
 (** Perl hash value. *)
-*)
 
 exception Perl_failure of string
 (** [die] in Perl code is translated automatically into this exception. *)
@@ -90,9 +88,9 @@ val int_of_sv : sv -> int
   *)
 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. *)
@@ -138,6 +136,19 @@ val sv_type : sv -> sv_t
 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
@@ -148,13 +159,11 @@ val deref_array : sv -> av
   * array [AV]. If the input is not a reference to an array, throws
   * [Invalid_arg].
   *)
-(*
 val deref_hash : sv -> hv
 (** The input is a reference to a hash. This returns the underlying
   * hash [HV]. If the input is not a reference to a hash, throws
   * [Invalid_arg].
   *)
-*)
 
 val av_empty : unit -> av
 (** Create an empty [AV] (array). *)
@@ -187,6 +196,25 @@ val av_extend : av -> int -> unit
 val av_map : (sv -> 'a) -> av -> 'a list
 (** Map a function over the elements in the [AV], return a list of the
   * results. *)
+val list_of_av : av -> sv list
+(** Convert an [AV] into a simple list of [SV]s. *)
+val av_of_string_list : string list -> av
+(** Build an [AV] from a list of strings. *)
+
+val hv_empty : unit -> hv
+(** Create an empty [HV] (hash). *)
+val hv_set : hv -> string -> sv -> unit
+(** Store the given [SV] in the named key in the hash. *)
+val hv_get : hv -> string -> sv
+(** Return the [SV] at the key in the hash. Throws [Not_found] if no key. *)
+val hv_exists : hv -> string -> bool
+(** Return true if the hash contains the given key. Same as Perl [exists]. *)
+val hv_delete : hv -> string -> unit
+(** Delete the given key from the hash. Same as Perl [delete]. *)
+val hv_clear : hv -> unit
+(** Remove all elements from the [HV]. Same as Perl [%av = ()]. *)
+val hv_undef : hv -> unit
+(** Delete the [HV] (and all elements in it). Same as Perl [undef %hv]. *)
 
 val get_sv : ?create:bool -> string -> sv
 (** Return a scalar value by name. For example, if you have a symbol
@@ -200,6 +228,8 @@ val get_sv : ?create:bool -> string -> sv
   *)
 val get_av : ?create:bool -> string -> av
 (** Same as {!Perl.get_sv} except will return and/or create [\@a]. *)
+val get_hv : ?create:bool -> string -> hv
+(** Same as {!Perl.get_sv} except will return and/or create [%a]. *)
 
 val call : ?sv:sv -> ?fn:string -> sv list -> sv
 (** Call a Perl function in a scalar context, either by name (using the [?fn]