Initial commit
This commit is contained in:
75
application/source/examples/example.console.log.c
Normal file
75
application/source/examples/example.console.log.c
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
#include "../console.h"
|
||||
|
||||
#include "../street.h"
|
||||
|
||||
#include "../user.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
struct user * newUser = new user();
|
||||
|
||||
newUser->id = 1;
|
||||
|
||||
newUser->username = "peter";
|
||||
|
||||
newUser->userlevel = 2134;
|
||||
|
||||
newUser->hash = "#234234325";
|
||||
|
||||
|
||||
|
||||
struct array * addresses = newUser->addresses;
|
||||
|
||||
|
||||
address * someAddress = new address();
|
||||
|
||||
someAddress->street = "HiLane";
|
||||
|
||||
someAddress->number = 1234;
|
||||
|
||||
addresses->add( someAddress );
|
||||
|
||||
|
||||
|
||||
|
||||
address * otherAddress = new address();
|
||||
|
||||
otherAddress->street = "OtherLane";
|
||||
|
||||
otherAddress->number = 4567;
|
||||
|
||||
addresses->add( otherAddress );
|
||||
|
||||
// todo newUser->addresses->add( otherAddress );
|
||||
|
||||
|
||||
printf("adresses count: %i\n\n", addresses->length() );
|
||||
|
||||
|
||||
char * something = "this is from an char * ";
|
||||
|
||||
int somethingElse = 123;
|
||||
|
||||
|
||||
console.log( "Goedendag",
|
||||
123456,
|
||||
"en een andere text.",
|
||||
something,
|
||||
somethingElse,
|
||||
"something en something",
|
||||
"in native c",
|
||||
23456,
|
||||
newUser,
|
||||
"and some text again" );
|
||||
|
||||
}
|
||||
|
||||
void abort() {
|
||||
|
||||
|
||||
}
|
||||
57
application/source/examples/example.file.system.c
Normal file
57
application/source/examples/example.file.system.c
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
|
||||
#include "../fileSystem.h"
|
||||
|
||||
#include "../console.h"
|
||||
|
||||
void main() {
|
||||
|
||||
char * directory2 = "./assets/";
|
||||
|
||||
fileSystem * filesystem = new fileSystem();
|
||||
|
||||
char * directory = "./assets/";
|
||||
|
||||
|
||||
|
||||
filesystem->writeFile( "./assets/testFile", "content of file" );
|
||||
|
||||
|
||||
array * files = filesystem->readDir( directory );
|
||||
|
||||
int fileCount = files->length();
|
||||
|
||||
for ( int i = 0; i < fileCount; ++i )
|
||||
{
|
||||
|
||||
char * filename = files->get( i );
|
||||
|
||||
char * path = directory->concatenate( filename );
|
||||
|
||||
char * source = filesystem->readFile( path );
|
||||
|
||||
|
||||
printf("filename: %s\n", path);
|
||||
|
||||
printf("source: %s\n\n\n", source);
|
||||
|
||||
}
|
||||
|
||||
if( filesystem->ensureDirectory("./Some/example/assure") ) {
|
||||
|
||||
console.log("Directories successfuly created.");
|
||||
|
||||
}
|
||||
|
||||
if( filesystem->exists( "Some" ) ) {
|
||||
|
||||
console.log("Directories 'Some' does exist.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void abort() {
|
||||
|
||||
|
||||
}
|
||||
38
application/source/examples/example.multiple.inheritance.c
Normal file
38
application/source/examples/example.multiple.inheritance.c
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "extends.h"
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
|
||||
struct inherit * pointer = new inherit();
|
||||
|
||||
//pointer->propertyFromC = 20;
|
||||
|
||||
|
||||
printf("pointer->propertyFromC: %i\n\n", pointer->propertyFromC );
|
||||
|
||||
pointer->methodFromC();
|
||||
|
||||
printf("\n\n\n\n");
|
||||
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
|
||||
struct inherit instance = new inherit();
|
||||
|
||||
instance.propertyFromA = i;
|
||||
|
||||
instance.propertyFromB = i;
|
||||
|
||||
instance.propertyFromC = i;
|
||||
|
||||
instance.methodFromC();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
12
application/source/examples/example.opengl.c
Normal file
12
application/source/examples/example.opengl.c
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
#include "../engine/opengl.h"
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
opengl * instance = new opengl();
|
||||
|
||||
instance->initialize();
|
||||
|
||||
}
|
||||
166
application/source/examples/example.operator.overload.c
Normal file
166
application/source/examples/example.operator.overload.c
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "../text.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../vector3.h"
|
||||
|
||||
#include "../console.h"
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
text * textB = new text("ook mooi");
|
||||
|
||||
char * other = malloc(5000);
|
||||
|
||||
vector3 * newVector3 = new vector3();
|
||||
|
||||
newVector3->x = 2;
|
||||
|
||||
newVector3->y = 2;
|
||||
|
||||
newVector3->z = 3;
|
||||
|
||||
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
|
||||
vector3 * vector3B = new vector3();
|
||||
|
||||
|
||||
vector3B->x = 2;
|
||||
|
||||
vector3B->y = 3;
|
||||
|
||||
vector3B->z = 4;
|
||||
|
||||
|
||||
vector3 * vector3C = new vector3();
|
||||
|
||||
|
||||
vector3C->x = 2;
|
||||
|
||||
vector3C->y = 3;
|
||||
|
||||
vector3C->z = 4;
|
||||
|
||||
newVector3 = vector3C + ( vector3C + newVector3 + ( ( ( ( vector3B + vector3C ) ) + vector3C ) + vector3B ) );
|
||||
|
||||
newVector3 = newVector3 + ( ( vector3B + vector3C ) + vector3C );
|
||||
|
||||
}
|
||||
|
||||
console->log( newVector3 );
|
||||
|
||||
text * textA = new text("mooi");
|
||||
|
||||
if( textA == textB ) {
|
||||
|
||||
printf("mooi zo");
|
||||
|
||||
}
|
||||
|
||||
text * textC = new text("mooi");
|
||||
|
||||
text * textD = new text("mooi");
|
||||
|
||||
|
||||
if( ( ( textA == textC ) && ( textA == textD ) ) && textA == textD ) {
|
||||
|
||||
printf("Good, This works.\n\n");
|
||||
|
||||
}
|
||||
|
||||
char * realChar = "something";
|
||||
|
||||
if( "something" == realChar ) {
|
||||
|
||||
printf("Wauw.\n\n");
|
||||
|
||||
}
|
||||
|
||||
if( realChar == "something" ) {
|
||||
|
||||
printf("Wauw.\n\n");
|
||||
|
||||
}
|
||||
|
||||
if( realChar == realChar ) {
|
||||
|
||||
printf("Wauw.\n\n");
|
||||
|
||||
}
|
||||
|
||||
if( "something" == "something" && realChar == "something" ) {
|
||||
|
||||
printf("Wauw.\n\n");
|
||||
|
||||
}
|
||||
|
||||
char * fancy = "aaa ";
|
||||
|
||||
char * aaaa = " bbb ";
|
||||
|
||||
char * bbbb = " ccc ";
|
||||
|
||||
char * dddd = " dddd ";
|
||||
|
||||
other += ( fancy + ( bbbb + aaaa ) + dddd ) + " eee" + " het is een wonder ";
|
||||
|
||||
other += ("boven wonder" + returnText("this is a normal function") + " and this " + ( "works just good..." + dddd ));
|
||||
|
||||
other += "something" + ( returnText("this is a normal function") + textB->toNative() + textB->value );
|
||||
|
||||
other += ("and here some text") + (textB->toNative()) ;
|
||||
|
||||
other += ( textB->value + ( ( textB->value ) + returnText("this is a normal function") ) + (textB->toNative() + "here some text" + textB->value ) );
|
||||
|
||||
other += textB->value + textB->value + ( textB->value + textB->value ) + ( textB->value + textB->value ) + textB->value + textB->value;
|
||||
|
||||
console.log( "Mooi zo ", other );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
vector2 testVector = new vector2( 1, 450 );
|
||||
|
||||
|
||||
//int count = 0;
|
||||
|
||||
for (int i = 0; i < 2000000; ++i)
|
||||
{
|
||||
vector2 testVector1 = new vector2( 2, 450 );
|
||||
|
||||
vector2 * testVector2 = new vector2( 10, 450 );
|
||||
|
||||
testVector += testVector1 + testVector2;
|
||||
|
||||
//count++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
char * returnText( char * text ) {
|
||||
|
||||
return text;
|
||||
|
||||
}
|
||||
|
||||
void abort() {
|
||||
|
||||
|
||||
}
|
||||
154
application/source/examples/example.sqlite3.c
Normal file
154
application/source/examples/example.sqlite3.c
Normal file
@@ -0,0 +1,154 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "../sqlite.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../console.h"
|
||||
|
||||
#include "../street.h"
|
||||
|
||||
#include "../user.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
void main() {
|
||||
|
||||
// sqlite * sql = new sqlite("./database/users.sqlite");
|
||||
|
||||
sqlite * sql = new sqlite(":memory:");
|
||||
|
||||
sql->selectModel( "user" );
|
||||
|
||||
|
||||
sql->createTable();
|
||||
|
||||
char * names[20] = { "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain", "piet", "gurbe", "siebe", "gerben", "twain" };
|
||||
|
||||
clock_t tic = clock();
|
||||
|
||||
|
||||
array * usersInsertArray = new array();
|
||||
|
||||
for (int i = 0; i <10; ++i) //20000
|
||||
{
|
||||
|
||||
char * name = names[i];
|
||||
|
||||
struct user * userInstance = new user();
|
||||
|
||||
userInstance->id = i;
|
||||
|
||||
userInstance->username = name;
|
||||
|
||||
userInstance->userlevel = 3;
|
||||
|
||||
userInstance->hash = "12345";
|
||||
|
||||
usersInsertArray.add( userInstance );
|
||||
|
||||
//sql->addRow( userInstance );
|
||||
|
||||
}
|
||||
|
||||
|
||||
sql->addRows( usersInsertArray );
|
||||
|
||||
|
||||
|
||||
clock_t toc = clock();
|
||||
|
||||
printf("Multiply: %f seconds, rows: %i\n", (double)( toc - tic ) / CLOCKS_PER_SEC, 10000);
|
||||
|
||||
|
||||
|
||||
array * usersA = sql->fetchRows( "SELECT * FROM user" );
|
||||
|
||||
//user * firstUser = new user();
|
||||
|
||||
user * firstUser = usersA->get( 1 );
|
||||
|
||||
//firstUser->id =10;
|
||||
|
||||
firstUser->username = "updated";
|
||||
|
||||
firstUser->userlevel = 1111;
|
||||
|
||||
firstUser->hash = "new hash";
|
||||
|
||||
console->log( "??", firstUser, "Yeey console.log workswith , , " );
|
||||
|
||||
|
||||
sql->update( firstUser );
|
||||
|
||||
printf("before log\n\n");
|
||||
|
||||
|
||||
|
||||
|
||||
array * users = sql->fetchRows( "SELECT * FROM user " );
|
||||
|
||||
int userCount = users->total;
|
||||
|
||||
|
||||
printf("added rows: %i\n", userCount);
|
||||
|
||||
console->createHorisontalLine();
|
||||
|
||||
printf("\e[1m");
|
||||
|
||||
printf(" ");
|
||||
|
||||
printf("%-20s", "id" );
|
||||
|
||||
printf("%-30s", "username" );
|
||||
|
||||
printf("%-20s", "userLevel" );
|
||||
|
||||
printf("%-30s", "Hash");
|
||||
|
||||
printf("\e[m");
|
||||
|
||||
printf("\n");
|
||||
|
||||
console->createHorisontalLine();
|
||||
|
||||
printf("users: %i\n", userCount);
|
||||
|
||||
for (int i = 0; i < userCount; ++i)
|
||||
{
|
||||
|
||||
struct user * userInstance = users->get( i );
|
||||
|
||||
userInstance->id;
|
||||
|
||||
userInstance->username;
|
||||
|
||||
printf(" ");
|
||||
|
||||
printf("%-20i", userInstance->id);
|
||||
|
||||
printf("%-30s", userInstance->username);
|
||||
|
||||
printf("%-20i", userInstance->userlevel);
|
||||
|
||||
printf("%-30s", userInstance->hash);
|
||||
|
||||
printf( "\n" );//%-30s
|
||||
|
||||
}
|
||||
|
||||
sql->free();
|
||||
|
||||
console->createHorisontalLine();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void abort() {
|
||||
|
||||
|
||||
}
|
||||
78
application/source/examples/example.text.c
Executable file
78
application/source/examples/example.text.c
Executable file
@@ -0,0 +1,78 @@
|
||||
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../text.h"
|
||||
|
||||
#include "time.h"
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
clock_t tic = clock();
|
||||
|
||||
text * sometext = new text(" my first text");
|
||||
|
||||
struct text a = new text(" Mooi ");
|
||||
|
||||
for ( int i = 0; i < 100; ++i ) {
|
||||
|
||||
sometext->appendObject( a )->append("something")->appendObject( new text(" and this") );
|
||||
|
||||
}
|
||||
|
||||
printf("append: %s \n\n", sometext->buffer);
|
||||
|
||||
clock_t toc = clock();
|
||||
|
||||
printf("Multiply: %f seconds\n", (double)( toc - tic ) / CLOCKS_PER_SEC);
|
||||
|
||||
|
||||
char * testText = "a,";
|
||||
|
||||
array * splitParts = testText->concatenate( "b, " )->concatenate("c,d,e")->concatenate(",f ")->split(",g");
|
||||
|
||||
char * compareString = "something";
|
||||
|
||||
splitParts.unshift((char *) "first");
|
||||
|
||||
splitParts.unshift((char *) "this first");
|
||||
|
||||
|
||||
printf( "joined: %s\n\n", splitParts.join(", ") );
|
||||
|
||||
char * lastElement = splitParts->pop();
|
||||
|
||||
printf( "pop joined: %s\n\n", splitParts.join(", ") );
|
||||
|
||||
printf( "pop removed element: %s\n\n", lastElement );
|
||||
|
||||
|
||||
if( compareString.compare("something") ) {
|
||||
|
||||
printf("this is true\n");
|
||||
|
||||
} else {
|
||||
|
||||
printf("this is not true\n");
|
||||
|
||||
}
|
||||
|
||||
printf("first: %s \n\n", splitParts.get( 0 ) );
|
||||
|
||||
int splitCount = splitParts->length();
|
||||
|
||||
printf("splitCount: %i\n", splitCount);
|
||||
|
||||
for (int i = 0; i < splitCount; ++i)
|
||||
{
|
||||
|
||||
char * splitPart = splitParts.get( i );
|
||||
|
||||
//printf("splitPart: %s \n\n", splitPart->trim() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
138
application/source/examples/example.vector.c
Normal file
138
application/source/examples/example.vector.c
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
|
||||
|
||||
#include "vector2.h"
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "array.h"
|
||||
|
||||
#include "triangle.h"
|
||||
|
||||
void main() {
|
||||
|
||||
array * arrayA = new array();
|
||||
|
||||
clock_t tic = clock();
|
||||
|
||||
vector2 * testVector = new vector2( 1, 450 );
|
||||
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
{
|
||||
vector2 * testVector1 = new vector2( i, i * 450 );
|
||||
|
||||
vector2 * testVector2 = new vector2( 10, 450 );
|
||||
|
||||
testVector += testVector1 + testVector2;
|
||||
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
printf("count: %i\n", count);
|
||||
|
||||
|
||||
for ( int i = 0; i < 1; ++i )
|
||||
{
|
||||
|
||||
vector2 testVector = new vector2( 10, 450 );
|
||||
|
||||
|
||||
arrayA->add( &testVector );
|
||||
|
||||
arrayA->add( &testVector );
|
||||
|
||||
|
||||
//printf("number of items in array: %i \n ", arrayA->length() );
|
||||
|
||||
vector2 * returned = arrayA->get( i );
|
||||
|
||||
//printf("returned vector x: %i \n ", returned->x );
|
||||
|
||||
//printf("returned vector y: %i \n ", returned->y );
|
||||
|
||||
vector2 testVector3 = new vector2( 2, 3 );
|
||||
|
||||
arrayA->set( i, &testVector3 );
|
||||
|
||||
vector2 * secondReturn = arrayA->get( 0 );
|
||||
|
||||
//printf("returned vector x: %i \n ", secondReturn->x );
|
||||
|
||||
//printf("returned vector y: %i \n ", secondReturn->y );
|
||||
|
||||
returned->add( secondReturn );
|
||||
|
||||
printf( "returned vector x: %i \n ", returned->x );
|
||||
|
||||
printf("returned vector y: %i \n ", returned->y );
|
||||
|
||||
}
|
||||
|
||||
|
||||
for ( int i = 0; i < 1; ++i )
|
||||
{
|
||||
|
||||
vector2 a = new vector2( 10, 10 );
|
||||
|
||||
vector2 b = new vector2( 10, 10 );
|
||||
|
||||
a->add( &b );
|
||||
|
||||
printf( "a->x: %i, a->y: %i\n", a.x, a.y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
triangle * a = new triangle();
|
||||
|
||||
triangle * b = new triangle();
|
||||
|
||||
|
||||
a->add( b );
|
||||
}
|
||||
|
||||
|
||||
vector2 * t = new vector2( 2,2 );
|
||||
|
||||
int totalLength = 0;
|
||||
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
|
||||
t->x = 100;
|
||||
|
||||
vector2 b = new vector2( 123, 2 );
|
||||
|
||||
b.x = 50;
|
||||
|
||||
vector2 c = new vector2( 1, 12 );
|
||||
|
||||
|
||||
c.x = i;
|
||||
|
||||
t->add( &b );
|
||||
|
||||
b.add( &c );
|
||||
|
||||
c.add( &b );
|
||||
|
||||
printf("a, %i\n", t->x);
|
||||
|
||||
printf("b, %i\n", b.x);
|
||||
|
||||
printf("c, %i\n", c.x);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
application/source/examples/example.vulkan.c
Normal file
18
application/source/examples/example.vulkan.c
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
#include "vulkan.h"
|
||||
volatile sig_atomic_t stop;
|
||||
|
||||
void inthand(int signum) {
|
||||
stop = 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
vulkan * instance = new vulkan();
|
||||
|
||||
instance->setup();
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
70
application/source/examples/example.web.server.c
Normal file
70
application/source/examples/example.web.server.c
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
#include "../http.h"
|
||||
|
||||
#include "./fileSystem.h"
|
||||
|
||||
#include "./text.h"
|
||||
|
||||
#include "./mimeTypes.h"
|
||||
|
||||
#include "./cache.h"
|
||||
|
||||
|
||||
struct cache * cacheManager;
|
||||
|
||||
|
||||
|
||||
void handleRequest( struct request * requestInstance, struct text * response ) {
|
||||
|
||||
text * filePath = new text("www/");
|
||||
|
||||
filePath += requestInstance->url;
|
||||
|
||||
|
||||
if( filesystem->isDirectory( filePath->value ) ) {
|
||||
|
||||
filePath->value += "index.html";
|
||||
|
||||
requestInstance->mimeType = "text/html";
|
||||
|
||||
}
|
||||
|
||||
text * content = cacheManager->getFile( filePath->value );
|
||||
|
||||
//text * content = filesystem->readFile( filePath->value, "binary" );
|
||||
|
||||
response += "HTTP/1.0 200 OK\r\n";
|
||||
|
||||
response += "Server: webserver-c\r\n";
|
||||
|
||||
response += "Content-type: " + requestInstance->mimeType + "\r\n\r\n";
|
||||
|
||||
printf("Filename: %s\n", filePath->value);
|
||||
|
||||
printf("Source: %s\n", content->value);
|
||||
|
||||
response->appendObject( content );
|
||||
|
||||
response += "\r\n";
|
||||
|
||||
|
||||
|
||||
filePath->free();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
|
||||
cacheManager = new cache();
|
||||
|
||||
|
||||
|
||||
http * serverInstance = new http();
|
||||
|
||||
serverInstance->createServer( handleRequest );
|
||||
|
||||
serverInstance->listen( 8080 );
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user