Skip to content

Commit

Permalink
Improve auto splitter order of execution and console output
Browse files Browse the repository at this point in the history
  • Loading branch information
wins1ey committed Jun 5, 2024
1 parent ba10e05 commit 7be3953
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions src/auto-splitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,25 +269,33 @@ void state(lua_State* L)
call_va(L, "state", "");
}

void update(lua_State* L)
bool update(lua_State* L)
{
call_va(L, "update", "");
bool ret;
if (call_va(L, "update", ">b", &ret)) {
lua_pop(L, 1);
return ret;
}
lua_pop(L, 1);
return true;
}

void start(lua_State* L)
{
bool ret;
if (call_va(L, "start", ">b", &ret)) {
atomic_store(&call_start, ret);
if (call_va(L, "start", ">b", &ret) && ret) {
atomic_store(&call_start, true);
printf("start: true\n");
}
lua_pop(L, 1); // Remove the return value from the stack
}

void split(lua_State* L)
{
bool ret;
if (call_va(L, "split", ">b", &ret)) {
atomic_store(&call_split, ret);
if (call_va(L, "split", ">b", &ret) && ret) {
atomic_store(&call_split, true);
printf("split: true\n");
}
lua_pop(L, 1); // Remove the return value from the stack
}
Expand All @@ -298,20 +306,24 @@ void is_loading(lua_State* L)
if (call_va(L, "isLoading", ">b", &loading)) {
if (loading != prev_is_loading) {
atomic_store(&toggle_loading, true);
printf("isLoading: %s\n", loading ? "true" : "false");
prev_is_loading = !prev_is_loading;
}
}
lua_pop(L, 1); // Remove the return value from the stack
}

void reset(lua_State* L)
bool reset(lua_State* L)
{
bool shouldReset;
if (call_va(L, "reset", ">b", &shouldReset)) {
if (shouldReset)
atomic_store(&call_reset, true);
bool should_reset;
if (call_va(L, "reset", ">b", &should_reset) && should_reset) {
atomic_store(&call_reset, true);
printf("reset: true\n");
lua_pop(L, 1);
return true;
}
lua_pop(L, 1); // Remove the return value from the stack
lua_pop(L, 1);
return false;
}

void run_auto_splitter()
Expand Down Expand Up @@ -398,24 +410,18 @@ void run_auto_splitter()
state(L);
}

if (update_exists) {
update(L);
}

if (start_exists) {
start(L);
}

if (split_exists) {
split(L);
}

if (is_loading_exists) {
is_loading(L);
}

if (reset_exists) {
reset(L);
if (!update_exists || update(L)) {
if (is_loading_exists) {
is_loading(L);
}
if (start_exists) {
start(L);
}
if (!reset_exists || !reset(L)) {
if (split_exists) {
split(L);
}
}
}

// Clear the memory maps cache if needed
Expand Down

0 comments on commit 7be3953

Please sign in to comment.