From 09967410e1ae0623c634df95c309f859881f2ddb Mon Sep 17 00:00:00 2001 From: zach Date: Thu, 2 Nov 2023 14:20:19 -0700 Subject: [PATCH] cleanup: add Val_type.ptr as an alias for ValType::I64 (#11) --- README.md | 4 ++-- examples/kv.ml | 4 ++-- examples/runner.ml | 4 ++-- src/extism.mli | 3 +++ src/val_type.ml | 2 ++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c1b9c1..e0edd4c 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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 diff --git a/examples/kv.ml b/examples/kv.ml index 54ffb02..7394929 100644 --- a/examples/kv.ml +++ b/examples/kv.ml @@ -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; @@ -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 diff --git a/examples/runner.ml b/examples/runner.ml index d297bda..e3f3f98 100644 --- a/examples/runner.ml +++ b/examples/runner.ml @@ -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; diff --git a/src/extism.mli b/src/extism.mli index 1ed536b..a9301d6 100644 --- a/src/extism.mli +++ b/src/extism.mli @@ -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 *) diff --git a/src/val_type.ml b/src/val_type.ml index b0f373a..759d3cb 100644 --- a/src/val_type.ml +++ b/src/val_type.ml @@ -1 +1,3 @@ include Bindings.Extism_val_type + +let ptr = I64