bindings/cpp; c: addressed Application class registration issues
authorJerome St-Louis <jerome@ecere.com>
Thu, 22 Sep 2016 21:04:10 +0000 (17:04 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:59 +0000 (09:18 -0500)
- New REGISTER_APP_CLASS and EVOLVE_APP macros
- Improved Application class registration samples
- Added missing GuiApplication::cycle() 'idle' parameter

bindings/c/ecere.h
bindings/cpp/eC.hpp
bindings/cpp/ecere.hpp
bindings/cpp/samples/helloApp.cpp
bindings/cpp/samples/helloApp3.cpp
bindings/cpp/samples/helloApp4.cpp [new file with mode: 0644]

index f658d1f..9e87bed 100644 (file)
@@ -58,9 +58,9 @@ extern "C"
                                                       bool (* method)(eC_Window, eC_Button, int, int, Modifiers) = (bool (*)(eC_Window, eC_Button, int, int, Modifiers))(i ? i->_vTbl : class_Button->_vTbl)[Button_notifyClicked_vTblID]; \
                                                       method ? method(m, b, x, y, mods) : true; })
 
-#define GuiApplication_cycle(x)    ({  eC_GuiApplication i = x; \
-                                  bool (* method)(eC_GuiApplication) = (bool (*)(eC_Instance))(i ? i->_vTbl : class_GuiApplication->_vTbl)[GuiApplication_cycle_vTblID]; \
-                                  method ? method(i) : true; })
+#define GuiApplication_cycle(x, idle)    ({  eC_GuiApplication i = x; \
+                                  bool (* method)(eC_GuiApplication, bool) = (bool (*)(eC_Instance, bool))(i ? i->_vTbl : class_GuiApplication->_vTbl)[GuiApplication_cycle_vTblID]; \
+                                  method ? method(i, idle) : true; })
 
 // Bit Class Member Access
 #define COLOR_r_MASK       0x00FF0000
index 2130d79..7d0e227 100644 (file)
 // For C++ classes proxying eC classes:
 #define REGISTER_CPP_CLASS(n, a)       n::_class.setup(_REGISTER_CLASS(n, "CPP" #n, #n, a));
 
+#define EVOLVE_APP(ac, a) \
+   Instance_evolve(&(a).impl, ac::_class.impl); \
+   _INSTANCE((a).impl, (a).impl->_class) = &(a); \
+   __thisModule = (a).impl; \
+   (a).vTbl = _class.vTbl;
+
+#define REGISTER_APP_CLASS(ac, b, a) \
+   REGISTER_CLASS(ac, b, a); \
+   EVOLVE_APP(ac, a)
+
 #define _CONSTRUCT(c, b) \
    INSTANCE_VIRTUAL_METHODS(c) \
    static TCPPClass<c> _class; \
index 6fc70e6..68037c2 100644 (file)
@@ -211,22 +211,15 @@ public:
 #define GuiApplication_class_registration(d) \
    Application_class_registration(d); \
    REGISTER_METHOD("Cycle", cycle, GuiApplication, d, \
-      bool, (eC_GuiApplication a), a, a, return fn(*i), (a), true);
+      bool, (eC_GuiApplication a, bool idle), a, a, return fn(*i, idle), (a, idle), true);
 
 class GuiApplication : public Application
 {
 public:
-   APP_CONSTRUCT(GuiApplication, Application)
-   {
-      Instance_evolve(&impl, GuiApplication::_class.impl);
-      _INSTANCE(impl, impl->_class) = this;
-      __thisModule = impl;
-      vTbl = _class.vTbl;
-   }
-
+   APP_CONSTRUCT(GuiApplication, Application) { EVOLVE_APP(GuiApplication, *this); }
    REGISTER() { GuiApplication_class_registration(GuiApplication); }
-   VIRTUAL_METHOD(cycle, GuiApplication, GuiApplication, bool, GuiApplication &, , ,
-      return GuiApplication_cycle(self->impl));
+   VIRTUAL_METHOD(cycle, GuiApplication, GuiApplication, bool, GuiApplication & _ARG, , bool idle,
+      return GuiApplication_cycle(self->impl, idle));
 };
 
 #endif
index 942935c..68922b3 100644 (file)
@@ -2,27 +2,25 @@
 
 #include "eC.hpp"
 
+class MyApp;
+extern MyApp app;
+
 class MyApp : public Application
 {
 public:
    APP_CONSTRUCT(MyApp, Application) { }
-   static void class_registration(CPPClass & _class);
+   REGISTER()
+   {
+      register_main(_class, [](Application & app)
+      {
+         PrintLn(class_String, "C++: Hello, eC", null);
+      });
+      EVOLVE_APP(MyApp, app);
+   }
 };
 
 MyApp app;
 
-void MyApp::class_registration(CPPClass & _class)
-{
-   register_main(_class, [](Application & app)
-   {
-      PrintLn(class_String, "C++: Hello, eC", null);
-   });
-   Instance_evolve(&app.impl, MyApp::_class.impl);
-   _INSTANCE(app.impl, app.impl->_class) = &app;
-   __thisModule = app.impl;
-   app.vTbl = _class.vTbl;
-}
-
 REGISTER_CLASS_DEF(MyApp, Application, app);
 
 MAIN_DEFINITION;
index 231f51d..7527adf 100644 (file)
@@ -7,11 +7,24 @@ class MyApp : public GuiApplication
 public:
    APP_CONSTRUCT(MyApp, GuiApplication)
    {
-      cycle = +[](GuiApplication & app)
+      REGISTER_APP_CLASS(MyApp, GuiApplication, *this);
+      /*
+      cycle = +[](GuiApplication & app, bool idle)
       {
          PrintLn(class_String, "   Cycling!", null);
          return true;
       };
+      */
+   }
+
+   REGISTER()
+   {
+      GuiApplication_class_registration(GuiApplication);
+      register_cycle(_class, [](GuiApplication & app, bool idle)
+      {
+         PrintLn(class_String, "   Cycling!", null);
+         return true;
+      });
    }
 
    void main()
@@ -23,7 +36,5 @@ public:
 
 MyApp app;
 Window w;
-
-REGISTER_CLASS_DEF(MyApp, GuiApplication, app);
-
+CLASS_DEF(MyApp);
 MAIN_DEFINITION
diff --git a/bindings/cpp/samples/helloApp4.cpp b/bindings/cpp/samples/helloApp4.cpp
new file mode 100644 (file)
index 0000000..281931a
--- /dev/null
@@ -0,0 +1,21 @@
+#define MODULE_NAME  "MyApp"
+
+#include "eC.hpp"
+
+class MyApp : public Application
+{
+public:
+   APP_CONSTRUCT(MyApp, Application)
+   {
+      REGISTER_APP_CLASS(MyApp, Application, *this);
+
+      main = [](Application & app)
+      {
+         PrintLn(class_String, "C++: Hello, eC", null);
+      };
+   }
+};
+
+MyApp app;
+CLASS_DEF(MyApp);
+MAIN_DEFINITION;