bindings: Fixed support for C++ instantiating objects from eC
authorJerome St-Louis <jerome@ecere.com>
Wed, 1 Jun 2016 03:56:15 +0000 (23:56 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:56 +0000 (09:18 -0500)
- Opted to replace defining PSELF macro by extra parameter for set/get macros
- Tweaked SELF macro to include a 0x10 offset to avoid offsetof warnings on older MinGW/GCC
- ecs: Fixed both eC and C++ source files in the project (Using eC .main.ec main definition in that case,
   but not re-creating Application object; Defining __thisModule in eC.c for C/C++ only module)
- ecere/com/instance: Added eInstance_NewEx() with extra parameter to specify whether bindings construction still needs to be done
- Added 'bindingsClass' member to Class to use for bindings instead of data (Windows do make use of 'data' for class_data); Fixed class definition of Class and BinaryTree
- Commented out conflicting _strtoi64/_strtoui64
- Fixed enum declarations on non-C++11 (though the code still uses a lot of C++11 only features like constructor delegation)
- Fixed MAIN_DECLARATION to be 'extern "C" to work on older MinGW/GCC
- Overriding new and delete to able able to link without STL
- ecere/com/dataTypes: Fixed const_ness of Print* functions's typed_object parameter

bindings/c/eC.c
bindings/c/eC.h
bindings/c/ecere.h
bindings/cpp/eC.hpp
bindings/cpp/ecere.hpp
bindings/cpp/samples/foo.ec [new file with mode: 0644]
bindings/cpp/samples/form.cpp
bindings/cpp/samples/test.epj
compiler/ecs/ecs.ec
ecere/src/com/dataTypes.ec
ecere/src/com/instance.ec

index 22bf2b4..6ee1cf9 100644 (file)
@@ -15,8 +15,8 @@ char *(*PrintLnString)(Class * class_object, const void * object, ...);
 int (*PrintStdArgsToBuffer)(char *buffer, int maxLen, Class * class_object, const void * object, va_list args);
 char *(*PrintString)(Class * class_object, const void * object, ...);
 void (*SetActiveDesigner)(DesignerBase designer);
-int64 (*_strtoi64)(const char *string, const char **endString, int base);
-uint64 (*_strtoui64)(const char *string, const char **endString, int base);
+// int64 (*_strtoi64)(const char *string, const char **endString, int base);
+// uint64 (*_strtoui64)(const char *string, const char **endString, int base);
 uint (*log2i)(uint number);
 void (*memswap)(byte *a, byte *b, uint size);
 uint (*pow2i)(uint number);
@@ -99,6 +99,8 @@ int onSerialize_vTblID;
 int onUnserialize_vTblID;
 int onSaveEdit_vTblID;
 
+Class * class_Module;
+
 int Application_main_vTblID;
 
 Method * method_Application_main;
@@ -164,6 +166,8 @@ Application eC_init(bool guiApp, int argc, char * argv[])
 
          class_Instance = eC_findClass(app, "Instance");
 
+         class_Module = eC_findClass(app, "Module");
+
          class_Application = eC_findClass(app, "Application");
          if(class_Application)
          {
@@ -179,3 +183,5 @@ Application eC_init(bool guiApp, int argc, char * argv[])
    }
    return app;
 }
+
+Module __thisModule;
index 0c55764..67a0505 100644 (file)
@@ -28,11 +28,10 @@ extern "C"
 
 #define incref(x) (x)->_refCount++;
 
-#define newi(c) ({ Instance i = Instance_new(c); incref(i); i; })
-#ifndef __cplusplus
-   #define new(t, c) eC_new(class_ ## t->structSize * c)
-#endif
 #define newb(c) eC_new(c)
+#define newi(c) ({ eC_Instance i = Instance_new(c); incref(i); i; })
+#define newc(t, c) (t *)eC_new(class_ ## t->structSize * c)
+#define newt(t, c) (t *)eC_new(sizeof(t) * c)
 
 #define deletei(v) Instance_decref(v), v = null
 #ifndef __cplusplus
@@ -143,6 +142,7 @@ extern "C"
 #define Module_load              __ecereNameSpace__ecere__com__eModule_Load
 
 #define Instance_new             __ecereNameSpace__ecere__com__eInstance_New
+#define Instance_newEx           __ecereNameSpace__ecere__com__eInstance_NewEx
 #define Instance_delete          __ecereNameSpace__ecere__com__eInstance_Delete
 #define Instance_decref          __ecereNameSpace__ecere__com__eInstance_DecRef
 #define Instance_evolve          __ecereNameSpace__ecere__com__eInstance_Evolve
@@ -372,9 +372,10 @@ enum boolean
 };
 #endif
 
