From 79f6fd728cc5ebd28b0e6a762c2591a4017f8d75 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 4 Jun 2022 22:13:20 -0400 Subject: [PATCH] Fix, Deprecate, Remove, and Replace tpt.element_func / tpt.graphics_func --- src/lua/LegacyLuaAPI.cpp | 75 ------------------------------ src/lua/LuaScriptHelper.h | 4 -- src/lua/LuaScriptInterface.cpp | 2 - src/lua/luascripts/eventcompat.lua | 22 +++++++-- 4 files changed, 19 insertions(+), 84 deletions(-) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index fea17b895..d24ab9345 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -317,81 +317,6 @@ int luatpt_getelement(lua_State *l) return 1; } -int luatpt_element_func(lua_State *l) -{ - if (lua_isfunction(l, 1)) - { - int element = luaL_optint(l, 2, 0); - int replace = luaL_optint(l, 3, 0); - if (luacon_sim->IsElement(element)) - { - lua_el_func[element].Assign(l, 1); - if (replace == 2) - lua_el_mode[element] = 3; //update before - else if (replace) - lua_el_mode[element] = 2; //replace - else - lua_el_mode[element] = 1; //update after - return 0; - } - else - { - return luaL_error(l, "Invalid element"); - } - } - else if (lua_isnil(l, 1)) - { - int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsElement(element)) - { - lua_el_func[element].Clear(); - lua_el_mode[element] = 0; - } - else - { - return luaL_error(l, "Invalid element"); - } - } - else - return luaL_error(l, "Not a function"); - return 0; -} - -int luatpt_graphics_func(lua_State *l) -{ - if(lua_isfunction(l, 1)) - { - int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsElement(element)) - { - lua_gr_func[element].Assign(l, 1); - luacon_ren->graphicscache[element].isready = 0; - return 0; - } - else - { - return luaL_error(l, "Invalid element"); - } - } - else if (lua_isnil(l, 1)) - { - int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsElement(element)) - { - lua_gr_func[element].Clear(); - luacon_ren->graphicscache[element].isready = 0; - return 0; - } - else - { - return luaL_error(l, "Invalid element"); - } - } - else - return luaL_error(l, "Not a function"); - return 0; -} - int luatpt_error(lua_State* l) { String errorMessage = ByteString(luaL_optstring(l, 1, "Error text")).FromUtf8(); diff --git a/src/lua/LuaScriptHelper.h b/src/lua/LuaScriptHelper.h index 4fde4c12b..407b005b9 100644 --- a/src/lua/LuaScriptHelper.h +++ b/src/lua/LuaScriptHelper.h @@ -52,10 +52,6 @@ int luacon_transitionwrite(lua_State* l); //tpt. api int luatpt_getelement(lua_State *l); -int luatpt_graphics_func(lua_State *l); - -int luatpt_element_func(lua_State *l); - int luatpt_error(lua_State* l); int luatpt_drawtext(lua_State* l); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 3593df684..2cd747bb5 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -216,8 +216,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): {"screenshot",&luatpt_screenshot}, {"record",&luatpt_record}, {"element",&luatpt_getelement}, - {"element_func",&luatpt_element_func}, - {"graphics_func",&luatpt_graphics_func}, {"get_clipboard", &platform_clipboardCopy}, {"set_clipboard", &platform_clipboardPaste}, {"setdrawcap", &luatpt_setdrawcap}, diff --git a/src/lua/luascripts/eventcompat.lua b/src/lua/luascripts/eventcompat.lua index b3cdea0ab..4b656cc85 100644 --- a/src/lua/luascripts/eventcompat.lua +++ b/src/lua/luascripts/eventcompat.lua @@ -21,9 +21,10 @@ local function print_deprecation_warnings() print("\""..table.concat(deprecated, "\", \"").."\"") end +tpt.DEPRECATION_WARNINGS = false local function deprecationwarning() - -- no warning for now - --[[local calling_file_info = debug.getinfo(3, "S") + if not tpt.DEPRECATION_WARNINGS then return end + local calling_file_info = debug.getinfo(3, "S") if calling_file_info then calling_file_info = calling_file_info["short_src"] @@ -34,7 +35,7 @@ local function deprecationwarning() event.register(event.tick, print_deprecation_warnings) end end - end]] + end end @@ -223,3 +224,18 @@ function tpt.unregister_keypress(f) registered_keypresses[f] = nil end tpt.unregister_keyevent = tpt.unregister_keypress + + +function tpt.element_func(f, element, replace) + deprecationwarning() + + if f == nil then f = false end + elem.property(element, "Update", f, replace) +end + +function tpt.graphics_func(f, element) + deprecationwarning() + + if f == nil then f = false end + elem.property(element, "Graphics", f) +end