diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake index 7fb7ca3..906de8e 100644 --- a/cmake/FindLua.cmake +++ b/cmake/FindLua.cmake @@ -40,7 +40,8 @@ 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") + 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} @@ -100,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() 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} ) 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", + }, +} diff --git a/src/library/LuaCompat.cpp b/src/library/LuaCompat.cpp index 0cea1ed..e067a1c 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 @@ -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 a593b65..1c5fc71 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 @@ -29,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/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 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;