Initial commit
This commit is contained in:
27
.editorconfig
Normal file
27
.editorconfig
Normal file
@@ -0,0 +1,27 @@
|
||||
[*]
|
||||
end_of_line = LF
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{ts,js,tsx,jsx,lua,sh}]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{go,bb}]
|
||||
indent_style = tab
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
[*.{yml,json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[meson.{build,options}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# CMake/Meson
|
||||
build*
|
||||
cmake-build-*
|
||||
|
||||
# IntelliJ
|
||||
.idea
|
||||
|
||||
# LSPs
|
||||
.ccls
|
||||
.ccls-cache
|
||||
.cache
|
||||
compile_commands.json
|
||||
|
||||
# JetBrains Fleet
|
||||
.fleet
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
# ImGui
|
||||
imgui.ini
|
||||
8
hax.cpp
Normal file
8
hax.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
extern "C" {
|
||||
#include "mod.h"
|
||||
}
|
||||
|
||||
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* arv[]) -> int {
|
||||
run_mods();
|
||||
return 0;
|
||||
}
|
||||
27
meson.build
Normal file
27
meson.build
Normal file
@@ -0,0 +1,27 @@
|
||||
project(
|
||||
'cchax',
|
||||
['c', 'cpp'],
|
||||
version : '0.1',
|
||||
default_options : [
|
||||
'warning_level=3',
|
||||
'c_std=c2x',
|
||||
'cpp_std=c++23'
|
||||
])
|
||||
|
||||
modules = static_library(
|
||||
'mods',
|
||||
[
|
||||
'mod.c',
|
||||
'mods/mod_a.c',
|
||||
'mods/mod_b.c',
|
||||
],
|
||||
)
|
||||
|
||||
executable(
|
||||
'hax',
|
||||
[
|
||||
'hax.cpp',
|
||||
],
|
||||
link_whole: modules,
|
||||
install : false
|
||||
)
|
||||
22
mod.c
Normal file
22
mod.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "mod.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern struct mod_t __start___mod_list[]; // note: [] not single object
|
||||
extern struct mod_t __stop___mod_list[];
|
||||
|
||||
static inline size_t mod_count(void) {
|
||||
return (size_t)(__stop___mod_list - __start___mod_list);
|
||||
}
|
||||
|
||||
// mod_register(mod_begin, mod_begin);
|
||||
|
||||
void run_mods(void) {
|
||||
printf("Running mods! %lu\n", mod_count());
|
||||
// mod_t* first = &mod_mod_begin;
|
||||
//
|
||||
// mod_t* it = first + 1;
|
||||
//
|
||||
// it->fn();
|
||||
|
||||
// for (mod_t* it = first + 1; ieiieieieieie
|
||||
}
|
||||
23
mod.h
Normal file
23
mod.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef CCHAX_MOD_H
|
||||
#define CCHAX_MOD_H
|
||||
|
||||
typedef int (*fn_t)(void);
|
||||
|
||||
typedef struct mod_t {
|
||||
char const* name;
|
||||
fn_t fn;
|
||||
} mod_t;
|
||||
|
||||
#define mod_register(name_ref, fn_ref) \
|
||||
static struct mod_t mod_##name_ref __attribute__(( \
|
||||
used, \
|
||||
section("__mod_list"), \
|
||||
aligned(__alignof__(struct mod_t)) \
|
||||
)) = { \
|
||||
.name = #name_ref, \
|
||||
.fn = fn_ref \
|
||||
}
|
||||
|
||||
void run_mods(void);
|
||||
|
||||
#endif // !CCHAX_MOD_H
|
||||
11
mods/mod_a.c
Normal file
11
mods/mod_a.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "mod.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static int hello() {
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mod_register(mod_a, hello);
|
||||
|
||||
12
mods/mod_b.c
Normal file
12
mods/mod_b.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "mod.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static int hello() {
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mod_register(mod_b, hello);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user