From fa25cdad81969111ccace7774db915ae26abcd1b Mon Sep 17 00:00:00 2001
From: GoldenTails <milestailsprower101n2@gmail.com>
Date: Sun, 7 Nov 2021 01:27:59 -0500
Subject: [PATCH] Fix `constants' searching SOC's vars, deny A_* and super
 being in `constants'.

---
 src/deh_lua.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/deh_lua.c b/src/deh_lua.c
index 4666a8946f..5f6e8055b7 100644
--- a/src/deh_lua.c
+++ b/src/deh_lua.c
@@ -555,11 +555,15 @@ static int constants_get(lua_State *L)
 
 	key = luaL_checkstring(L, 2);
 
-	// In Lua, mathlib is always there
-	ret = getEnum(L, true, key);
+	// In Lua, mathlib is never there
+	ret = getEnum(L, false, key);
 
 	if (ret != -1)
-		return ret;
+		// Don't allow A_* or super.
+		// All userdata is meant to be considered global variables,
+		// so no need to get more specific than "is it userdata?"
+		if (!lua_isuserdata(L, -1) && !lua_isfunction(L, -1))
+			return ret;
 
 	return 0;
 }
-- 
GitLab