123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185let(//)=Filename.concatletpaths=["/usr/lib";"/usr/local/lib";Sys.getenv"HOME"//".local/lib";Sys.getcwd();]letcheckx=leta=x//"libextism.so"inletb=x//"libextism.dylib"inifSys.file_existsathenSomeaelseifSys.file_existsbthenSomebelseNoneletlocate()=letinit=matchSys.getenv_opt"EXTISM_PATH"with|Somepath->(matchcheckpathwithNone->check(path//"lib")|Some_asx->x)|None->NoneinList.fold_left(funaccpath->matchaccwithSome_->acc|None->checkpath)initpaths|>function|Somex->x|None->(letfailn=Printf.fprintfstderr"Unable to find Extism installation, see \
https://extism.org/docs/install/ for installation instructions\n";exitninmatchSys.getenv_opt"EXTISM_TEST_NO_LIB"with|None->fail1|Some_->fail0)letfrom=letfilename=locate()inDl.dlopen~filename~flags:[Dl.RTLD_GLOBAL;Dl.RTLD_NOW]openCtypesletfn=Foreign.foreign~from~release_runtime_lock:trueletcontext=ptrvoidletextism_context_new=fn"extism_context_new"(void@->returningcontext)letextism_context_free=fn"extism_context_free"(context@->returningvoid)moduleExtism_val_type=structtypet=I32|I64|F32|F64|V128|FuncRef|ExternRefletto_int=function|I32->0|I64->1|F32->2|F64->3|V128->4|FuncRef->5|ExternRef->6letof_int=function|0->I32|1->I64|2->F32|3->F64|4->V128|5->FuncRef|6->ExternRef|n->invalid_arg("Extism_val_type.of_int: "^string_of_intn)lett:ttyp=view~read:of_int~write:to_intintendmoduleExtism_val_union=structtypetlett:tuniontyp=union"ExtismValUnion"leti32=fieldt"i32"int32_tleti64=fieldt"i64"int64_tletf32=fieldt"f32"floatletf64=fieldt"f64"doublelet()=sealtendmoduleExtism_val=structtypetlett:tstructuretyp=structure"ExtismVal"letty=fieldt"t"Extism_val_type.tletv=fieldt"v"Extism_val_union.tlet()=sealtendletextism_plugin_new=fn"extism_plugin_new"(context@->string@->uint64_t@->ptr(ptrvoid)@->uint64_t@->bool@->returningint32_t)letextism_plugin_update=fn"extism_plugin_update"(context@->int32_t@->string@->uint64_t@->ptr(ptrvoid)@->uint64_t@->bool@->returningbool)letextism_plugin_config=fn"extism_plugin_config"(context@->int32_t@->string@->uint64_t@->returningbool)letextism_plugin_call=fn"extism_plugin_call"(context@->int32_t@->string@->ptrchar@->uint64_t@->returningint32_t)letextism_plugin_call_s=fn"extism_plugin_call"(context@->int32_t@->string@->string@->uint64_t@->returningint32_t)letextism_error=fn"extism_error"(context@->int32_t@->returningstring_opt)letextism_plugin_output_length=fn"extism_plugin_output_length"(context@->int32_t@->returninguint64_t)letextism_plugin_output_data=fn"extism_plugin_output_data"(context@->int32_t@->returning(ptrchar))letextism_log_file=fn"extism_log_file"(string@->string_opt@->returningbool)letextism_version=fn"extism_version"(void@->returningstring)letextism_plugin_free=fn"extism_plugin_free"(context@->int32_t@->returningvoid)letextism_context_reset=fn"extism_context_reset"(context@->returningvoid)letextism_plugin_function_exists=fn"extism_plugin_function_exists"(context@->int32_t@->string@->returningbool)letextism_function_type=Foreign.funptr~runtime_lock:true(ptrvoid@->ptrExtism_val.t@->uint64_t@->ptrExtism_val.t@->uint64_t@->ptrvoid@->returningvoid)letextism_free_user_data=Foreign.funptr_opt~runtime_lock:true(ptrvoid@->returningvoid)letextism_function_new=fn"extism_function_new"(string@->ptrExtism_val_type.t@->uint64_t@->ptrExtism_val_type.t@->uint64_t@->extism_function_type@->ptrvoid@->extism_free_user_data@->returning(ptrvoid))letextism_function_set_namespace=fn"extism_function_set_namespace"(ptrvoid@->string@->returningvoid)letextism_function_free=fn"extism_function_free"(ptrvoid@->returningvoid)letextism_current_plugin_memory=fn"extism_current_plugin_memory"(ptrvoid@->returning(ptruint8_t))letextism_current_plugin_memory_length=fn"extism_current_plugin_memory_length"(ptrvoid@->uint64_t@->returninguint64_t)letextism_current_plugin_memory_alloc=fn"extism_current_plugin_memory_alloc"(ptrvoid@->uint64_t@->returninguint64_t)letextism_current_plugin_memory_free=fn"extism_current_plugin_memory_free"(ptrvoid@->uint64_t@->returningvoid)letextism_plugin_cancel_handle=fn"extism_plugin_cancel_handle"(context@->int32_t@->returning(ptrvoid))letextism_plugin_cancel=fn"extism_plugin_cancel"(ptrvoid@->returningbool)