Browse thread
creating a functional value from C
- dmitry grebeniuk
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | dmitry grebeniuk <gds-mlsts@m...> |
| Subject: | creating a functional value from C |
Hello. I want to create a functional value from C world, which can be called from OCaml. Something to make this code work: external create_func_val : int -> (string -> string) = "c_create_func_val"; value fv = create_func_val 123; print_string (fv "abc"); print_string (fv "def"); Real situation is more complex -- functions "c_create_func_val" and "fv" both has side effects, so I can't just rewrite last lines as "print_string (create_func_val 123 "abc"); print_string (create_func_val 123 "def");", moreover, the real address that will be stored in "fv"-closure becomes known only in function "c_create_func_val", and it is the address of C function that follow all gc-related conventions (takes and returns "value"s, uses CAMLparam and so on). As a simplification, "fv" should not hold any ML values in its environment. Is it possible? If yes, then how to do it? Reading OCaml sources hadn't helped me. -- WBR, dmitry mailto:gds-mlsts@moldavcable.com