-enum BackSlashEscaping
 #if CPP11
-   : uint32
+enum BackSlashEscaping : uint32
+#else
+enum enum_BackSlashEscaping
 #endif
 { forArgsPassing = 2 };
 
@@ -471,6 +472,8 @@ struct BinaryTree
 {
    BTNode * root;
    int count;
+   int (*CompareKey)(BinaryTree * tree, uintptr a, uintptr b);
+   void (*FreeKey)(void * key);
 };
 
 struct OldList
@@ -591,9 +594,9 @@ struct Class
    NameSpace * nameSpace;
    const char *dataTypeString;
    Type dataType;
-   void (*Initialize)();
    int typeSize;
    int defaultAlignment;
+   void (*Initialize)();
    int memberOffset;
    OldList selfWatchers;
    const char *designerClass;
@@ -621,6 +624,7 @@ struct Class
    int numParams;
    bool isInstanceClass;
    bool byValueSystemClass;
+   void * bindingsClass;
 };
 struct ClassProperty
 {
@@ -894,8 +898,8 @@ extern __attribute__((dllimport)) Application __ecereNameSpace__ecere__com____ec
 
 extern __attribute__((dllimport)) Class * __ecereNameSpace__ecere__com__eSystem_FindClass(Module module, const char *name);
 extern __attribute__((dllimport)) Class * __ecereNameSpace__ecere__com__eSystem_RegisterClass(ClassType type, const char *name, const char *baseName, int size, int sizeClass, bool (*Constructor)(void *), void (*Destructor)(void *), Module module, AccessMode declMode, AccessMode inheritanceAccess);
-extern __attribute__((dllimport)) void * __ecereNameSpace__ecere__com__eSystem_new(uint size);
-extern __attribute__((dllimport)) void * __ecereNameSpace__ecere__com__eSystem_new0(uint size);
+extern __attribute__((dllimport)) void * __ecereNameSpace__ecere__com__eSystem_New(uint size);
+extern __attribute__((dllimport)) void * __ecereNameSpace__ecere__com__eSystem_New0(uint size);
 extern __attribute__((dllimport)) void *__ecereNameSpace__ecere__com__eSystem_Renew(void *memory, uint size);
 extern __attribute__((dllimport)) void *__ecereNameSpace__ecere__com__eSystem_Renew0(void *memory, uint size);
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eSystem_Delete(void *memory);
@@ -934,6 +938,7 @@ extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eClass_SetP
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eClass_Unregister(Class * _class);
 
 extern __attribute__((dllimport)) Instance __ecereNameSpace__ecere__com__eInstance_New(Class * _class);
+extern __attribute__((dllimport)) Instance __ecereNameSpace__ecere__com__eInstance_NewEx(Class * _class, bool bindingsAlloc);
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eInstance_Delete(Instance instance);
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eInstance_Evolve(Instance *instancePtr, Class * _class);
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__com__eInstance_SetMethod(Instance instance, constString name, void *function);
@@ -963,6 +968,8 @@ extern __attribute__((dllimport)) constString __ecereNameSpace__ecere__GetTransl
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__LoadTranslatedStrings(constString moduleName, constString name);
 extern __attribute__((dllimport)) void __ecereNameSpace__ecere__UnloadTranslatedStrings(constString name);
 
+extern Module __thisModule;
+
 // Global Functions
 extern void (*CheckConsistency)(void);
 extern void (*CheckMemory)(void);
@@ -977,8 +984,8 @@ extern char *(*PrintLnString)(Class * class_object, const void * object, ...);
 extern int (*PrintStdArgsToBuffer)(char *buffer, int maxLen, Class * class_object, const void * object, va_list args);
 extern char *(*PrintString)(Class * class_object, const void * object, ...);
 extern void (*SetActiveDesigner)(DesignerBase designer);
-extern int64 (*_strtoi64)(const char *string, const char **endString, int base);
-extern uint64 (*_strtoui64)(const char *string, const char **endString, int base);
+// extern int64 (*_strtoi64)(const char *string, const char **endString, int base);
+// extern uint64 (*_strtoui64)(const char *string, const char **endString, int base);
 extern uint (*log2i)(uint number);
 extern void (*memswap)(byte *a, byte *b, uint size);
 extern uint (*pow2i)(uint number);
@@ -1062,6 +1069,9 @@ extern Class * class_byte;
 // Instance Class
 extern Class * class_Instance;
 
+// Module Class
+extern Class * class_Module;
+
 // Application Class
 extern Class * class_Application;
 
index 6de16e0..2b547f1 100644 (file)
@@ -111,9 +111,10 @@ typedef uint32 Color;
 typedef Color SystemColor;
 #endif
 
-enum SystemColor
 #if CPP11
-   : Color
+enum SystemColor : Color
+#else
+enum enum_Color
 #endif
 {
    formColor = COLOR(229, 234, 245)
@@ -170,9 +171,11 @@ typedef int64 DialogResult;
 #endif
 
 // Enumerations
-enum DialogResult
+
 #if CPP11
-   : int64
+enum DialogResult : int64
+#else
+enum enum_DialogResult
 #endif
 {
    cancel = 0,
@@ -181,9 +184,10 @@ enum DialogResult
    ok = 3
 };
 
-enum BorderStyle
 #if CPP11
-   : BorderBits
+enum BorderStyle : BorderBits
+#else
+enum enum_BorderStyle
 #endif
 {
    none,
index 0ecc078..5a846ca 100644 (file)
@@ -16,7 +16,8 @@
 
 #define INSTANCE(x, c) ({c * _i = (c *)_INSTANCE(x, x->_class); _i ? *_i : c(x); })
 
-#define newt(t, c) eC_new(class_ ## t->structSize * c)
+#undef   newi
+#define  newi(c) Instance_newEx(c, true)
 
 #define _REGISTER_CLASS(n, ns, bs, a) \
    (Class *)eC_registerClass(normalClass, ns, bs, sizeof(Instance *), 0, \
 #define _CONSTRUCT(c, b) \
    INSTANCE_VIRTUAL_METHODS(c) \
    static TCPPClass<c> _class; \
-   static eC_bool constructor(eC_Instance i) { if(!Class_isDerived(i->_class, _class.impl)) return new c(i) != null; return true;} \
+   static eC_bool constructor(eC_Instance i, eC_bool alloc) { return (alloc && !_INSTANCE(i, _class.impl)) ? new c(i, _class) != null : true; } \
    static void destructor(eC_Instance i) { c * inst = (c *)_INSTANCE(i, _class.impl); if(_class.destructor) ((void (*)(c & self))_class.destructor)(*inst); delete inst; } \
    explicit inline c(eC_Instance _impl, CPPClass & cl = _class) : b(_impl, cl)
 
 #define CONSTRUCT(c, b) \
-   c() : c(Instance_new(_class.impl), _class) { } \
+   c() : c(Instance_newEx(_class.impl, false), _class) { } \
    _CONSTRUCT(c, b)
 
 #define DESTRUCT(c) \
@@ -60,7 +61,7 @@
 #endif
 
 #define MAIN_DEFINITION \
-   MAIN_DECLARATION \
+   extern "C" MAIN_DECLARATION \
    { \
       APP_SET_ARGS(app); \
       app.main(); \
@@ -68,7 +69,7 @@
       return app.exitCode; \
    }
 
-#define SELF(c, n)  c * self = ((c *)(((char *)this) - (char *)&((c *)0)->n))
+#define SELF(c, n)  c * self = ((c *)(((char *)this) + 0x10 - (char *)&((c *)0x10)->n))
 
 #define _ARG ,
 
@@ -83,7 +84,7 @@
          if(self->vTbl == c::_class.vTbl) \
          { \
             uint size = c :: _class.impl->vTblSize; \
-            self->vTbl = (void (**)())new FunctionType[size]; \
+            self->vTbl = (void (**)())newt(FunctionType, size); \
             memcpy(self->vTbl, c::_class.vTbl, sizeof(FunctionType) * size); \
          } \
          ((FunctionType *)self->vTbl)[b ## _ ## n ## _vTblID] = func; \
 
 #define REGISTER_TYPED_METHOD(ns, n, bc, c, r, p, ocl, oi, code, ea, rv) \
    _REGISTER_METHOD(\
-      CPPClass * cppcl = _class ? (CPPClass *)_class->data : null;, \
+      CPPClass * cppcl = _class ? (CPPClass *)_class->bindingsClass : null;, \
       else if(cppcl && cppcl->vTbl && cppcl->vTbl[vid]) \
       { \
          fn = (bc ## _ ## n ## _Functor::FunctionType) cppcl->vTbl[vid]; \
 
 #define property(n, sg) struct n ## Prop { n ## Prop() { }; int _[0]; sg } n;
 
-#define _set(t, n, d) \
+#define _set(t, n, c, d) \
    inline t operator= (t v) \
    { \
-      PSELF; \
+      SELF(c, n); \
       d; \
       return v; \
    } \
 
-#define set(t, n, d) \
-   _set(t, n, d) \
+#define set(t, n, c, d) \
+   _set(t, n, c, d) \
    inline n ## Prop & operator= (n ## Prop & prop) \
    { \
-      PSELF; \
+      SELF(c, n); \
       t v = prop; \
       d; \
       return prop; \
    }
 
-#define get(t, n, d) inline operator t () const { PSELF; d; }
+#define get(t, n, c, d) inline operator t () const { SELF(c, n); d; }
 
 extern "C" eC_Module ecere_init(eC_Module fromModule);
 
@@ -192,9 +193,9 @@ public:
       impl = _impl;
       if(impl)
       {
-         _impl->data = this;
-         if(vTbl) delete [] vTbl;
-         vTbl = new Function[impl->vTblSize];
+         _impl->bindingsClass = this;
+         if(vTbl) eC_delete(vTbl);
+         vTbl = newt(Function, impl->vTblSize);
          memset(vTbl, 0, sizeof(Function) * impl->vTblSize);
          T::class_registration(*this);
       }
@@ -202,7 +203,7 @@ public:
    ~TCPPClass()
    {
       if(impl)
-         delete [] vTbl;
+         eC_delete(vTbl);
    }
 };
 
@@ -300,10 +301,19 @@ public:
    eC_Instance impl;
    void (**vTbl)(void);
 
-   static eC_bool constructor(eC_Instance i) { if(!Class_isDerived(i->_class, _class.impl)) return new Instance(i) != null; return true; }
+   void * operator new   (uintsize count) { return eC_new(count); }
+   void * operator new [](uintsize count) { return eC_new(count); }
+   void operator delete   (void * ptr) { eC_delete(ptr); }
+   void operator delete [](void * ptr) { eC_delete(ptr); }
+
+   static eC_bool constructor(eC_Instance i, bool alloc)
+   {
+      if(alloc &&!_INSTANCE(i, _class.impl))
+         return new Instance(i, _class) != null;
+      return true;
+   }
    static void destructor(eC_Instance i) { Instance * inst = (Instance *)_INSTANCE(i, _class.impl); delete inst; }
    static void class_registration(CPPClass & _class);
-   //static void class_registration(CPPClass & _class) { Instance_class_registration(Instance); }
 
    INSTANCE_VIRTUAL_METHODS(Instance);
 
@@ -328,16 +338,16 @@ public:
    {
       if(impl && impl->_class)
       {
-         if(impl->_class->data)
+         if(impl->_class->bindingsClass)
          {
             Instance ** i = (Instance **)&INSTANCEL(impl, impl->_class);
             if(i && *i == this)
                *i = null;
             if(vTbl)
             {
-               CPPClass * cl = (CPPClass *)impl->_class->data;
+               CPPClass * cl = (CPPClass *)impl->_class->bindingsClass;
                if(cl && vTbl != cl->vTbl)
-               delete [] vTbl;
+               eC_delete(vTbl);
             }
          }
          Instance_decref(impl);
@@ -372,10 +382,12 @@ public:
       eC_cpp_init(*this);
       _INSTANCE(impl, impl->_class) = this;
       vTbl = _class.vTbl;
+      __thisModule = impl;
 
       // TODO: Omit this if we're linking against eC rt only
       ecere_init(impl);
       ecere_cpp_init(*this);
+
 #ifdef MODULE_NAME
       loadTranslatedStrings(null, MODULE_NAME);
 #endif
@@ -383,9 +395,7 @@ public:
 
    static void class_registration(CPPClass & _class) { Application_class_registration(Application); }
 
-   #undef   PSELF
-   #define  PSELF SELF(Application, exitCode)
-   property(exitCode, get(int, exitCode, return self ? _IPTR(self->impl, class_Application, class_members_Application)->exitCode : 0) );
+   property(exitCode, get(int, exitCode, Application, return self ? _IPTR(self->impl, class_Application, class_members_Application)->exitCode : 0) );
 
    VIRTUAL_METHOD(main, Application, Application, void, Application &, , ,
       return Application_main(self->impl));
index 583aaf2..9612533 100644 (file)
@@ -40,24 +40,21 @@ public:
       this->italic = italic;
    }
 
-   #undef PSELF
-   #define PSELF SELF(FontResource, bold)
-
    property(bold,
-      set(eC_bool, bold, FontResource_set_bold(self ? self->impl : null, v))
-      get(eC_bool, bold, return FontResource_get_bold(self ? self->impl : null))
+      set(eC_bool, bold, FontResource, FontResource_set_bold(self ? self->impl : null, v))
+      get(eC_bool, bold, FontResource, return FontResource_get_bold(self ? self->impl : null))
    );
    property(italic,
-      set(eC_bool, italic, FontResource_set_italic(self ? self->impl : null, v))
-      get(eC_bool, italic, return FontResource_get_italic(self ? self->impl : null))
+      set(eC_bool, italic, FontResource, FontResource_set_italic(self ? self->impl : null, v))
+      get(eC_bool, italic, FontResource, return FontResource_get_italic(self ? self->impl : null))
    );
    property(faceName,
-      set(constString, faceName, FontResource_set_faceName(self ? self->impl : null, v))
-      get(constString, faceName, return FontResource_get_faceName(self ? self->impl : null))
+      set(constString, faceName, FontResource, FontResource_set_faceName(self ? self->impl : null, v))
+      get(constString, faceName, FontResource, return FontResource_get_faceName(self ? self->impl : null))
    );
    property(size,
-      set(float, size, FontResource_set_size(self ? self->impl : null, v))
-      get(float, size, return FontResource_get_size(self ? self->impl : null))
+      set(float, size, FontResource, FontResource_set_size(self ? self->impl : null, v))
+      get(float, size, FontResource, return FontResource_get_size(self ? self->impl : null))
    );
 };
 
@@ -87,70 +84,67 @@ public:
    //void set_size(const Size & v) { Window_set_size(impl, &v); }
    //void set_hasClose(eC_bool v)  { Window_set_hasClose(impl, v); }
 
-   #undef   PSELF
-   #define  PSELF SELF(Window, parent)
-
    property(parent,
-      set(const Window &, parent, Window_set_parent(self ? self->impl : null, v.impl))
-      get(Window &, parent,
+      set(const Window &, parent, Window, Window_set_parent(self ? self->impl : null, v.impl))
+      get(Window &, parent, Window,
          eC_Instance i = Window_get_parent(self ? self->impl : null);
          return *(Window *)_INSTANCE(i, Window::_class.impl))
 
-      _set(const Window *, parent, Window_set_parent(self ? self->impl : null, v ? v->impl : null))
-      get(Window *, parent,
+      _set(const Window *, parent, Window, Window_set_parent(self ? self->impl : null, v ? v->impl : null))
+      get(Window *, parent, Window,
          eC_Instance i = Window_get_parent(self ? self->impl : null);
          return i ? (Window *)_INSTANCE(i, Window::_class.impl) : null)
 
-      get(Window, parent, return Window(Window_get_parent(self ? self->impl : null)));
+      get(Window, parent, Window, return Window(Window_get_parent(self ? self->impl : null)));
    );
    property(size,
-      set(const Size &, size, Window_set_size(self ? self->impl : null, &v))
-      get(Size, size, { Size v; Window_get_size(self ? self->impl : null, &v); return v; })
+      set(const Size &, size, Window, Window_set_size(self ? self->impl : null, &v))
+      get(Size, size, Window, { Size v; Window_get_size(self ? self->impl : null, &v); return v; })
    );
    property(clientSize,
-      set(const Size &, clientSize, Window_set_clientSize(self ? self->impl : null, &v))
-      get(Size,         clientSize, { Size v; Window_get_clientSize(self ? self->impl : null, &v); return v; })
+      set(const Size &, clientSize, Window, Window_set_clientSize(self ? self->impl : null, &v))
+      get(Size,         clientSize, Window, { Size v; Window_get_clientSize(self ? self->impl : null, &v); return v; })
    );
    property(position,
-      set(const Point &, position, Window_set_position(self ? self->impl : null, &v))
-      get(Point,         position, { Point v; Window_get_position(self ? self->impl : null, &v); return v; })
+      set(const Point &, position, Window, Window_set_position(self ? self->impl : null, &v))
+      get(Point,         position, Window, { Point v; Window_get_position(self ? self->impl : null, &v); return v; })
    );
    property(hasClose,
-      set(eC_bool, hasClose, Window_set_hasClose(self ? self->impl : null, v))
-      get(eC_bool, hasClose, return Window_get_hasClose(self ? self->impl : null))
+      set(eC_bool, hasClose, Window, Window_set_hasClose(self ? self->impl : null, v))
+      get(eC_bool, hasClose, Window, return Window_get_hasClose(self ? self->impl : null))
    );
    property(hasMinimize,
-      set(eC_bool, hasMinimize, Window_set_hasMinimize(self ? self->impl : null, v))
-      get(eC_bool, hasMinimize, return Window_get_hasMinimize(self ? self->impl : null))
+      set(eC_bool, hasMinimize, Window, Window_set_hasMinimize(self ? self->impl : null, v))
+      get(eC_bool, hasMinimize, Window, return Window_get_hasMinimize(self ? self->impl : null))
    );
    property(hasMaximize,
-      set(eC_bool, hasMaximize, Window_set_hasMaximize(self ? self->impl : null, v))
-      get(eC_bool, hasMaximize, return Window_get_hasMaximize(self ? self->impl : null))
+      set(eC_bool, hasMaximize, Window, Window_set_hasMaximize(self ? self->impl : null, v))
+      get(eC_bool, hasMaximize, Window, return Window_get_hasMaximize(self ? self->impl : null))
    );
    property(caption,
-      set(constString, caption, Window_set_caption(self ? self->impl : null, v))
-      get(constString, caption, return Window_get_caption(self ? self->impl : null))
+      set(constString, caption, Window, Window_set_caption(self ? self->impl : null, v))
+      get(constString, caption, Window, return Window_get_caption(self ? self->impl : null))
    );
    property(font,
-      set(const FontResource &, font, Window_set_font(self ? self->impl : null, v.impl))
-      get(FontResource &, font,
+      set(const FontResource &, font, Window, Window_set_font(self ? self->impl : null, v.impl))
+      get(FontResource &, font, Window,
             eC_Instance i = Window_get_font(self ? self->impl : null);
             return *(FontResource *)_INSTANCE(i, FontResource::_class.impl))
 
-      _set(const FontResource *, font, Window_set_font(self ? self->impl : null, v->impl))
-      get(FontResource *, font,
+      _set(const FontResource *, font,Window,  Window_set_font(self ? self->impl : null, v->impl))
+      get(FontResource *, font, Window,
             eC_Instance i = Window_get_font(self ? self->impl : null);
             return i ? (FontResource *)_INSTANCE(i, FontResource::_class.impl) : null)
 
-      get(FontResource, font, return FontResource(Window_get_font(self ? self->impl : null)))
+      get(FontResource, font, Window, return FontResource(Window_get_font(self ? self->impl : null)))
    );
    property(borderStyle,
-      set(BorderStyle, borderStyle, Window_set_borderStyle(self ? self->impl : null, v))
-      get(BorderStyle, borderStyle, return Window_get_borderStyle(self ? self->impl : null))
+      set(BorderStyle, borderStyle, Window, Window_set_borderStyle(self ? self->impl : null, v))
+      get(BorderStyle, borderStyle, Window, return Window_get_borderStyle(self ? self->impl : null))
    );
    property(background,
-      set(Color, background, Window_set_background(self ? self->impl : null, v))
-      get(Color, background, return Window_get_background(self ? self->impl : null))
+      set(Color, background, Window, Window_set_background(self ? self->impl : null, v))
+      get(Color, background, Window, return Window_get_background(self ? self->impl : null))
    );
 };
 
@@ -176,12 +170,9 @@ public:
    }
    REGISTER() { Window_class_registration(MessageBox); }
 
-   #undef PSELF
-   #define PSELF SELF(MessageBox, contents)
-
    property(contents,
-      set(constString, contents, MessageBox_set_contents(self ? self->impl : null, v))
-      get(constString, contents, return MessageBox_get_contents(self ? self->impl : null))
+      set(constString, contents, MessageBox, MessageBox_set_contents(self ? self->impl : null, v))
+      get(constString, contents, MessageBox, return MessageBox_get_contents(self ? self->impl : null))
    );
 };
 
@@ -210,9 +201,6 @@ class ToolButton : public Button
 public:
    CONSTRUCT(ToolButton, Button) { }
    REGISTER() { Button_class_registration(ToolButton); }
-
-   #undef PSELF
-   #define PSELF SELF(ToolButton, Foo)
 };
 
 ///////////// GuiApplication Class /////////////////////////////////////////////////
@@ -223,6 +211,7 @@ public:
    {
       Instance_evolve(&impl, GuiApplication::_class.impl);
       _INSTANCE(impl, impl->_class) = this;
+      __thisModule = impl;
       vTbl = _class.vTbl;
    }
 
diff --git a/bindings/cpp/samples/foo.ec b/bindings/cpp/samples/foo.ec
new file mode 100644 (file)
index 0000000..b02d707
--- /dev/null
@@ -0,0 +1,2 @@
+class HelloForm2;
+HelloForm2 form2 { };
index d2be761..3a79abc 100644 (file)
@@ -48,6 +48,8 @@ public:
 };
 REGISTER_CLASS_DEF(Foo, Instance, app);
 
+void testStuff();
+
 class HelloForm2 : public Window
 {
 public:
@@ -100,7 +102,7 @@ public:
             printf("after");
             */
             Surface s { };
-            ((Foo *)null)->onDisplay(s, 0,0,0, null, 0, 0);
+            Foo * o = (Foo *)null; o->onDisplay(s, 0,0,0, null, 0, 0);
             //((Foo *)&obj3)->onDisplay(Surface { }, 0,0,0, null, 0, 0);
 
             int r;
@@ -108,6 +110,8 @@ public:
             //r = obj2.onCompare(obj1); printf("result: %d\n", r);
             //r = obj1.onCompare(obj3); printf("result: %d\n", r);
             //printf("result: a = %d, b = %d\n", obj4.a, obj4.b);
+
+            testStuff();
          }
          return true;
       };
@@ -140,6 +144,13 @@ public:
 };
 REGISTER_CLASS_DEF(HelloForm2, Window, app);
 
+void testStuff()
+{
+   //eC_Class * c = eC_findClass(app.impl, "HelloForm2");
+   eC_Class * c = HelloForm2::_class.impl;
+   ((HelloForm2 *)_INSTANCE(newi(c), c))->modal();
+}
+
 class HelloForm3 : public HelloForm2
 {
 public:
@@ -158,5 +169,5 @@ public:
 };
 REGISTER_CLASS_DEF(HelloForm3, HelloForm2, app);
 
-HelloForm2 hello2;
-//HelloForm3 hello3;
+//HelloForm2 hello2;
+HelloForm3 hello3;
index 3869f0c..de9e6a7 100644 (file)
@@ -54,7 +54,8 @@
             "../ecere.hpp"
          ]
       },
-      "form.cpp"
+      "form.cpp",
+      "foo.ec"
    ],
    "ResourcesPath" : "",
    "Resources" : [
index 680f7c6..225f0d6 100644 (file)
@@ -460,6 +460,7 @@ static void WriteMain(const char * fileName)
       {
          f.Puts("   int exitCode;\n");
          f.Puts("   Module module;\n");
+         f.Puts("   bool setThingsUp = !__thisModule;\n");
       }
 
       //if(nonInst || thisAppClass)    // We use it all the time to get "Application" for the exit code now...
@@ -489,10 +490,15 @@ static void WriteMain(const char * fileName)
             f.Puts("      __thisModule = module;\n");
          f.Puts("   }\n\n");
       }
-      else if(targetPlatform == win32 && !isConsole)
-         f.Puts("   __thisModule = __currentModule = module = __ecere_COM_Initialize(1, 0, null);\n\n");
       else
-         f.Puts("   __thisModule = __currentModule = module = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n");
+      {
+         f.Puts("   if(setThingsUp)\n");
+         if(targetPlatform == win32 && !isConsole)
+            f.Puts("      __thisModule = __ecere_COM_Initialize(1, 0, null);\n\n");
+         else
+            f.Puts("      __thisModule = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n");
+         f.Puts("   __currentModule = module = __thisModule;\n");
+      }
 
       // First load all modules
       if(_imports.count)
@@ -651,7 +657,7 @@ static void WriteMain(const char * fileName)
       if(!isDynamicLibrary && thisAppClass)
       {
          f.Printf("   _class = eSystem_FindClass(__currentModule, \"%s\");\n", thisAppClass.name);
-         f.Printf("   eInstance_Evolve((Instance *)&__currentModule, _class);\n");
+         f.Printf("   if(setThingsUp) eInstance_Evolve((Instance *)&__currentModule, _class);\n");
          f.Printf("   __thisModule = __currentModule;\n");
       }
 
@@ -1973,6 +1979,8 @@ class SymbolgenApp : Application
                   thisAppClass = FindAppClass(&privateModule.application.privateNameSpace, false);
                */
                thisAppClass = SearchAppClass_Module(privateModule);
+               if(!thisAppClass)
+                  thisAppClass = eSystem_FindClass(privateModule, "Application");
             }
             WriteMain(output);
 
