From 6886f248f8a845ab7b39d326f836a910f4d1ba11 Mon Sep 17 00:00:00 2001
From: Agent X <44549182+Agent-11@users.noreply.github.com>
Date: Mon, 1 Jan 2024 14:43:44 -0500
Subject: [PATCH] Add gControllers
---
autogen/lua_definitions/manual.lua | 3 +++
docs/lua/globals.md | 7 +++++++
src/pc/lua/smlua_cobject.c | 11 +++++++++++
3 files changed, 21 insertions(+)
diff --git a/autogen/lua_definitions/manual.lua b/autogen/lua_definitions/manual.lua
index 53ad6390..6594c25a 100644
--- a/autogen/lua_definitions/manual.lua
+++ b/autogen/lua_definitions/manual.lua
@@ -23,6 +23,9 @@ gActiveMods = {}
--- @type Character[]
gCharacters = {}
+--- @type Controller[]
+gControllers = {}
+
--- @type GlobalTextures
gTextures = {}
diff --git a/docs/lua/globals.md b/docs/lua/globals.md
index a7e08603..651840f2 100644
--- a/docs/lua/globals.md
+++ b/docs/lua/globals.md
@@ -37,6 +37,13 @@ The `gCharacters[]` table is an array from `0` to `(CT_MAX - 1)` that contains a
+## [gControllers](#gControllers)
+The `gControllers[]` table is an array from `0` to `(MAX_PLAYERS - 1)` that contains a [Controller](structs.md#Controller) struct for each possible player.
+
+[:arrow_up_small:](#)
+
+
+
## [gTextures](#gTextures)
The `gTextures` table contains references to textures. Listed in [GlobalTextures](structs.md#GlobalTextures).
diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c
index 3d66a451..9eaebc0f 100644
--- a/src/pc/lua/smlua_cobject.c
+++ b/src/pc/lua/smlua_cobject.c
@@ -603,6 +603,17 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gCharacters");
}
+ {
+ lua_newtable(L);
+ int t = lua_gettop(gLuaState);
+ for (s32 i = 0; i < MAX_PLAYERS; i++) {
+ lua_pushinteger(L, i);
+ smlua_push_object(L, LOT_CONTROLLER, &gControllers[i]);
+ lua_settable(L, t);
+ }
+ lua_setglobal(L, "gControllers");
+ }
+
#define EXPOSE_GLOBAL(lot, ptr) \
{ \
smlua_push_object(L, lot, &ptr); \