Rust rewrite
This commit is contained in:
19
dim_plugins/example_c/Makefile
Normal file
19
dim_plugins/example_c/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
PLUGIN_NAME=example_c
|
||||
|
||||
|
||||
CC_FLAGS = $(DIM_CC_FLAGS)
|
||||
|
||||
SOURCES=$(wildcard src/*.c)
|
||||
OBJECTS=$(patsubst src/%.c,$(OBJECT_DIR)/$(PLUGIN_NAME)/%.o,$(SOURCES))
|
||||
|
||||
$(info $(SOURCES))
|
||||
|
||||
build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim
|
||||
|
||||
$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECTS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(DIM_CC) -o $@ $^ $(CC_FLAGS)
|
||||
|
||||
$(OBJECT_DIR)/$(PLUGIN_NAME)/%.o: src/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
$(DIM_CC) -c -o $@ $< -fPIC -pie
|
||||
39
dim_plugins/example_c/src/main.c
Normal file
39
dim_plugins/example_c/src/main.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../../../include/plug.h"
|
||||
|
||||
PLUG_INFO("Example plugin", "0.0.0", "GPLv3")
|
||||
|
||||
typedef struct plug_t {
|
||||
char* some_data;
|
||||
int count;
|
||||
} plug_t;
|
||||
|
||||
plug_t* p = {0};
|
||||
|
||||
void plug_init() {
|
||||
p = malloc(sizeof(plug_t));
|
||||
assert(p != NULL && "Buy more ram KEKW");
|
||||
p->some_data = "hi :3";
|
||||
p->count = 0;
|
||||
|
||||
printf("Hello from plugin");
|
||||
}
|
||||
|
||||
void* plug_pre_reload() {
|
||||
return p;
|
||||
}
|
||||
|
||||
void plug_post_reload(void *state) {
|
||||
p = state;
|
||||
}
|
||||
|
||||
void plug_poll(char *buf, size_t len) {
|
||||
snprintf(buf, len, "%s (%d)", p->some_data, p->count++);
|
||||
}
|
||||
|
||||
void plug_free() {
|
||||
free(p);
|
||||
}
|
||||
Reference in New Issue
Block a user