diff --git a/src/api/event.c b/src/api/event.c index 932ac1bf..03ad4204 100644 --- a/src/api/event.c +++ b/src/api/event.c @@ -1,6 +1,8 @@ #include "api.h" #include "api/event.h" #include "event/event.h" +#include +#include const char* EventTypes[] = { [EVENT_QUIT] = "quit", @@ -93,7 +95,7 @@ static int nextEvent(lua_State* L) { return 3; case EVENT_CUSTOM: - for (int i = 0; i < event.data.custom.count; i++) { + for (uint32_t i = 0; i < event.data.custom.count; i++) { Variant* variant = &event.data.custom.data[i]; luax_pushvariant(L, variant); lovrVariantDestroy(variant); @@ -125,7 +127,7 @@ static int l_lovrEventPush(lua_State* L) { const char* name = luaL_checkstring(L, 1); strncpy(eventData.name, name, MAX_EVENT_NAME_LENGTH - 1); eventData.count = MIN(lua_gettop(L) - 1, 4); - for (int i = 0; i < eventData.count; i++) { + for (uint32_t i = 0; i < eventData.count; i++) { luax_checkvariant(L, 2 + i, &eventData.data[i]); } diff --git a/src/event/event.c b/src/event/event.c index 36ab9c82..87c94201 100644 --- a/src/event/event.c +++ b/src/event/event.c @@ -1,9 +1,15 @@ #include "event/event.h" #include "platform.h" +#include "types.h" +#include "lib/vec/vec.h" #include #include -static EventState state; +static struct { + bool initialized; + vec_t(EventPump) pumps; + vec_t(Event) events; +} state; void lovrVariantDestroy(Variant* variant) { switch (variant->type) { @@ -25,7 +31,7 @@ void lovrEventDestroy() { if (!state.initialized) return; vec_deinit(&state.pumps); vec_deinit(&state.events); - memset(&state, 0, sizeof(EventState)); + memset(&state, 0, sizeof(state)); } void lovrEventAddPump(EventPump pump) { diff --git a/src/event/event.h b/src/event/event.h index 7f65cad5..bf943e04 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -1,11 +1,11 @@ -#include "lib/vec/vec.h" -#include "types.h" #include +#include #pragma once #define MAX_EVENT_NAME_LENGTH 32 +struct Ref; struct Thread; typedef enum { @@ -27,7 +27,7 @@ typedef union { bool boolean; double number; char* string; - Ref* ref; + struct Ref* ref; } VariantValue; typedef struct { @@ -52,7 +52,7 @@ typedef struct { typedef struct { char name[MAX_EVENT_NAME_LENGTH]; Variant data[4]; - int count; + uint32_t count; } CustomEvent; typedef union { @@ -69,12 +69,6 @@ typedef struct { typedef void (*EventPump)(void); -typedef struct { - bool initialized; - vec_t(EventPump) pumps; - vec_t(Event) events; -} EventState; - void lovrVariantDestroy(Variant* variant); bool lovrEventInit(void); diff --git a/src/types.h b/src/types.h index 2fa7657e..be6f3ebe 100644 --- a/src/types.h +++ b/src/types.h @@ -56,7 +56,7 @@ typedef struct { extern const TypeInfo lovrTypeInfo[T_MAX]; -typedef struct { +typedef struct Ref { Type type; int count; } Ref;