simple example of how to embed C in ecere

General help with the core C language of which eC is a superset, integrating eC with other languages such as C++ at the C level, using C libraries in eC, etc.
Post Reply
amigojapan
Posts: 3
Joined: Fri Jul 29, 2022 7:43 am

simple example of how to embed C in ecere

Post by amigojapan »

Code: Select all

import "ecere"


class Form1 : Window
{
   caption = $"Form1";
   background = formColor;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   clientSize = { 320, 304 };

   //*** How to call a C function form ecere
   extern int myFunction(int val) {
      //C code in here
      return __GNUC__+val;
   }
   Label label1 { this, caption = $"label1", position = { 48, 24 } };
   Button button1
   {
      this, caption = $"button1", position = { 144, 72 };

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         int v;v=1;//value to send to C function
         int a=myFunction(v);
         char c[100];
         sprintf(c,"%d",a);
         label1.text=c;
         return true;
      }
   };
}

Form1 form1 {};
amigojapan
Posts: 3
Joined: Fri Jul 29, 2022 7:43 am

Re: simple example of how to embed C in ecere

Post by amigojapan »

my bad, I had gotten something confused, turns out all you need to do to run C is add a c file to the project, you do this by going to the project view and clickign add file from the context menu. then those files can just call C functions... easier than I thought!
Post Reply