bindings: Various Improvements
authorJerome St-Louis <jerome@ecere.com>
Mon, 30 May 2016 08:02:01 +0000 (04:02 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:55 +0000 (09:18 -0500)
- vTbl inside CPPClass (data points back to CPPClass)
- Move constructor for Instance (copy constructor disabled)
- REGISTER and DESTRUCT macros

bindings/c/eC.c
bindings/c/eC.h
bindings/cpp/eC.cpp
bindings/cpp/eC.hpp
bindings/cpp/ecere.cpp
bindings/cpp/ecere.hpp
bindings/cpp/samples/form.cpp [new file with mode: 0644]
bindings/cpp/samples/sample1.cpp
bindings/cpp/samples/sample2.cpp
bindings/cpp/samples/sample3.cpp

index a6c2e1c..7a17b26 100644 (file)
@@ -8,12 +8,12 @@ void (*InitializeDataTypes)(Module module);
 void (*InitializeDataTypes1)(Module module);
 bool (*LocateModule)(const char *name, const char *fileName);
 void (*Print)(Class * class_object, void * object, ...);
-int (*PrintBuf)(char *buffer, int maxLen, Class * class_object, void * object, ...);
-void (*PrintLn)(Class * class_object, void * object, ...);
-int (*PrintLnBuf)(char *buffer, int maxLen, Class * class_object, void * object, ...);
-char *(*PrintLnString)(Class * class_object, void * object, ...);
-int (*PrintStdArgsToBuffer)(char *buffer, int maxLen, Class * class_object, void * object, va_list args);
-char *(*PrintString)(Class * class_object, void * object, ...);
+int (*PrintBuf)(char *buffer, int maxLen, Class * class_object, const void * object, ...);
+void (*PrintLn)(Class * class_object, const void * object, ...);
+int (*PrintLnBuf)(char *buffer, int maxLen, Class * class_object, const void * object, ...);
+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);
index 84978ed..1979d3a 100644 (file)
@@ -15,41 +15,6 @@ extern "C"
 {
 #endif
 
-#define Instance           eC_Instance
-#define Module             eC_Module
-#define Application        eC_Application
-#define Container          eC_Container
-#define Array              eC_Array
-#define CustomAVLTree      eC_CustomAVLTree
-#define AVLTree            eC_AVLTree
-#define Map                eC_Map
-#define LinkList           eC_LinkList
-#define List               eC_List
-#define IOChannel          eC_IOChannel
-#define SerialBuffer       eC_SerialBuffer
-#define OldArray           eC_OldArray
-
-#define Window             eC_Window
-#define ClassDesignerBase  eC_ClassDesignerBase
-#define DesignerBase       eC_DesignerBase
-
-// Structs / Unions (with methods or properties)
-#define Iterator           eC_Iterator
-#define MapIterator        eC_MapIterator
-#define BuiltInContainer   eC_BuiltInContainer
-#define BinaryTree         eC_BinaryTree
-#define StringBinaryTree   eC_StringBinaryTree
-#define OldList            eC_OldList
-
-// class : struct (with methods or properties)
-#define Class              eC_Class
-#define BTNode             eC_BTNode
-#define Item               eC_Item
-#define OldLink            eC_OldLink
-#define AVLNode            eC_AVLNode
-#define MapNode            eC_MapNode
-#define StringBTNode       eC_StringBTNode
-
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -118,26 +83,40 @@ extern "C"
 
 // GENERATED:
 
-#ifdef __cplusplus
-   // class : struct (with methods or properties)
-   #define Class eC_Class
-   #define BTNode eC_BTNode
-   #define Item eC_Item
-   #define OldLink eC_OldLink
-   #define AVLNode eC_AVLNode
-   #define MapNode eC_MapNode
-   #define StringBTNode eC_StringBTNode
-#endif
+#define Instance           eC_Instance
+#define Module             eC_Module
+#define Application        eC_Application
+#define Container          eC_Container
+#define Array              eC_Array
+#define CustomAVLTree      eC_CustomAVLTree
+#define AVLTree            eC_AVLTree
+#define Map                eC_Map
+#define LinkList           eC_LinkList
+#define List               eC_List
+#define IOChannel          eC_IOChannel
+#define SerialBuffer       eC_SerialBuffer
+#define OldArray           eC_OldArray
 
-#ifdef __cplusplus
-   // Structs / Unions (with methods or properties)
-   #define Iterator eC_Iterator
-   #define MapIterator eC_MapIterator
-   #define BuiltInContainer eC_BuiltInContainer
-   #define BinaryTree eC_BinaryTree
-   #define StringBinaryTree eC_StringBinaryTree
-   #define OldList eC_OldList
-#endif
+#define Window             eC_Window
+#define ClassDesignerBase  eC_ClassDesignerBase
+#define DesignerBase       eC_DesignerBase
+
+// Structs / Unions (with methods or properties)
+#define Iterator           eC_Iterator
+#define MapIterator        eC_MapIterator
+#define BuiltInContainer   eC_BuiltInContainer
+#define BinaryTree         eC_BinaryTree
+#define StringBinaryTree   eC_StringBinaryTree
+#define OldList            eC_OldList
+
+// class : struct (with methods or properties)
+#define Class              eC_Class
+#define BTNode             eC_BTNode
+#define Item               eC_Item
+#define OldLink            eC_OldLink
+#define AVLNode            eC_AVLNode
+#define MapNode            eC_MapNode
+#define StringBTNode       eC_StringBTNode
 
 // Defines
 #if defined(__cplusplus)
@@ -990,12 +969,12 @@ extern DesignerBase (*GetActiveDesigner)(void);
 extern Platform (*GetRuntimePlatform)(void);
 extern bool (*LocateModule)(const char *name, const char *fileName);
 extern void (*Print)(Class * class_object, void * object, ...);
-extern int (*PrintBuf)(char *buffer, int maxLen, Class * class_object, void * object, ...);
-extern void (*PrintLn)(Class * class_object, void * object, ...);
-extern int (*PrintLnBuf)(char *buffer, int maxLen, Class * class_object, void * object, ...);
-extern char *(*PrintLnString)(Class * class_object, void * object, ...);
-extern int (*PrintStdArgsToBuffer)(char *buffer, int maxLen, Class * class_object, void * object, va_list args);
-extern char *(*PrintString)(Class * class_object, void * object, ...);
+extern int (*PrintBuf)(char *buffer, int maxLen, Class * class_object, const void * object, ...);
+extern void (*PrintLn)(Class * class_object, const void * object, ...);
+extern int (*PrintLnBuf)(char *buffer, int maxLen, Class * class_object, const void * object, ...);
+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);
index 6ac6bef..59e9c07 100644 (file)
@@ -1,8 +1,8 @@
 #include "eC.hpp"
 
