Working with JavaScriptCore's C API and I have this C function pointer signature:
typedef void
(*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object);
And here is a problematic usage:
JSClassDefinition def = kJSClassDefinitionEmpty;
// This is that previously typed out signature being used
def.initialize = [](JSContextRef ctx, JSObjectRef obj){
CAMLlocal2(init_context, init_obj);
init_context = caml_alloc(sizeof(JSContextRef), Abstract_tag);
init_obj = caml_alloc(sizeof(JSObjectRef), Abstract_tag);
Store_field(init_context, 0, (value)ctx);
Store_field(init_obj, 0, (value)obj);
// Need to call this but can't because class_def is
// from the outside and can't be put in the capture list
//caml_callback2(Field(class_def, 5), init_context, init_obj);
};
So I'm not sure what's the right way to get around this. I don't want to start defining C functions all over the place because I need to create these callbacks dynamically and I'm not sure how to do the global state solution correctly because that will introduce more issues of locking correctly, etc.
I'm also open to using objective-C blocks, just the blocks, no objective-C. Saw some mentions of std::function
but I don't understand C++ well enough to use that API.
Looking through the Apple Objective-C layer on top of JSC to see how they did it....
EDIT1:Found this link as a possible solution, http://p-nand-q.com/programming/cplusplus/using_member_functions_with_c_function_pointers .html but its pretty deep in C++ knowledge of which mine is limited.
EDIT2: I guess I need something to template magic generate the code for me?