native.h | native.h | |||
---|---|---|---|---|
skipping to change at line 52 | skipping to change at line 52 | |||
* module is given bar and defines stuff in that. | * module is given bar and defines stuff in that. | |||
* | * | |||
* The purpose of this is to allow a module with lazy properties | * The purpose of this is to allow a module with lazy properties | |||
* by allowing module objects to be custom classes. It's used for | * by allowing module objects to be custom classes. It's used for | |||
* the gobject-introspection module for example. | * the gobject-introspection module for example. | |||
*/ | */ | |||
GJS_NATIVE_SUPPLIES_MODULE_OBJ = 1 << 0 | GJS_NATIVE_SUPPLIES_MODULE_OBJ = 1 << 0 | |||
} GjsNativeFlags; | } GjsNativeFlags; | |||
/* | ||||
* In a native module, you define a GjsDefineModuleFunc that | ||||
* adds your stuff to module_obj. | ||||
* | ||||
* You then declare GJS_REGISTER_NATIVE_MODULE("my.module.path", my_module_ | ||||
func) | ||||
* | ||||
* This declaration will call gjs_register_native_module() when your | ||||
* module is dlopen'd. We can't just use a well-known symbol name | ||||
* in your module, because we need to dlopen modules with | ||||
* global symbols. | ||||
*/ | ||||
typedef JSBool (* GjsDefineModuleFunc) (JSContext *context, | typedef JSBool (* GjsDefineModuleFunc) (JSContext *context, | |||
JSObject *module_obj); | JSObject *module_obj); | |||
/* FIXME - Reuse glib/glib/gconstructor.h */ | /* called on context init */ | |||
#ifdef __GNUC__ | ||||
#define _GJS_CONSTRUCTOR __attribute__((constructor)) | ||||
#elif __SUNPRO_C | ||||
#define Pragma(x) _Pragma(#x) | ||||
#define _GJS_CONSTRUCTOR Pragma(init(register_native_module)) | ||||
#else | ||||
Initialization routine in a dynamic object not defined for current compiler | ||||
#endif | ||||
#define GJS_REGISTER_NATIVE_MODULE_WITH_FLAGS(module_id_string, module_func | ||||
, flags) \ | ||||
_GJS_CONSTRUCTOR static void \ | ||||
register_native_module (void) | ||||
\ | ||||
{ | ||||
\ | ||||
gjs_register_native_module(module_id_string, module_func, flags); \ | ||||
} | ||||
#define GJS_REGISTER_NATIVE_MODULE(module_id_string, module_func) | ||||
\ | ||||
GJS_REGISTER_NATIVE_MODULE_WITH_FLAGS(module_id_string, module_func, 0) | ||||
/* called in constructor function on dlopen() load */ | ||||
void gjs_register_native_module (const char *module_id, | void gjs_register_native_module (const char *module_id, | |||
GjsDefineModuleFunc func, | GjsDefineModuleFunc func, | |||
GjsNativeFlags flags); | GjsNativeFlags flags); | |||
/* called by importer.c to to check for already loaded modules */ | /* called by importer.c to to check for already loaded modules */ | |||
gboolean gjs_is_registered_native_module(JSContext *context, | gboolean gjs_is_registered_native_module(JSContext *context, | |||
JSObject *parent, | JSObject *parent, | |||
const char *name); | const char *name); | |||
/* called by importer.c to load a native module once it finds | /* called by importer.c to load a statically linked native module */ | |||
* it in the search path | JSBool gjs_import_native_module (JSContext *context, | |||
*/ | JSObject *module_obj, | |||
JSBool gjs_import_native_module (JSContext *context, | const char *name); | |||
JSObject *module_obj, | ||||
const char *filename, | ||||
GjsNativeFlags *flags_p); | ||||
G_END_DECLS | G_END_DECLS | |||
#endif /* __GJS_NATIVE_H__ */ | #endif /* __GJS_NATIVE_H__ */ | |||
End of changes. 3 change blocks. | ||||
45 lines changed or deleted | 5 lines changed or added | |||