On 06/03/2017 22:27, Bruno Albuquerque wrote:
Ok, thanks. It appears cfish_ParcelSpec does not exist in 0.4.2. Is there
an alternative?

In 0.4, Class_bootstrap is declared as

   void
   Class_bootstrap(const cfish_ClassSpec *specs, size_t num_specs);

and cfish_ClassSpec is

    typedef struct cfish_ClassSpec {
        cfish_Class **klass;
        cfish_Class **parent;
        const char   *name;
        size_t        ivars_size;
        size_t       *ivars_offset_ptr;
        uint32_t      num_novel_meths;
        uint32_t      num_overridden_meths;
        uint32_t      num_inherited_meths;
        const cfish_NovelMethSpec      *novel_meth_specs;
        const cfish_OverriddenMethSpec *overridden_meth_specs;
        const cfish_InheritedMethSpec  *inherited_meth_specs;
    } cfish_ClassSpec;

So something like the following should work:

    size_t MyAnalyzer_IVARS_OFFSET;

    // Create a subclass with ivars at runtime.
    static Class*
    S_class_var(void) {
        StackString *class_name = SSTR_WRAP_UTF8("MyAnalyzer", 10);
        Class *klass = Class_fetch_class((String*)class_name);
        if (!klass) {
            cfish_ClassSpec class_spec = {
                &klass,
                &ANALYZER,
                "MyAnalyzer",
                sizeof(MyAnalyzerIVARS),
                &MyAnalyzer_IVARS_OFFSET,
                0, 0, 0,
                NULL, NULL, NULL
            };
            Class_bootstrap(&class_spec, 1);
            Class_Override(klass,
                           (cfish_method_t)S_MyAnalyzer_Transform_IMP,
                           LUCY_Analyzer_Transform_OFFSET);
        }
        return klass;
    }

Nick

Reply via email to