-CPPClass<Instance> Instance::_class;
-CPPClass<Module> Module::_class;
-CPPClass<Application> Application::_class;
+TCPPClass<Instance> Instance::_class;
+TCPPClass<Module> Module::_class;
+TCPPClass<Application> Application::_class;
 
 void eC_cpp_init(Module & module)
 {
index cffafcc..257a97d 100644 (file)
 
 #define newt(t, c) eC_new(class_ ## t->structSize * c)
 
-#define class_vtbl_setup(c) \
-   { typedef void (* Function)(void *); delete [] (Function *)_class->data; _class->data = new Function [_class->vTblSize]; \
-   memset(_class->data, 0, sizeof(Function) * _class->vTblSize); } \
-
 #define _REGISTER_CLASS(n, ns, bs, a) \
-   n::class_registration((Class *)eC_registerClass(normalClass, ns, bs, sizeof(Instance *), 0, \
-      (eC_bool (*)(void *)) n::constructor, (void(*)(void *)) n::destructor, (a).impl, privateAccess, publicAccess))
+   (Class *)eC_registerClass(normalClass, ns, bs, sizeof(Instance *), 0, \
+      (eC_bool (*)(void *)) n::constructor, (void(*)(void *)) n::destructor, (a).impl, privateAccess, publicAccess)
 
 // For defining _class and registereing together (single translation unit)
-#define REGISTER_CLASS_DEF(n, b, a)    CPPClass<n> n::_class(_REGISTER_CLASS(n,     #n, b::_class.impl->name, a));
+#define REGISTER_CLASS_DEF(n, b, a)    TCPPClass<n> n::_class(_REGISTER_CLASS(n,     #n, b::_class.impl->name, a));
 
 // For defining _class and registering separately (multiple translation units)
-#define CLASS_DEF(n)                   CPPClass<n> n::_class;
-#define REGISTER_CLASS(n, b, a)        n::_class.impl = _REGISTER_CLASS(n,       #n, b::_class.impl->name, a);
+#define CLASS_DEF(n)                   TCPPClass<n> n::_class;
+#define REGISTER_CLASS(n, b, a)        n::_class.setup(_REGISTER_CLASS(n,       #n, b::_class.impl->name, a));
 
 // For C++ classes proxying eC classes:
-#define REGISTER_CPP_CLASS(n, a)       n::_class.impl = _REGISTER_CLASS(n, "CPP" #n, #n, a);
+#define REGISTER_CPP_CLASS(n, a)       n::_class.setup(_REGISTER_CLASS(n, "CPP" #n, #n, a));
 
 #define _CONSTRUCT(c, b) \
-   static CPPClass<c> _class; \
+   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 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, Class * cl = _class.impl) : b(_impl, cl)
+   explicit inline c(eC_Instance _impl, CPPClass & cl = _class) : b(_impl, cl)
 
 #define CONSTRUCT(c, b) \