index c998aa0..9faca2e 100644 (file)
@@ -1204,6 +1204,7 @@ static void OnSerialize(Class _class, void * data, IOChannel channel)
    }
    else if(_class.type == normalClass || _class.type == noHeadClass || _class.type == structClass)
    {
+      // TOCHECK: Serializing null instances?
       //if(data)
       {
          Class lastClass = null;
@@ -2439,7 +2440,7 @@ void InitializeDataTypes(Module module)
    RegisterClass_String(module);
 }
 
-public int PrintStdArgsToBuffer(char * buffer, int maxLen, typed_object object, va_list args)
+public int PrintStdArgsToBuffer(char * buffer, int maxLen, const typed_object object, va_list args)
 {
    int len = 0;
    // TOFIX: OnGetString will need a maxLen as well
@@ -2477,7 +2478,7 @@ public int PrintStdArgsToBuffer(char * buffer, int maxLen, typed_object object,
    return len;
 }
 
-public int PrintBuf(char * buffer, int maxLen, typed_object object, ...)
+public int PrintBuf(char * buffer, int maxLen, const typed_object object, ...)
 {
    va_list args;
    int len;
@@ -2487,7 +2488,7 @@ public int PrintBuf(char * buffer, int maxLen, typed_object object, ...)
    return len;
 }
 
-public int PrintLnBuf(char * buffer, int maxLen, typed_object object, ...)
+public int PrintLnBuf(char * buffer, int maxLen, const typed_object object, ...)
 {
    va_list args;
    int len;
@@ -2499,7 +2500,7 @@ public int PrintLnBuf(char * buffer, int maxLen, typed_object object, ...)
    return len;
 }
 
-public char * PrintString(typed_object object, ...)
+public char * PrintString(const typed_object object, ...)
 {
    char buffer[4096];
    va_list args;
@@ -2513,7 +2514,7 @@ public char * PrintString(typed_object object, ...)
    return string;
 }
 
-public char * PrintLnString(typed_object object, ...)
+public char * PrintLnString(const typed_object object, ...)
 {
    char buffer[4096];
    va_list args;
@@ -2534,7 +2535,7 @@ public char * PrintLnString(typed_object object, ...)
 #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ecere-app", __VA_ARGS__))
 #endif
 
-public void PrintLn(typed_object object, ...)
+public void PrintLn(const typed_object object, ...)
 {
    va_list args;
    char buffer[4096];
@@ -2548,7 +2549,7 @@ public void PrintLn(typed_object object, ...)
 #endif
 }
 
-public void Print(typed_object object, ...)
+public void Print(const typed_object object, ...)
 {
    va_list args;
    char buffer[4096];
index 4b43127..1c25c0e 100644 (file)
@@ -390,6 +390,7 @@ public:
    int numParams;       // TOTAL number of params including all base classes; use templateParams.count for this level
    bool isInstanceClass;
    bool byValueSystemClass;
+   void * bindingsClass;
 
    property const char *
    {
@@ -4618,12 +4619,12 @@ public dllexport Method eClass_FindMethod(Class _class, const char * name, Modul
 }
 
 // Construct an instance
-static bool ConstructInstance(void * instance, Class _class, Class from)
+static bool ConstructInstance(void * instance, Class _class, Class from, bool bindingsAlloc)
 {
    if(_class.templateClass) _class = _class.templateClass;
    if(_class.base && from != _class.base)
    {
-      if(!ConstructInstance(instance, _class.base, from))
+      if(!ConstructInstance(instance, _class.base, from, false))
          return false;
    }
    if(_class.Initialize)
@@ -4634,7 +4635,12 @@ static bool ConstructInstance(void * instance, Class _class, Class from)
    }
    if(_class.Constructor)
    {
-      if(!_class.Constructor(instance))
+      bool result;
+      if(_class.bindingsClass)
+         result = ((bool (*)(void *, bool))(void *)_class.Constructor)(instance, bindingsAlloc);
+      else
+         result = _class.Constructor(instance);
+      if(!result)
       {
          for(; _class; _class = _class.base)
          {
@@ -4649,7 +4655,7 @@ static bool ConstructInstance(void * instance, Class _class, Class from)
    return true;
 }
 
-public dllexport void * eInstance_New(Class _class)
+static void * Instance_New(Class _class, bool bindingsAlloc)
 {
    Instance instance = null;
    if(_class)
@@ -4711,7 +4717,7 @@ public dllexport void * eInstance_New(Class _class)
          // Copy the virtual table initially
          instance._vTbl = _class._vTbl;
       }
-      if(instance && !ConstructInstance(instance, _class, null))
+      if(instance && !ConstructInstance(instance, _class, null, bindingsAlloc))
       {
          _free(instance);
          instance = null;
@@ -4722,6 +4728,16 @@ public dllexport void * eInstance_New(Class _class)
    return instance;
 }
 
+public dllexport void * eInstance_New(Class _class)
+{
+   return Instance_New(_class, true);
+}
+
+public dllexport void * eInstance_NewEx(Class _class, bool bindingsAlloc)
+{
+   return Instance_New(_class, bindingsAlloc);
+}
+
 public dllexport void eInstance_Evolve(Instance * instancePtr, Class _class)
 {
    if(_class && instancePtr && *instancePtr)
@@ -4831,7 +4847,7 @@ public dllexport void eInstance_Evolve(Instance * instancePtr, Class _class)
       instance._vTbl = _class._vTbl;
 
       // We don't want to reconstruct the portion already constructed...
-      if(!ConstructInstance(instance, _class, fromClass))
+      if(!ConstructInstance(instance, _class, fromClass, false))
       {
          _free(instance);
          *instancePtr = null;
@@ -6284,7 +6300,7 @@ public dllexport void eProperty_SelfWatch(Class _class, const char * name, void
    }
 }
 
-public dllexport void eInstance_Watch(void * instance, Property _property, void * object, void (*callback)(void *, void *))
+public dllexport void eInstance_Watch(Instance instance, Property _property, void * object, void (*callback)(void *, void *))
 {
    if(_property.isWatchable)
    {