Fix everything
This commit is contained in:
parent
56da082f55
commit
9a5e0b0f87
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
gen
|
||||
build
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,3 +1,3 @@
|
||||
[submodule "wit/repo"]
|
||||
path = wit/repo
|
||||
url = https://github.com/Pumpkin-MC/Pumpkin.git
|
||||
[submodule "wit"]
|
||||
path = wit
|
||||
url = https://github.com/Pumpkin-MC/pumpkin-plugin-wit
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(pumpkin-api-c C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# Add the generated bindings
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/gen)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
add_library(pumpkin-api STATIC
|
||||
src/gen/plugin.c
|
||||
src/pumpkin_api.c
|
||||
)
|
||||
40
Makefile
Normal file
40
Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
WIT_BINDGEN ?= wit-bindgen
|
||||
CC_WASI ?= wasm32-wasip2-clang
|
||||
AR_LLVM ?= llvm-ar
|
||||
INSTALL_PREFIX ?= install
|
||||
|
||||
CFLAGS ?= -Oz
|
||||
|
||||
WIT_FILES := $(wildcard wit/v0.1/*.wit)
|
||||
HEADERS := pumpkin_api.h gen/plugin.h
|
||||
OBJS := build/pumpkin_api.o build/plugin.o gen/plugin_component_type.o
|
||||
|
||||
.PHONY: all clean install
|
||||
|
||||
all: build/libpumpkin-api.a
|
||||
|
||||
gen: $(WIT_FILES)
|
||||
$(WIT_BINDGEN) c --out-dir gen wit/v0.1
|
||||
|
||||
gen/plugin.c: gen
|
||||
gen/plugin.h: gen
|
||||
gen/plugin_component_type.o: gen
|
||||
|
||||
build/pumpkin_api.o: pumpkin_api.c $(HEADERS) | build
|
||||
$(CC_WASI) $(CFLAGS) -I. -Igen -c $< -o $@
|
||||
build/plugin.o: gen/plugin.c $(HEADERS) | build
|
||||
$(CC_WASI) $(CFLAGS) -I. -Igen -c $< -o $@
|
||||
|
||||
build/libpumpkin-api.a: $(OBJS) | build
|
||||
$(AR_LLVM) rcs $@ $^
|
||||
|
||||
build:
|
||||
mkdir build
|
||||
|
||||
install: build/libpumpkin-api.a $(HEADERS)
|
||||
mkdir -p $(INSTALL_PREFIX)/include $(INSTALL_PREFIX)/lib
|
||||
cp $(HEADERS) $(INSTALL_PREFIX)/include/
|
||||
cp build/libpumpkin-api.a $(INSTALL_PREFIX)/lib/
|
||||
|
||||
clean:
|
||||
rm -rf build gen
|
||||
@ -2,14 +2,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
pumpkin_metadata_t get_meta(void) {
|
||||
static const char* authors[] = {"alex"};
|
||||
static const char* authors[] = {"you"};
|
||||
return (pumpkin_metadata_t) {
|
||||
.name = "my-c-plugin",
|
||||
.version = "0.1.0",
|
||||
.authors = authors,
|
||||
.authors_count = 1,
|
||||
.description = "A simple C plugin for Pumpkin",
|
||||
.dependencies_count = 0
|
||||
.dependencies_count = 0,
|
||||
.permissions_count = 0
|
||||
};
|
||||
}
|
||||
|
||||
@ -17,12 +18,7 @@ void on_load(plugin_own_context_t ctx) {
|
||||
printf("C plugin loaded!\n");
|
||||
}
|
||||
|
||||
void on_unload(plugin_own_context_t ctx) {
|
||||
printf("C plugin unloaded!\n");
|
||||
}
|
||||
|
||||
REGISTER_PUMPKIN_PLUGIN(((pumpkin_plugin_t){
|
||||
.get_metadata = get_meta,
|
||||
.on_load = on_load,
|
||||
.on_unload = on_unload
|
||||
.on_load = on_load
|
||||
}))
|
||||
|
||||
@ -15,7 +15,7 @@ void exports_pumpkin_plugin_metadata_get_metadata(exports_pumpkin_plugin_metadat
|
||||
pumpkin_metadata_t meta = g_plugin.get_metadata();
|
||||
plugin_string_dup(&(ret->name), meta.name);
|
||||
plugin_string_dup(&(ret->version), meta.version);
|
||||
|
||||
|
||||
ret->authors.len = meta.authors_count;
|
||||
ret->authors.ptr = (plugin_string_t*)malloc(ret->authors.len * sizeof(plugin_string_t));
|
||||
for (size_t i = 0; i < ret->authors.len; ++i) {
|
||||
@ -29,21 +29,25 @@ void exports_pumpkin_plugin_metadata_get_metadata(exports_pumpkin_plugin_metadat
|
||||
for (size_t i = 0; i < ret->dependencies.len; ++i) {
|
||||
plugin_string_dup(&(ret->dependencies.ptr[i]), meta.dependencies[i]);
|
||||
}
|
||||
|
||||
ret->permissions.len = meta.permissions_count;
|
||||
ret->permissions.ptr = (plugin_string_t*)malloc(ret->permissions.len * sizeof(plugin_string_t));
|
||||
for (size_t i = 0; i < ret->permissions.len; ++i) {
|
||||
plugin_string_dup(&(ret->permissions.ptr[i]), meta.permissions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool exports_plugin_on_load(plugin_own_context_t context_handle, plugin_string_t *err) {
|
||||
if (g_plugin.on_load) {
|
||||
g_plugin.on_load(context_handle);
|
||||
return true;
|
||||
}
|
||||
return true; // No on_load is not an error
|
||||
return true;
|
||||
}
|
||||
|
||||
bool exports_plugin_on_unload(plugin_own_context_t context_handle, plugin_string_t *err) {
|
||||
if (g_plugin.on_unload) {
|
||||
g_plugin.on_unload(context_handle);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -54,8 +58,14 @@ void exports_plugin_handle_event(uint32_t event_id, plugin_own_server_instance_t
|
||||
}
|
||||
|
||||
bool exports_plugin_handle_command(uint32_t command_id, plugin_own_command_sender_t sender, plugin_own_server_instance_t server, plugin_own_consumed_args_t args, int32_t *ret, plugin_command_error_t *err) {
|
||||
err->is_err = true;
|
||||
plugin_string_dup(&(err->val.err.val.command_failed.val.text), "Command not implemented");
|
||||
err->tag = PUMPKIN_PLUGIN_COMMAND_COMMAND_ERROR_COMMAND_FAILED;
|
||||
|
||||
plugin_string_t str;
|
||||
plugin_string_set(&str, "Command not implemented");
|
||||
|
||||
pumpkin_plugin_text_own_text_component_t text = pumpkin_plugin_text_static_text_component_text(&str);
|
||||
err->val.command_failed = text;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -10,11 +10,17 @@ extern "C" {
|
||||
typedef struct {
|
||||
const char* name;
|
||||
const char* version;
|
||||
|
||||
const char** authors;
|
||||
size_t authors_count;
|
||||
|
||||
const char* description;
|
||||
|
||||
const char** dependencies;
|
||||
size_t dependencies_count;
|
||||
|
||||
const char** permissions;
|
||||
size_t permissions_count;
|
||||
} pumpkin_metadata_t;
|
||||
|
||||
typedef void (*pumpkin_on_load_t)(plugin_own_context_t ctx);
|
||||
4606
src/gen/plugin.c
4606
src/gen/plugin.c
File diff suppressed because it is too large
Load Diff
2369
src/gen/plugin.h
2369
src/gen/plugin.h
File diff suppressed because it is too large
Load Diff
Binary file not shown.
1
wit
Submodule
1
wit
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2aacac1f07848b6273b30a0390818e87ef1259e9
|
||||
1
wit/repo
1
wit/repo
@ -1 +0,0 @@
|
||||
Subproject commit 7cc4854078e8a4008253b2e3bc7dc89db0ef37d3
|
||||
Loading…
Reference in New Issue
Block a user