Inital context stuff and tests
Linking and building is successfull and inital tests pass
This commit is contained in:
1 parent
2296f68123
commit
363e9894e8
10 files changed
+410
-59
No files matched your search
@@ -0,0 +1,70 @@
|
||||
#include "../include/regolith.h"
|
||||
#include "../include/regolith_lua.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct counter {
|
||||
size_t live;
|
||||
size_t peak;
|
||||
} counter;
|
||||
|
||||
static void track(counter *c, size_t add, size_t sub) {
|
||||
c->live = c->live + add - sub;
|
||||
if (c->live > c->peak)
|
||||
c->peak = c->live;
|
||||
}
|
||||
|
||||
static void *c_alloc(size_t size, void *user) {
|
||||
void *p = malloc(size);
|
||||
if (p)
|
||||
track(user, size, 0);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void *c_realloc(void *ptr, size_t old_size, size_t new_size,
|
||||
void *user) {
|
||||
void *p = realloc(ptr, new_size);
|
||||
if (p)
|
||||
track(user, new_size, old_size);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void c_free(void *ptr, size_t size, void *user) {
|
||||
track(user, 0, size);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
counter c = {0, 0};
|
||||
rg_config cfg;
|
||||
rg_context *ctx;
|
||||
int rc;
|
||||
|
||||
rg_config_init(&cfg);
|
||||
cfg.allocator.alloc = c_alloc;
|
||||
cfg.allocator.realloc = c_realloc;
|
||||
cfg.allocator.free = c_free;
|
||||
cfg.allocator.user = &c;
|
||||
|
||||
ctx = rg_create(&cfg);
|
||||
if (!ctx)
|
||||
return 1;
|
||||
|
||||
rc = rg_lua_open(ctx);
|
||||
if (rc == RG_OK)
|
||||
rc = rg_lua_dostring(ctx, "print('hello from ' .. _VERSION)", "=smoke");
|
||||
if (rc == RG_OK)
|
||||
rc = rg_lua_dostring(ctx, "this is not lua", "=smoke_bad") == RG_ERR_LUA
|
||||
? RG_OK
|
||||
: RG_ERR_GENERIC;
|
||||
|
||||
printf("regolith %s, peak %zu bytes\n", rg_version(), c.peak);
|
||||
rg_destroy(ctx);
|
||||
|
||||
if (c.live != 0) {
|
||||
printf("leak: %zu bytes still live\n", c.live);
|
||||
return 1;
|
||||
}
|
||||
return rc == RG_OK ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int v = SDL_GetVersion();
|
||||
printf("SDL %d.%d.%d\n", SDL_VERSIONNUM_MAJOR(v), SDL_VERSIONNUM_MINOR(v), SDL_VERSIONNUM_MICRO(v));
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user