From 3235351b99a8d134dab228f48f6585a8e4ac787f Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Wed, 11 May 2016 14:33:50 -0700 Subject: [PATCH] And now Lua yells at you for doing what I just fixed --- src/lua_baselib.c | 4 ++++ src/lua_script.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 525f2fe68..20342d33e 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -115,6 +115,8 @@ static int lib_pRandomKey(lua_State *L) INT32 a = (INT32)luaL_checkinteger(L, 1); NOHUD + if (a > 65536) + LUA_UsageWarning(L, "P_RandomKey: range > 65536 is undefined behavior"); lua_pushinteger(L, P_RandomKey(a)); return 1; } @@ -130,6 +132,8 @@ static int lib_pRandomRange(lua_State *L) a = b; b = c; } + if ((b-a+1) > 65536) + LUA_UsageWarning(L, "P_RandomRange: range > 65536 is undefined behavior"); lua_pushinteger(L, P_RandomRange(a, b)); return 1; } diff --git a/src/lua_script.h b/src/lua_script.h index 45fab2f53..447d3d686 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -81,4 +81,15 @@ void COM_Lua_f(void); }\ } +// Warnings about incorrect function usage. +// Shows once, then never again, like deprecation +#define LUA_UsageWarning(L, warningmsg)\ +{\ + static UINT8 seen = 0;\ + if (!seen) {\ + seen = 1;\ + CONS_Alert(CONS_WARNING,"%s\n", warningmsg);\ + }\ +} + #endif