Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua53 fixes #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cmake/FindLua.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to mention, for some reason Lua 5.1 seems to output the version string to stderr. At least that's the case for me under Win7. That's the reason for setting ERROR_VARIABLE to lua_version_str here, in case the interpreter splits out the version string to stderr, cmake will capture it.

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()

Expand Down
3 changes: 2 additions & 1 deletion cmake/lua.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} )
Expand Down
28 changes: 28 additions & 0 deletions luacom-scm-3.rockspec
Original file line number Diff line number Diff line change
@@ -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",
},
}
18 changes: 13 additions & 5 deletions src/library/LuaCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
12 changes: 11 additions & 1 deletion src/library/LuaCompat.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
{
Expand Down
4 changes: 3 additions & 1 deletion src/library/luacom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/library/tLuaCOMTypeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down