-   c() : c(Instance_new(_class.impl), _class.impl) { } \
+   c() : c(Instance_new(_class.impl), _class) { } \
    _CONSTRUCT(c, b)
 
+#define DESTRUCT(c) \
+   ((TCPPClass<c> &)_class).destructor
+
+#define REGISTER() \
+   static void class_registration(CPPClass & _class)
+
 #define APP_CONSTRUCT(c, b) \
    inline c() : c(eC_init_CALL) { } \
    _CONSTRUCT(c, b)
       FunctionType operator= (FunctionType func) \
       { \
          SELF(c, n); \
-         if(self->vTbl == c::_class.impl->data) \
+         if(self->vTbl == c::_class.vTbl) \
          { \
             uint size = c :: _class.impl->vTblSize; \
             self->vTbl = (void (**)())new FunctionType[size]; \
-            memcpy(self->vTbl, c::_class.impl->data, sizeof(FunctionType) * size); \
+            memcpy(self->vTbl, c::_class.vTbl, sizeof(FunctionType) * size); \
          } \
          ((FunctionType *)self->vTbl)[b ## _ ## n ## _vTblID] = func; \
          return func; \
          d; \
       } \
    } n; \
-   static void register_ ## n(Class * cl, c ## _ ## n ## _Functor::FunctionType func) \
+   static void register_ ## n(CPPClass & cl, c ## _ ## n ## _Functor::FunctionType func) \
    { \
-      ((c ## _ ## n ## _Functor::FunctionType *)cl->data)[b ## _ ## n ## _vTblID] = func; \
+      ((c ## _ ## n ## _Functor::FunctionType *)cl.vTbl)[b ## _ ## n ## _vTblID] = func; \
    }
 
 #define REGISTER_METHOD(ns, n, bc, c, r, p, o, a, ea, rv) \
-   addMethod(_class, ns, (void *) +[]p \
+   addMethod(_class.impl, ns, (void *) +[]p \
    { \
       Class * cl = (Class *)o->_class; \
       c * i = (c *)_INSTANCE(o, cl); \
@@ -142,19 +144,40 @@ extern "C" eC_Module ecere_init(eC_Module fromModule);
 
 class Class : public eC_Class { };
 
-template <class T>
 class CPPClass
 {
 public:
+   typedef void (* Function)(void);
    Class * impl;
-   void (*destructor)(T &);
+   Function * vTbl;
+};
 
-   CPPClass() { };
-   CPPClass(Class * _impl) : impl(_impl) { }
-   ~CPPClass()
+template <class T>
+class TCPPClass : public CPPClass
+{
+public:
+   TCPPClass() { }
+   TCPPClass(Class * _impl)
+   {
+      setup(_impl);
+   }
+   void (*destructor)(T &);
+   void setup(Class * _impl)
+   {
+      impl = _impl;
+      if(impl)
+      {
+         _impl->data = this;
+         if(vTbl) delete [] vTbl;
+         vTbl = new Function[impl->vTblSize];
+         memset(vTbl, 0, sizeof(Function) * impl->vTblSize);
+         T::class_registration(*this);
+      }
+   }
+   ~TCPPClass()
    {
       if(impl)
-         delete [] (void (**)(void))impl->data;
+         delete [] vTbl;
    }
 };
 
@@ -164,17 +187,18 @@ public:
 class Instance
 {
 public:
-   static CPPClass<Instance> _class;
+   static TCPPClass<Instance> _class;
    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; }
    static void destructor(eC_Instance i) { Instance * inst = (Instance *)_INSTANCE(i, _class.impl); delete inst; }
-
-   inline explicit Instance(eC_Instance _impl, Class * c = _class.impl)
+   static void class_registration(CPPClass & _class) { }
+   inline explicit Instance(eC_Instance _impl, CPPClass & cl = _class)
    {
+      Class * c = cl.impl;
       impl = _impl;
-      vTbl = c ? (void (**)(void))c->data : null;
+      vTbl = cl.vTbl;
       if(impl)
       {
          if(c && !_INSTANCE(impl, c))
@@ -182,13 +206,11 @@ public:
          impl->_refCount++;
       }
    }
-
    inline Instance()
    {
       impl = null;
       vTbl = null;
    }
-
    inline ~Instance()
    {
       if(impl && impl->_class)
@@ -196,38 +218,34 @@ public:
          Instance ** i = (Instance **)&INSTANCEL(impl, impl->_class);
          if(i && *i == this)
             *i = null;
-         if(vTbl && vTbl != impl->_class->data)
+         if(vTbl)
+         {
+            CPPClass * cl = (CPPClass *)impl->_class->data;
+            if(cl && vTbl != cl->vTbl)
             delete [] vTbl;
+         }
          Instance_decref(impl);
       }
    }
-
-   inline Instance(const Instance & i)
+   inline Instance(const Instance & i) = delete;
+   inline Instance(const Instance && i)
    {
       impl = i.impl;
-      vTbl = null;
-      if(impl)
-      {
-         impl->_refCount++;
-         if(i.vTbl)
-            vTbl = i.vTbl;
-      }
+      vTbl = i.vTbl;
    }
-
-   static Class * class_registration(Class * _class) { return _class; }
 };
 
 class Module : public Instance
 {
 public:
-   static CPPClass<Module> _class;
-   inline explicit Module(eC_Instance _impl, Class * c = _class.impl) : Instance(_impl, c) { }
+   static TCPPClass<Module> _class;
+   inline explicit Module(eC_Instance _impl, CPPClass & c = _class) : Instance(_impl, c) { }
 };
 
 void eC_cpp_init(Module & module);
 void ecere_cpp_init(Module & module);
 
-#define Application_class_registration(c, d) \
+#define Application_class_registration(d) \
    REGISTER_METHOD("Main", main, Application, d, void, (eC_Instance o), o, (*i), (o), );
 
 class Application : public Module
@@ -237,7 +255,7 @@ public:
    {
       eC_cpp_init(*this);
       _INSTANCE(impl, impl->_class) = this;
-      vTbl = (void (**)(void))_class.impl->data;
+      vTbl = _class.vTbl;
 
       // TODO: Omit this if we're linking against eC rt only
       ecere_init(impl);
@@ -247,7 +265,7 @@ public:
 #endif
    }
 
-   static Class * class_registration(Class * _class) { Application_class_registration(_class, Application); class_vtbl_setup(_class); return _class; }
+   static void class_registration(CPPClass & _class) { Application_class_registration(Application); }
 
    #undef   PSELF
    #define  PSELF SELF(Application, exitCode)
index b1bd4bf..92d074d 100644 (file)
@@ -1,12 +1,12 @@
 #include "ecere.hpp"
 
-CPPClass<GuiApplication> GuiApplication::_class;
-CPPClass<Surface> Surface::_class;
-CPPClass<FontResource> FontResource::_class;
-CPPClass<Window> Window::_class;
-CPPClass<Button> Button::_class;
-CPPClass<Label> Label::_class;
-CPPClass<MessageBox> MessageBox::_class;
+TCPPClass<GuiApplication> GuiApplication::_class;
+TCPPClass<Surface> Surface::_class;
+TCPPClass<FontResource> FontResource::_class;
+TCPPClass<Window> Window::_class;
+TCPPClass<Button> Button::_class;
+TCPPClass<Label> Label::_class;
+TCPPClass<MessageBox> MessageBox::_class;
 
 void ecere_cpp_init(Module & module)
 {
index 6458b89..8a0405a 100644 (file)
@@ -63,9 +63,9 @@ public:
    ecere::gui Namespace
 ****************************************************************************/
 ///////////// Window Class /////////////////////////////////////////////////
-#define Window_class_registration(c, d) \
-   REGISTER_METHOD("OnRedraw", onRedraw, Window, d, void, (eC_Instance o, eC_Instance s),    o, (*i, Surface { s }), (o, s), ); \
-   REGISTER_METHOD("OnCreate", onCreate, Window, d, bool, (eC_Instance o),                     o, (*i),                (o),    true);
+#define Window_class_registration(d) \
+   REGISTER_METHOD("OnRedraw", onRedraw, Window, d, void, (eC_Window o, eC_Surface s),    o, (*i, Surface { s }), (o, s), ); \
+   REGISTER_METHOD("OnCreate", onCreate, Window, d, bool, (eC_Window o),                  o, (*i),                (o),    true);
 
 bool foo(eC_Instance o);
 
@@ -74,7 +74,7 @@ class Window : public Instance
 public:
    CONSTRUCT(Window, Instance) { }
 
-   static Class * class_registration(Class * _class) { Window_class_registration(_class, Window); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Window_class_registration(Window); }
 
    VIRTUAL_METHOD(onCreate, Window, Window, bool, (Window &), (),
       return Window_onCreate(self->impl));
@@ -160,7 +160,7 @@ class Label : public Window
 public:
    CONSTRUCT(Label, Window) { }
 
-   static Class * class_registration(Class * _class) { Window_class_registration(_class, Label); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Window_class_registration(Label); }
 };
 
 ///////////// MessageBox Class /////////////////////////////////////////////////
@@ -174,7 +174,7 @@ public:
       this->contents = contents;
       this->caption = caption;
    }
-   static Class * class_registration(Class * _class) { Window_class_registration(_class, MessageBox); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Window_class_registration(MessageBox); }
 
    #undef PSELF
    #define PSELF SELF(MessageBox, contents)
@@ -186,10 +186,10 @@ public:
 };
 
 ///////////// Button Class /////////////////////////////////////////////////
-#define Button_class_registration(c, d) \
-   Window_class_registration(_class, d); \
+#define Button_class_registration(d) \
+   Window_class_registration(d); \
    REGISTER_METHOD("NotifyClicked", notifyClicked, Button, d, \
-      bool, (eC_Instance m, eC_Instance b, int x, int y, Modifiers mods), \
+      bool, (eC_Window m, eC_Button b, int x, int y, Modifiers mods), \
       b, (*(Window *)INSTANCEL(m, m->_class), *(Button *)INSTANCEL(b, b->_class), x, y, mods), \
       (m, b, x, y, mods), true);
 
@@ -198,7 +198,7 @@ class Button : public Window
 public:
    CONSTRUCT(Button, Window) { }
 
-   static Class * class_registration(Class * _class) { Button_class_registration(_class, Button); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Button_class_registration(Button); }
 
    VIRTUAL_METHOD(notifyClicked, Button, Button, bool, (Window &, Button &, int, int, Modifiers), (Window & window, Button & button, int x, int y, Modifiers mods),
       return Button_notifyClicked(self->impl, window.impl, button.impl, x, y, mods));
@@ -209,7 +209,7 @@ class ToolButton : public Button
 {
 public:
    CONSTRUCT(ToolButton, Button) { }
-   static Class * class_registration(Class * _class) { Button_class_registration(_class, ToolButton); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Button_class_registration(ToolButton); }
 
    #undef PSELF
    #define PSELF SELF(ToolButton, Foo)
@@ -223,10 +223,10 @@ public:
    {
       Instance_evolve(&impl, GuiApplication::_class.impl);
       _INSTANCE(impl, impl->_class) = this;
-      vTbl = (void (**)(void))_class.impl->data;
+      vTbl = _class.vTbl;
    }
 
-   static Class * class_registration(Class * _class) { Application_class_registration(_class, GuiApplication); class_vtbl_setup(_class); return _class; }
+   REGISTER() { Application_class_registration(GuiApplication); }
 };
 
 #endif
diff --git a/bindings/cpp/samples/form.cpp b/bindings/cpp/samples/form.cpp
new file mode 100644 (file)
index 0000000..866afcc
--- /dev/null
@@ -0,0 +1,88 @@
+#define MODULE_NAME  "HelloForm"
+
+// #define __CONSOLE_APP__
+
+#include "ecere.hpp"
+
+GuiApplication app;
+
+MAIN_DEFINITION;
+
+class HelloForm2 : public Window
+{
+public:
+   Button button;
+
+   CONSTRUCT(HelloForm2, Window)
+   {
+      caption = $("My Second Ecere/C++ Bindings App");
+      borderStyle = sizable;
+      clientSize = { 640, 480 };
+      hasClose = true;
+      hasMaximize = true;
+      hasMinimize = true;
+      background = formColor;
+      font = { "Arial", 30 };
+
+      button.parent = this;
+      button.position = { 200, 200 };
+      button.caption = $("Yay!!");
+      // button.onRedraw = [](Window & foo, Surface s){ };
+      button.notifyClicked = [](Window & owner, Button & btn, int x, int y, Modifiers mods)
+      {
+         double i = 3.14159265;
+         char tmp[256];
+         constString s = onGetString(class_double, &i, tmp, null, null);
+         PrintLn(class_String, "Hello! -- ", class_String, s, null); // Need to terminate with a null!
+         HelloForm2 & self = (HelloForm2 &)owner;
+         MessageBox($("C++ Bindings!"), self.button.caption).modal();
+         return true;
+      };
+
+      onCreate = [](Window & w)
+      {
+         MessageBox($("Cool"), $("Creation!")).modal();
+         return true;
+      };
+
+      //onRedraw(Surface());
+      //onCreate();
+   }
+
+   /*static void myOnRedraw(Window & w, Surface surface)
+   {
+      surface.writeTextf(100, 100, $("Testing stuff!"));
+      //surface.writeTextf(100, 100, "%d + %d = %d", 2, 3, 2+3);
+   };*/
+
+   REGISTER()
+   {
+      Window::class_registration(_class);
+      register_onRedraw(_class, [](Window & w, Surface surface)
+      {
+         surface.writeTextf(100, 100, $("Class Method!"));
+         //surface.writeTextf(100, 100, "%d + %d = %d", 2, 3, 2+3);
+      });
+   }
+};
+REGISTER_CLASS_DEF(HelloForm2, Window, app);
+
+class HelloForm3 : public HelloForm2
+{
+public:
+   CONSTRUCT(HelloForm3, HelloForm2)
+   {
+      background = 0x50B0F0;
+      position = { 0, 0 };
+
+      onRedraw = [](Window & w, Surface surface)
+      {
+         surface.writeTextf(100, 100, $("Instance Method!"));
+         //surface.writeTextf(100, 100, "%d + %d = %d", 2, 3, 2+3);
+      };
+   }
+};
+REGISTER_CLASS_DEF(HelloForm3, HelloForm2, app);
+
+HelloForm2 hello2;
+HelloForm3 hello3;
index ac81a11..832f6ee 100644 (file)
@@ -32,12 +32,13 @@ public:
       };
    }
 
-   static Class * class_registration(Class * _class)
+   REGISTER()
    {
       Window::class_registration(_class);
+
       register_onRedraw(_class, [](Window & w, Surface surface) { surface.writeTextf(100, 100, $("Class Method!")); });
-      HelloForm::_class.destructor = [](HelloForm & self) { printf("It's the end my friend!\n"); };
-      return _class;
+
+      DESTRUCT(HelloForm) = [](HelloForm & self) { printf("It's the end my friend!\n"); };
    }
 };
 
index 256bef7..a9b89eb 100644 (file)
@@ -32,11 +32,9 @@ public:
       };
    }
 
-   static Class * class_registration(Class * _class)
+   REGISTER()
    {
-      Window::class_registration(_class);
       register_onRedraw(_class, [](Window & w, Surface surface) { surface.writeTextf(100, 100, $("Class Method!")); });
-      return _class;
    }
 };
 
index 161a335..297475e 100644 (file)
@@ -32,11 +32,10 @@ public:
       };
    }
 
-   static Class * class_registration(Class * _class)
+   REGISTER()
    {
       Window::class_registration(_class);
       register_onRedraw(_class, [](Window & w, Surface surface) { surface.writeTextf(100, 100, $("Class Method!")); });
-      return _class;
    }
 };