*
* Copyright (C) 2003 Merjis Ltd.
*
- * $Id: perl.mli,v 1.4 2003-10-12 17:33:14 rich Exp $
+ * $Id: perl.mli,v 1.5 2003-10-14 16:05:21 rich Exp $
*)
type t
type sv
(** Perl scalar value. *)
+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. *)
(** Return the type of data contained in an [SV]. Somewhat equivalent to
* calling Perl's [ref] function.
*)
+val string_of_sv_t : sv_t -> string
+(** Return a printable string for an [sv_t] ([SV] type). *)
external deref : sv -> sv = "perl4caml_deref"
(** 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
* [Invalid_arg].
*)
-(*
external deref_array : sv -> av = "perl4caml_deref_array"
(** The input is a reference to an array. This returns the underlying
* array [AV]. If the input is not a reference to an array, throws
* [Invalid_arg].
*)
+(*
external deref_hash : sv -> hv = "perl4caml_deref_hash"
(** 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
*)
*)
+external av_empty : unit -> av = "perl4caml_av_empty"
+(** Create an empty [AV] (array). *)
+external av_of_sv_list : sv list -> av = "perl4caml_av_of_sv_list"
+(** Create an array from a list of [SVs]. *)
+external av_push : av -> sv -> unit = "perl4caml_av_push"
+(** Append the [SV] to the end of the array. Same as Perl [push @av, $sv]. *)
+external av_pop : av -> sv = "perl4caml_av_pop"
+(** Remove the [SV] at the end of the array and return it. Same as
+ * Perl [$sv = pop @av]. *)
+external av_shift : av -> sv = "perl4caml_av_shift"
+(** Remove the [SV] at the beginning of the array and return it. Same as
+ * Perl [$sv = shift @av]. *)
+external av_unshift : av -> sv -> unit = "perl4caml_av_unshift"
+(** Prepend the [SV] to the start of the array. Same as Perl
+ * [unshift @av, $sv]. *)
+external av_length : av -> int = "perl4caml_av_length"
+(** Return the length of the [AV]. *)
+external av_set : av -> int -> sv -> unit = "perl4caml_av_set"
+(** Replace the i'th element of the [AV] with [SV]. *)
+external av_get : av -> int -> sv = "perl4caml_av_get"
+(** Get the i'th element of the [AV]. *)
+external av_clear : av -> unit = "perl4caml_av_clear"
+(** Remove all elements from the [AV]. Same as Perl [@av = ()]. *)
+external av_undef : av -> unit = "perl4caml_av_undef"
+(** Delete the [AV] (and all elements in it). Same as Perl [undef @av]. *)
+external av_extend : av -> int -> unit = "perl4caml_av_extend"
+(** Extend the [AV] so it contains at least [n+1] elements. *)
+val av_map : (sv -> 'a) -> av -> 'a list
+(** Map a function over the elements in the [AV], return a list of the
+ * results. *)
+
external get_sv : ?create:bool -> string -> sv = "perl4caml_get_sv"
(** Return a scalar value by name. For example, if you have a symbol
* called [$a] in Perl, then [get_sv "a"] will return its value.
* not exist, then Perl will create the symbol (with value [undef]) and
* this function will return the [SV] for [undef].
*)
+external get_av : ?create:bool -> string -> av = "perl4caml_get_av"
+(** Same as {!get_sv} except will return and/or create [@a]. *)
external call : ?sv:sv -> ?fn:string -> sv list -> sv
= "perl4caml_call"