Skip to content

Commit

Permalink
cleanup: add Val_type.ptr as an alias for ValType::I64 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored Nov 2, 2023
1 parent a9065e4 commit 0996741
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let make_kv_plugin () =
let kv_read =
let open Val_type in
Function.create "kv_read" ~params:[ I64 ] ~results:[ I64 ] ~user_data:()
Function.create "kv_read" ~params:[ ptr ] ~results:[ ptr ] ~user_data:()
@@ fun plugin () ->
let key = Host_function.input_string plugin in
Printf.printf "Reading from key=%s\n" key;
Expand All @@ -177,7 +177,7 @@ let make_kv_plugin () =
let kv_write =
let open Val_type in
Function.create "kv_write" ~params:[ I64; I64 ] ~results:[] ~user_data:()
Function.create "kv_write" ~params:[ ptr; ptr ] ~results:[] ~user_data:()
@@ fun plugin () ->
let key = Host_function.input_string ~index:0 plugin in
let value = Host_function.input_string ~index:1 plugin in
Expand Down
4 changes: 2 additions & 2 deletions examples/kv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let make_kv_plugin () =

let kv_read =
let open Val_type in
Function.create "kv_read" ~params:[ I64 ] ~results:[ I64 ] ~user_data:()
Function.create "kv_read" ~params:[ ptr ] ~results:[ ptr ] ~user_data:()
@@ fun plugin () ->
let key = Host_function.input_string plugin in
Printf.printf "Reading from key=%s\n" key;
Expand All @@ -28,7 +28,7 @@ let make_kv_plugin () =

let kv_write =
let open Val_type in
Function.create "kv_write" ~params:[ I64; I64 ] ~results:[] ~user_data:()
Function.create "kv_write" ~params:[ ptr; ptr ] ~results:[] ~user_data:()
@@ fun plugin () ->
let key = Host_function.input_string ~index:0 plugin in
let value = Host_function.input_string ~index:1 plugin in
Expand Down
4 changes: 2 additions & 2 deletions examples/runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ let functions =
let v = Host_function.param plugin 0 in
Host_function.set_result plugin 0 v
in
let params = [ Val_type.I64 ] in
let results = [ Val_type.I64 ] in
let params = [ Val_type.ptr ] in
let results = [ Val_type.ptr ] in
[
Function.create "hello_world" ~user_data:() ~params ~results id;
Function.create "transform_string" ~user_data:() ~params ~results id;
Expand Down
3 changes: 3 additions & 0 deletions src/extism.mli
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ module Val_type : sig
| FuncRef
| ExternRef (** Value type *)

val ptr : t
(** An alias for [I64] to signify an Extism pointer value *)

val of_int : int -> t
(** Convert from [int] to {!t},
@raise Invalid_argument if the integer isn't valid *)
Expand Down
2 changes: 2 additions & 0 deletions src/val_type.ml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include Bindings.Extism_val_type

let ptr = I64

0 comments on commit 0996741

Please sign in to comment.