Giter Site home page Giter Site logo

c-methods's Introduction

C-methods

A library to add a very simple Object Orienting to C. Yet limited tools.
Just #include "methods.h"

Usage:

```C #include #include "methods.h"

// class declaration with the class keyword class (SomeClass){ // attributes before methods int attr1; double attr2; // Method declaration like function pointer. // Highly advised to put the first arg, // it will pass the self pointer int (method1)(SomeClass, int, int); };

// it is heavily advised to declare // a macro like this. // it will help setting up the // instances a lot faster. // surround with do-while(0) to avoid bugs #define SomeClass_set(var)
do{
var.method1 = _SomeClass_method1;
}while(0)

// method keyword to define methods outside the class // this will declare a function called _SomeClass_method1 int method (SomeClass, method1, int num1, int num2){ // self pointer self->attr1 += num1 * num2; return num1; }

int main(){ // fast initializer to the values SomeClass somevar = {35, 12}; SomeClass_set(somevar); // without this, the methods won't work // different kind of method call $(somevar, method1, 9, 11); // is exactly the same as somevar.method1(&somevar, 9, 11);

printf("%d\n", $(somevar, method1, 0, 3)); return 0; }

// if( problems || sugestions ){ // send_email( [email protected] ); // }


<h3>About:</h3>

Already supports:
<ul>
  <li> class attribute access </li>
  <li> self pointer </li>
  <li> method calls with arguments or not </li>
  <li> brace enclosed initializer </li>
  <li> dynamic definition of methods </li>
  <li> static keyword </li>
</ul>

Developing:
<ul>
  <li> inheritance </li>
  <li> method override </li>
  <li> private methods </li>
  <li> private attributes </li>
  <li> superclass pointer </li>
</ul>

Feel free to contribute.

c-methods's People

Contributors

jhlr avatar

Watchers

James Cloos avatar  avatar

Forkers

haifenghuang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.