Table of contents:
Install and Build guide
Install APIMacros
Before building TEL, you need to download or get APIMacros.
Download and install:
git clone https://github.com/IHateGameDev/APIMacros.git
cd APIMacros
mkdir build
cd build
cmake ..
sudo make install
# OR:
# cmake .. -G Ninja
# ninja install
Get only the needed dependencies:
Download TEL and write this in terminal:
mkdir APIMacros
cd APIMacros
# Downloading
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/api.h
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/shared.h
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/nullptr.h
cd ..
You have successfully obtained APIMacros!
Download TEL
To download TEL, run the following commands in the terminal:
git clone https://github.com/IHateGameDev/TEL.git
cd TEL
Build and Install TEL
Before building, you need install APIMacros and download TEL.
To build TEL, run the following commands in the terminal:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=OFF .. # -G Ninja
make # or ninja
make install # or ninja install
You can configure the build options; see CMake options.
These steps will install TEL on your PC.
CMake options
Option | Description | Default value |
BUILD_STATIC | Add static library to targets | ON |
BUILD_SHARED | Add shared library to targets | OFF |
BUILD_EXAMPLES | Enable building examples | OFF |
EXAMPLES_USE | Type of library use on compile examples | "Static" |
Summary
Example commands in the terminal:
git clone https://github.com/IHateGameDev/TEL.git
cd TEL
mkdir APIMacros
cd APIMacros
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/api.h
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/shared.h
wget https://raw.githubusercontent.com/IHateGameDev/APIMacros/main/APIMacros/nullptr.h
cd ..
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON .. -G Ninja
ninja
ninja install
TEL Implementing in project
If you want to implementing TEL in your project:
Extension info
You need to create a structure for your extension info:
#ifndef EXAMPLE_EXTENSION_INFO_H
#define EXAMPLE_EXTENSION_INFO_H
typedef void(ExampleUpdateFn*)(ExampleExtensionInfo*)
typedef struct {
const char* name;
ExampleUpdateFn update;
} ExampleExtensionInfo;
#endif
This structure is used to communicate between the application and the extension, and all extensions have their own info.
Add useful functions for extension developers if needed:
#ifndef EXAMPLE_SOME_HEADER_H
#define EXAMPLE_SOME_HEADER_H
extern char* ExampleNewString(const char* restrict src);
#endif
#include "SomeHeader.h"
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
char* ExampleNewString(const char* restrict src) {
char* out = malloc(strlen(src) + 1);
strcpy(out, src);
return out;
}
And construct you application source file:
#include "ExtensionInfo.h"
#include <stdio.h>
int main() {
puts("Hello from my application!\n");
ExampleExtensionInfo* info = (ExampleExtensionInfo*)extension->info;
puts("Extension: ");
puts(info->name);
puts(", successuflly loaded!\n");
for (unsigned char i = 0; i < 255; i++)
info->update();
}
Add extension structure and functions.
API TelError telExtensionLoad(TelExtension *self, const char *restrict path, const char *restrict setupFunctionName)
Function that loads the extension.
API TelError telExtensionUnload(TelExtension *self, const char *restrict cleanupFunctionName)
Function that unload the extension.
#define TEL_NEW_EXTENSION(extension, struct)
Macro that create TelExtension.
Definition Extension.h:59
This code loads the extension extension.te, prints its name,
calls the update function 255 times, and calls the cleanup function to free info->name.
NOTE: If you use the shared TEL library, don't forget to add compile flag: -DAPI_SHARED_USE.
Standard Specification
We use example this application.
Create the extension's main file:
#include "ExampleExtensionInfo.h"
#include "SomeHeader.h"
#include "APIMacros/api.h"
#include <stdio.h>
#include <stdlib.h>
void someUpdate(ExampleExtensionInfo* info) {
puts("Update: ");
puts(info->name);
puts("!\n")
}
API void setup(ExampleExtensionInfo* info) {
info->name = ExampleNewString("ExampleExtension (;o;)");
info->update = someUpdate;
}
API void cleanup(ExampleExtensionInfo* info) {
free(info->name);
}
NOTE Don't forget to add -fPIC and, if you use "APIMacros/api.h", also add -DAPI_SHARED_BUILD.