From cfcd7ce0d3959bcce0e8e00cc504b1354451cb50 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Tue, 8 Mar 2016 22:15:26 -0800 Subject: [PATCH] Readded EvalMath to Lua. There is a caveat to this: The first time EvalMath is used, a deprecated function warning will be shown to the user that tells them to use _G[] instead. This reverts commit 9d36cf37bd6fc1e5e0e9770031925db3a92a9929. --- src/lua_baselib.c | 9 +++++++++ src/lua_script.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index c415eecb8..2cc79db47 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -85,6 +85,14 @@ static int lib_print(lua_State *L) return 0; } +static int lib_evalMath(lua_State *L) +{ + const char *word = luaL_checkstring(L, 1); + LUA_Deprecated(L, "EvalMath(string)", "_G[string]"); + lua_pushinteger(L, LUA_EvalMath(word)); + return 1; +} + // M_RANDOM ////////////// @@ -1899,6 +1907,7 @@ static int lib_gTicsToMilliseconds(lua_State *L) static luaL_Reg lib[] = { {"print", lib_print}, + {"EvalMath", lib_evalMath}, // m_random {"P_Random",lib_pRandom}, diff --git a/src/lua_script.h b/src/lua_script.h index ec67703c3..96f832e2c 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -70,4 +70,15 @@ void COM_Lua_f(void); #define LUA_ErrInvalid(L, type) luaL_error(L, "accessed " type " doesn't exist anymore, please check 'valid' before using " type "."); +// Deprecation warnings +// Shows once upon use. Then doesn't show again. +#define LUA_Deprecated(L,this_func,use_instead)\ +{\ + static UINT8 seen = 0;\ + if (!seen) {\ + seen = 1;\ + CONS_Alert(CONS_WARNING,"\"%s\" is deprecated and will be removed.\nUse \"%s\" instead.\n", this_func, use_instead);\ + }\ +} + #endif