bindings/c;cpp: Sample apps overriding Application/GuiApplication
authorJerome St-Louis <jerome@ecere.com>
Thu, 22 Sep 2016 15:32:51 +0000 (11:32 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 21 Nov 2016 14:18:59 +0000 (09:18 -0500)
- Added GuiApplication::Cycle to C prototype bindings

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

index 6aaaa2b..fe8475b 100644 (file)
@@ -131,6 +131,9 @@ constString (* Picture_get_image)(Picture p);
 
 Class * class_GuiApplication;
 
+Method * method_GuiApplication_cycle;
+int GuiApplication_cycle_vTblID;
+
 Class * class_MessageBox;
 
 Property * property_MessageBox_contents;
@@ -359,6 +362,12 @@ Module ecere_init(Module fromModule)
       }
 
       class_GuiApplication = eC_findClass(module, "GuiApplication");
+      if(class_GuiApplication)
+      {
+         method_GuiApplication_cycle = Class_findMethod(class_GuiApplication, "Cycle", module);
+         if(method_GuiApplication_cycle)
+            GuiApplication_cycle_vTblID = method_GuiApplication_cycle->vid;
+      }
    }
    return module;
 }
index ac9136a..f658d1f 100644 (file)
@@ -58,6 +58,10 @@ 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; })
+
 // Bit Class Member Access
 #define COLOR_r_MASK       0x00FF0000
 #define COLOR_r_SHIFT      16
@@ -384,6 +388,8 @@ extern Class * class_GuiApplication;
 
 typedef Instance GuiApplication;
 
+extern int GuiApplication_cycle_vTblID;
+
 Module ecere_init(Module fromModule);
 
 #ifdef __cplusplus
index 09b88b4..6fc70e6 100644 (file)
@@ -208,6 +208,11 @@ public:
 };
 
 ///////////// GuiApplication Class /////////////////////////////////////////////////
+#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);
+
 class GuiApplication : public Application
 {
 public:
@@ -219,7 +224,9 @@ public:
       vTbl = _class.vTbl;
    }
 
-   REGISTER() { Application_class_registration(GuiApplication); }
+   REGISTER() { GuiApplication_class_registration(GuiApplication); }
+   VIRTUAL_METHOD(cycle, GuiApplication, GuiApplication, bool, GuiApplication &, , ,
+      return GuiApplication_cycle(self->impl));
 };
 
 #endif
diff --git a/bindings/cpp/samples/helloApp.cpp b/bindings/cpp/samples/helloApp.cpp
new file mode 100644 (file)
index 0000000..942935c
--- /dev/null
@@ -0,0 +1,28 @@
+#define MODULE_NAME  "MyApp"
+
+#include "eC.hpp"
+
+class MyApp : public Application
+{
+public:
+   APP_CONSTRUCT(MyApp, Application) { }
+   static void class_registration(CPPClass & _class);
+};
+
+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;
diff --git a/bindings/cpp/samples/helloApp2.cpp b/bindings/cpp/samples/helloApp2.cpp
new file mode 100644 (file)
index 0000000..70c703c
--- /dev/null
@@ -0,0 +1,16 @@
+#define MODULE_NAME  "MyApp"
+
+#include "eC.hpp"
+
+class MyApp : public Application
+{
+public:
+   void main()
+   {
+      PrintLn(class_String, "C++: Hello, eC", null);
+   }
+};
+
+MyApp app;
+
+MAIN_DEFINITION
diff --git a/bindings/cpp/samples/helloApp3.cpp b/bindings/cpp/samples/helloApp3.cpp
new file mode 100644 (file)
index 0000000..231f51d
--- /dev/null
@@ -0,0 +1,29 @@
+#define MODULE_NAME  "MyApp"
+
+#include "ecere.hpp"
+
+class MyApp : public GuiApplication
+{
+public:
+   APP_CONSTRUCT(MyApp, GuiApplication)
+   {
+      cycle = +[](GuiApplication & app)
+      {
+         PrintLn(class_String, "   Cycling!", null);
+         return true;
+      };
+   }
+
+   void main()
+   {
+      PrintLn(class_String, "C++: Hello, eC", null);
+      GuiApplication::main();
+   }
+};
+
+MyApp app;
+Window w;
+
+REGISTER_CLASS_DEF(MyApp, GuiApplication, app);
+
+MAIN_DEFINITION