https://github.com/ltabis/hook-machine
A program that register hooks on plugins.
https://github.com/ltabis/hook-machine
Last synced: about 1 month ago
JSON representation
A program that register hooks on plugins.
- Host: GitHub
- URL: https://github.com/ltabis/hook-machine
- Owner: ltabis
- License: mit
- Created: 2020-09-07T13:43:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-17T12:11:29.000Z (almost 3 years ago)
- Last Synced: 2025-04-01T21:53:37.778Z (about 2 months ago)
- Language: C
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hook-machine
A program (not yet a library) that register plugins, which can be used using hooks.
## How to use
start by building the machine using
```c
hm_t *hook_machine = init_hook_machine();
```### Add a plugin
I didn't made a library from this code yet, so to test it you can set your code directly in the ``src/main.c`` file.
Register your plugin using:
```c
// will create a plugin named "my-plugin".
register_plugin(hook_machine, "my-plugin");
```### Add a hook
To add a hook to a plugin, use the following syntax
```c
// this is the callback we will use.
void my_hook(void)
{
printf("I'm doing stuff!\n");
}// here, we register a hook called "my-hook" and attaching it to the
// plugin "my-plugin". when the hook is called, the machine will
// use the my_hook function.
add_hook_to_plugin(hook_machine, "my-plugin", "my-hook", &my_hook);
```### Trigger a hook
To trigger a hook, use the following syntax:
```c
// following the last example, this hook won't call anything.
emit(hook_machine, "event");// following the last example, this hook will call my_hook(),
// registered in the plugin "-plugin".
emit(hook_machine, "my-hook");
```### Handle memory
To clean your memory, you need to destroy your machine when you don't
need it anymore.You just have to use:
```c
destroy_hook_machine(hook_machine);
```This function will free all resources.
### Debug
To debug your machine, use:
```c
debug_hook_machine(hm);
```You will get an output showing all plugins and their content.
```
3 plugins found.- my plugin
1 hook(s) registered.
{ key: 'my hook', ptr: '0x55eaed8227b0' }
- my plugin 2
- my plugin 3
```## Contribute
Any PR is welcome ! If you find a problem, don't hesitate to open an issue.
### Compile & launch
```sh
$ make && ./hook-machine
```### Makefile rules
```sh
$ make # recompile changed files and link them.
$ make clean # clean the repository from object file.
$ make fclean # same as above and delete the binary.
$ make re # cleans everything and recompile the program.
```## Dependencies
- gcc
- makefile