From e979862784a952ed899638b52e4bcfb0a64f441f Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sat, 29 Feb 2020 19:52:48 -0800 Subject: [PATCH 1/8] Changed to 'find_package' instead since 'find_program' cannot find lua executables with suffix. eg. fails to find something like 'lua53.exe' --- cmake/lua.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/lua.cmake b/cmake/lua.cmake index 80bbc5f..78929fc 100644 --- a/cmake/lua.cmake +++ b/cmake/lua.cmake @@ -251,7 +251,8 @@ endmacro () # [1] http://lua-users.org/wiki/BinToCee # [2] http://lua-users.org/wiki/LuaCompilerInLua function ( add_lua_bin2c _target _source ) - find_program ( LUA NAMES lua lua.bat ) + find_package ( Lua REQUIRED ) + set ( LUA ${LUA_EXECUTABLE} CACHE STRING "" ) execute_process ( COMMAND ${LUA} -e "string.dump(function()end)" RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET ) if ( NOT ${_LUA_DUMP_RESULT} ) From 454e5386b1687183eff3144990d9cfe598664eaa Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sat, 29 Feb 2020 20:17:05 -0800 Subject: [PATCH 2/8] Removed usage of old 'luaL_register'. This should be refactored so luacom module isn't dumped into global space but one step at a time. --- src/library/luacom.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library/luacom.cpp b/src/library/luacom.cpp index e8ea9d9..401c497 100644 --- a/src/library/luacom.cpp +++ b/src/library/luacom.cpp @@ -2220,7 +2220,9 @@ LUACOM_API void luacom_open(lua_State *L) LUASTACK_SET(L); // creates LuaCOM library table - luaL_register(L, LIBNAME, functions_tb); + luaL_newlib(L, functions_tb); + lua_pushvalue(L, -1); + lua_setglobal(L, LIBNAME); // prepares to store configuration table in // library table From a2bf47b91a3f83c4dbc7a09b13b2876758752535 Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sat, 29 Feb 2020 21:57:35 -0800 Subject: [PATCH 3/8] Fixed comment and typo. --- src/library/LuaCompat.cpp | 2 +- src/library/LuaCompat.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/library/LuaCompat.cpp b/src/library/LuaCompat.cpp index 0cea1ed..315cff5 100644 --- a/src/library/LuaCompat.cpp +++ b/src/library/LuaCompat.cpp @@ -2,7 +2,7 @@ * LuaCompat.c * * Implementation of the class LuaCompat, - * which tries to hide almost all diferences + * which tries to hide almost all differences * between Lua versions * * This file isn't as useful as it used to be since diff --git a/src/library/LuaCompat.h b/src/library/LuaCompat.h index a593b65..966c4b4 100644 --- a/src/library/LuaCompat.h +++ b/src/library/LuaCompat.h @@ -1,9 +1,11 @@ /* * LuaCompat.h * - * Library that tries to hide almost all diferences + * Library that tries to hide almost all differences * between Lua versions * + * This file isn't as useful as it used to be since + * we no longer support Lua < 5.1. */ #ifndef __LUACOMPAT_H From cd3627e2c0cf6fec90a4615f5527854ed48c467a Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sat, 29 Feb 2020 22:41:34 -0800 Subject: [PATCH 4/8] Changes to migrate towards Lua 5.3 C api. Added compatibility code so luacom can still build under Lua 5.1 --- src/library/LuaCompat.cpp | 16 ++++++++++++---- src/library/LuaCompat.h | 8 ++++++++ src/library/tLuaCOMTypeHandler.cpp | 8 -------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/library/LuaCompat.cpp b/src/library/LuaCompat.cpp index 315cff5..e067a1c 100644 --- a/src/library/LuaCompat.cpp +++ b/src/library/LuaCompat.cpp @@ -105,11 +105,7 @@ int luaCompat_isOfType(lua_State* L, const char* module, const char* type) luaCompat_getType(L, -1); luaCompat_pushTypeByName(L, module, type); -#if defined(NLUA51) result = (lua_compare(L, -1, -2,LUA_OPEQ) ? 1 : 0); -#else - result = (lua_equal(L, -1, -2) ? 1 : 0); -#endif lua_pop(L, 2); LUASTACK_CLEAN(L, 0); @@ -209,3 +205,15 @@ int luaCompat_checkTagToCom(lua_State *L, int luaval) return 1; } +#if LUA_VERSION_NUM < 502 +int lua_compare(lua_State *L, int a, int b, LUA_OPS op) +{ + switch(op) + { + case LUA_OPEQ: return lua_equal(L, a, b); + case LUA_OPLT: return lua_lessthan(L, a, b); + case LUA_OPLE: return !lua_lessthan(L, b, a); + default: return 0; + } +} +#endif diff --git a/src/library/LuaCompat.h b/src/library/LuaCompat.h index 966c4b4..1c5fc71 100644 --- a/src/library/LuaCompat.h +++ b/src/library/LuaCompat.h @@ -31,6 +31,14 @@ void luaCompat_moduleGet(lua_State* L, const char* module, const char* key); int luaCompat_checkTagToCom(lua_State *L, int luaval); +#if LUA_VERSION_NUM < 502 +#define luaL_newlib(L, l) lua_createtable(L, 0, sizeof((l)) / sizeof((l[0])) ); luaL_register(L, NULL, l) +#define lua_rawlen(L, index) lua_objlen(L, index) + +enum LUA_OPS { LUA_OPEQ = 0, LUA_OPLT, LUA_OPLE, }; +int lua_compare(lua_State *L, int a, int b, LUA_OPS op); +#endif + #ifdef __cplusplus extern "C" { diff --git a/src/library/tLuaCOMTypeHandler.cpp b/src/library/tLuaCOMTypeHandler.cpp index 08b005f..7568a84 100644 --- a/src/library/tLuaCOMTypeHandler.cpp +++ b/src/library/tLuaCOMTypeHandler.cpp @@ -470,11 +470,7 @@ void tLuaCOMTypeHandler::lua2com(lua_State* L, stkIndex luaval, VARIANTARG& varg case LUA_TSTRING: { tStringBuffer str; -#if defined(NLUA51) size_t l_len = lua_rawlen(L, luaval); // For > Lua 5.1 -#else - size_t l_len = lua_strlen(L, luaval); -#endif str.copyToBuffer(lua_tostring(L, luaval), l_len); varg.vt = VT_BSTR; varg.bstrVal = tUtil::string2bstr(str, l_len); @@ -1420,11 +1416,7 @@ void tLuaCOMTypeHandler::safearray_lua2com(lua_State* L, { string2safearray( lua_tostring(L, luaval), -#if defined(NLUA51) lua_rawlen(L, luaval), // For > Lua 5.1 -#else - lua_strlen(L, luaval), -#endif varg ); return; From 16ea2544f1fd47c961ba78201d5b80b9ab242486 Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sat, 29 Feb 2020 23:16:43 -0800 Subject: [PATCH 5/8] Added suffix search for Lua 5.3 --- cmake/FindLua.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake index 7fb7ca3..901888f 100644 --- a/cmake/FindLua.cmake +++ b/cmake/FindLua.cmake @@ -40,7 +40,7 @@ SET(_POSSIBLE_LUA_LIBRARY lua) IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) - SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") + SET(_POSSIBLE_SUFFIXES "53" "5.3" "-5.3" "52" "5.2" "-5.2" "51" "5.1" "-5.1") ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) # Set up possible search names and locations From 72e2a31638a6ce660c6efadec993a424a17504e3 Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sun, 1 Mar 2020 00:48:13 -0800 Subject: [PATCH 6/8] Added suffix search for LuaJIT --- cmake/FindLua.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake index 901888f..21c9095 100644 --- a/cmake/FindLua.cmake +++ b/cmake/FindLua.cmake @@ -41,6 +41,7 @@ IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) SET(_POSSIBLE_SUFFIXES "53" "5.3" "-5.3" "52" "5.2" "-5.2" "51" "5.1" "-5.1") + SET(_POSSIBLE_JIT_SUFFIXES "-2.1" "-2.0") ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) # Set up possible search names and locations @@ -50,6 +51,12 @@ FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") ENDFOREACH(_SUFFIX) +# Repeat for Luajit +LIST(APPEND _POSSIBLE_LUA_EXECUTABLE luajit) +FOREACH(_SUFFIX ${_POSSIBLE_JIT_SUFFIXES}) + LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/luajit${_SUFFIX}") +ENDFOREACH(_SUFFIX) + # Find the lua executable FIND_PROGRAM(LUA_EXECUTABLE NAMES ${_POSSIBLE_LUA_EXECUTABLE} From ac3321f534e1579ef84a7251ee1645a1a7bc83e2 Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sun, 1 Mar 2020 02:08:48 -0800 Subject: [PATCH 7/8] Get Lua version from interpreter stdout/stderr. More reliable than matching against lua headers. --- cmake/FindLua.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake index 21c9095..906de8e 100644 --- a/cmake/FindLua.cmake +++ b/cmake/FindLua.cmake @@ -107,10 +107,14 @@ IF(LUA_LIBRARY) ENDIF(LUA_LIBRARY) # Determine Lua version -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}") +IF(LUA_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${LUA_EXECUTABLE} -v + OUTPUT_VARIABLE lua_version_str + ERROR_VARIABLE lua_version_str) + STRING(REGEX REPLACE "^(Lua|LuaJIT)[ \\t]+([0-9]\\.[0-9]\\.[0-9]).*" + "\\1 \\2" + LUA_VERSION_STRING + "${lua_version_str}") UNSET(lua_version_str) ENDIF() From 4f8a0ea22a836aa25ac3ecd13711b11c4bf03738 Mon Sep 17 00:00:00 2001 From: Greatwolf Date: Sun, 1 Mar 2020 02:12:10 -0800 Subject: [PATCH 8/8] Updated rockpsec file to use CMake. --- luacom-scm-3.rockspec | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 luacom-scm-3.rockspec diff --git a/luacom-scm-3.rockspec b/luacom-scm-3.rockspec new file mode 100644 index 0000000..c49e912 --- /dev/null +++ b/luacom-scm-3.rockspec @@ -0,0 +1,28 @@ +package = "LuaCOM" +version = "scm-3" +source = { + url = "git://github.com/davidm/luacom.git" +} +description = { + summary = "Use COM libraries from Lua", + detailed = [[ +LuaCOM is an add-on library to the Lua language that allows Lua programs to use and implement objects that follow Microsoft's Component Object Model (COM) specification and use the ActiveX technology for property access and method calls. ]], + license = "MIT/X11", + homepage = "http://luaforge.net/projects/luacom/" +} +supported_platforms = { + "windows" +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "cmake", + variables = { + CMAKE_CXX_FLAGS = "$(CFLAGS)", + CMAKE_PREFIX_PATH = "$(LUA_LIBDIR)", + CMAKE_INSTALL_PREFIX = "$(PREFIX)", + -- turn this on for helpful build debugging + CMAKE_VERBOSE_MAKEFILE = "OFF", + }, +}