From 1f856ecd8ead5b3f7933bc94c77e9b7c77399197 Mon Sep 17 00:00:00 2001 From: planetmaker Date: Thu, 16 Sep 2021 17:13:20 +0200 Subject: [PATCH 1/2] Add: Support for Lua 5.4 bindings --- CMakeModules/FindLua54.cmake | 81 ++++++++++++++++++++++++++++++++++ CMakeModules/FindLuabind.cmake | 24 +++++++--- 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 CMakeModules/FindLua54.cmake diff --git a/CMakeModules/FindLua54.cmake b/CMakeModules/FindLua54.cmake new file mode 100644 index 000000000..89812a406 --- /dev/null +++ b/CMakeModules/FindLua54.cmake @@ -0,0 +1,81 @@ +# Locate Lua library +# This module defines +# LUA54_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_path(LUA_INCLUDE_DIR lua.h + HINTS + ENV LUA_DIR + PATH_SUFFIXES include/lua54 include/lua5.4 include/lua-5.4 include/lua include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(LUA_LIBRARY + NAMES lua54 lua5.4 lua-5.4 lua + HINTS + ENV LUA_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +if(LUA_LIBRARY) + # include the math library for Unix + if(UNIX AND NOT APPLE AND NOT BEOS) + find_library(LUA_MATH_LIBRARY m) + set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + else() + set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + endif() +endif() + +if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + unset(lua_version_str) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua54 + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) + diff --git a/CMakeModules/FindLuabind.cmake b/CMakeModules/FindLuabind.cmake index dae1dbd99..6b68821b6 100644 --- a/CMakeModules/FindLuabind.cmake +++ b/CMakeModules/FindLuabind.cmake @@ -10,18 +10,32 @@ MACRO(FIND_CORRECT_LUA_VERSION) IF(LUABIND_LIBRARY_RELEASE MATCHES "\\.so") INCLUDE(CheckDepends) - # check for Lua 5.3 - SET(LUA53_LIBRARIES liblua5.3 liblua-5.3 liblua.so.5.3) + # check for Lua 5.4 + SET(LUA54_LIBRARIES liblua5.4 liblua-5.4 liblua.so.5.4) - FOREACH(_LIB ${LUA53_LIBRARIES}) + FOREACH(_LIB ${LUA54_LIBRARIES}) CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND) IF(LUALIB_FOUND) - MESSAGE(STATUS "Luabind is using Lua 5.3") - FIND_PACKAGE(Lua53 REQUIRED) + MESSAGE(STATUS "Luabind is using Lua 5.4") + FIND_PACKAGE(Lua54 REQUIRED) BREAK() ENDIF() ENDFOREACH() + IF(NOT LUALIB_FOUND) + # check for Lua 5.3 + SET(LUA53_LIBRARIES liblua5.3 liblua-5.3 liblua.so.5.3) + + FOREACH(_LIB ${LUA53_LIBRARIES}) + CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND) + IF(LUALIB_FOUND) + MESSAGE(STATUS "Luabind is using Lua 5.3") + FIND_PACKAGE(Lua53 REQUIRED) + BREAK() + ENDIF() + ENDFOREACH() + ENDIF() + IF(NOT LUALIB_FOUND) # check for Lua 5.2 SET(LUA52_LIBRARIES liblua5.2 liblua-5.2 liblua.so.5.2) From 1eec1fe31e5a98e9b23cd0c072d6c7a9cedf4111 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 17 Sep 2021 19:54:23 +0800 Subject: [PATCH 2/2] Fix vs2008 build --- nel/src/gui/css_background_renderer.cpp | 4 ++-- nel/src/gui/css_length.cpp | 3 ++- nel/src/gui/libwww.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nel/src/gui/css_background_renderer.cpp b/nel/src/gui/css_background_renderer.cpp index 4d7df021e..2c755ad80 100644 --- a/nel/src/gui/css_background_renderer.cpp +++ b/nel/src/gui/css_background_renderer.cpp @@ -438,7 +438,7 @@ namespace NLGUI if (bg.repeatX == CSS_VALUE_ROUND) { - sint numTiles = std::max(1, (sint)std::round((float)areaW / texW)); + sint numTiles = std::max(1, (sint)std::ceil(((float)areaW / texW) - 0.5f)); texW = areaW / numTiles; if (bg.height.isAuto() && bg.repeatY != CSS_VALUE_ROUND) { @@ -449,7 +449,7 @@ namespace NLGUI if (bg.repeatY == CSS_VALUE_ROUND) { - sint numTiles = std::max(1, (sint)std::round((float)areaH / texH)); + sint numTiles = std::max(1, (sint)std::ceil(((float)areaH / texH) - 0.5f)); texH = areaH / numTiles; if (bg.width.isAuto() && bg.repeatX != CSS_VALUE_ROUND) { diff --git a/nel/src/gui/css_length.cpp b/nel/src/gui/css_length.cpp index 79465c27d..b68b90f25 100644 --- a/nel/src/gui/css_length.cpp +++ b/nel/src/gui/css_length.cpp @@ -30,9 +30,10 @@ namespace NLGUI bool CSSLength::parseValue(const std::string &value, bool allowPercent, bool allowNegative) { - static const std::set knownUnits = { + static const std::string knownUnitsArr[] = { "%", "rem", "em", "px", "pt", "vw", "vh", "vi", "vb", "vmin", "vmax" }; + static const std::set knownUnits(knownUnitsArr, &knownUnitsArr[sizeof(knownUnitsArr) / sizeof(knownUnitsArr[0])]); std::string::size_type pos = 0; std::string::size_type len = value.size(); diff --git a/nel/src/gui/libwww.cpp b/nel/src/gui/libwww.cpp index 5d739863d..69d0ca992 100644 --- a/nel/src/gui/libwww.cpp +++ b/nel/src/gui/libwww.cpp @@ -208,9 +208,10 @@ namespace NLGUI // *************************************************************************** bool getCssLength (float &value, std::string &unit, const std::string &str, bool neg) { - static const std::set knownUnits = { + static const std::string knownUnitsArr[] = { "%", "rem", "em", "px", "pt", "vw", "vh", "vi", "vb", "vmin", "vmax" }; + static const std::set knownUnits(knownUnitsArr, &knownUnitsArr[sizeof(knownUnitsArr) / sizeof(knownUnitsArr[0])]); std::string::size_type pos = 0; std::string::size_type len = str.size();