a toolkit for OOP programming in C language
Monk-C, is a toolkit for OOP programming use pure C (static library). the aim of Monk-C is to support OOP in pure C with some tiny C macros, functions and even a light preprocessor (optional). Monk-C is inspired by Apple Objective-C and gcc builtin "Constructing Calls". It is tiny and primitive but full of fun. I use it to play with my RaspberryPi and it really vary suitable for the ARM/Linux based embeded systems. It is open source under BSD license(3-clause license).
- Monk-C 3.0 version will based on ANSI C standard. providing a modern syntax. https://github.com/sunpaq/monkc-next
1 wiki page on github
https://github.com/sunpaq/BohdiAR-pod
https://github.com/sunpaq/BohdiEngineDemoSwift
in 'platforms/windows' folder of this repo, there have a Visual Studio Solution 'monkc.sln' you can build 'monkc.lib' using it. the binary and header will copy into 'output' folder
here is a demo using the 'monkc.lib' in other Visual Studio Solution the binary and header placed into its 'libs' folder https://github.com/sunpaq/monkc4win64
clang/gcc
git
ruby
sudo gem install colored
sudo gem install mcbuild
./build.rb all
./build.rb run
please use "build-linux.rb" on linux
1.[SublimeText Menu -> Preferences -> Browse Packages...] open the plugin folder
2.copy the 'mcsublime-snippets' folder into 'User'
MCBuild is a script library written use Ruby. Helping C/Monk-C developr generate Makefile. https://github.com/sunpaq/mcbuild
Monk-C use "MC" as the prefix.
#include "monkc.h"
class(MCSort, MCObject,
MCGeneric* array;
size_t length);
method(MCSort, void, bye, voida);
method(MCSort, MCSort*, initWithArray, MCGeneric* array, size_t length);
method(MCSort, void, insertionSort, voida);
method(MCSort, void, quickSort, voida);
method(MCSort, void, printArray, voida);
#include "MCSort.h"
oninit(MCSort)
{
if (init(MCObject)) {
var(array) = null;
var(length) = 0;
return obj;
}else{
return null;
}
}
method(MCSort, void, bye, voida)
{
if (obj->array && obj->length > 0) {
free(obj->array);
}
}
method(MCSort, MCSort*, initWithArray, MCGeneric* array, size_t length)
{
var(array) = (MCGeneric*)malloc(sizeof(MCGeneric) * length);
for (size_t i=0; i<length; i++) {
obj->array[i] = array[i];
}
var(length) = length;
//debug
//ff(obj, printArray, 0);
return obj;
}
function(void, swap, size_t a, size_t b)
{
as(MCSort);
if (a < b) {
MCGeneric t = obj->array[a];
obj->array[a] = obj->array[b];
obj->array[b] = t;
}
}
method(MCSort, void, insertionSort, voida)
{
}
function(void, quicksort, const size_t l, const size_t r)
{
as(MCSort);
if (l >= r || l > obj->length || r > obj->length) {
//debug_log("quicksort exit l=%ld r=%ld\n", l, r);
return;
}
MCGeneric pivot = obj->array[l];
size_t cur=l;
for (size_t idx=l+1; idx<=r; idx++) {
if (MCGenericCompare(obj->array[idx], pivot) < 0)
swap(obj, ++cur, idx);
}
swap(obj, l, cur);
quicksort(obj, l, cur-1);
quicksort(obj, cur+1, r);
}
method(MCSort, void, quickSort, voida)
{
quicksort(obj, 0, var(length)-1);
}
method(MCSort, void, printArray, voida)
{
for (size_t i=0; i<obj->length; i++) {
printf("element of array[%ld]=%.2f\n", i, obj->array[i].mcfloat);
}
}
onload(MCSort)
{
if (load(MCObject)) {
binding(MCSort, void, bye, voida);
binding(MCSort, MCSort*, initWithArray, MCGeneric* array, size_t length);
binding(MCSort, void, insertionSort, voida);
binding(MCSort, void, quickSort, voida);
binding(MCSort, void, printArray, voida);
return cla;
}else{
return null;
}
}
it just like the Objective-C. sending message instead of function call.
Bird* bird = new(Bird);
ff(bird, fly, 0);
C style: Bird_fly(bird, 0);
- class
- method (binding)
- function (mixing)
- compute (computing)
- utility
- var
- new
- ff
- oninit (init)
- onload (load)
- retain
- release
- recycle
- obj
- cla
- voida & null
Total only 16 words.1
Footnotes
-
the syntex is improving, maybe more/less keywords in the future. ↩