[Lua] Add support for Lua 5.2 (patch SF#3514593 from Miles Bader)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12968 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2012-04-05 04:29:11 +00:00
commit e3eb54594e
18 changed files with 73 additions and 20 deletions

View file

@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (in progress)
===========================
2012-04-05: olly
[Lua] Add support for Lua 5.2 (patch SF#3514593 from Miles Bader)
2012-03-26: xavier98
[octave] Apply patch #3425993 from jgillis: add extra logic to the octave_swig_type::dims(void) method: it checks if the user has defined a __dims__ method and uses this in stead of returning (1,1)
[octave] Apply patch #3424833 from jgillis: make is_object return true for swig types

View file

@ -2,7 +2,9 @@ require("import") -- the import fn
import("abstract_access") -- import code
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- trying to instantiate pure virual classes
-- should fail

View file

@ -3,7 +3,9 @@ import("cpp_basic") -- import code
cb=cpp_basic -- renaming import
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
f=cb.Foo(4)
assert(f.num==4)

View file

@ -2,7 +2,9 @@ require("import") -- the import fn
import("disown") -- import code
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
for x=0,100 do
a=disown.A()

View file

@ -2,7 +2,9 @@ require("import") -- the import fn
import("enums") -- import lib
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- check values
assert(enums.CSP_ITERATION_FWD==0)

View file

@ -4,7 +4,9 @@ import("exception_order") -- import lib into global
eo=exception_order --alias
-- catching undefined variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
a = eo.A()

View file

@ -2,7 +2,9 @@ require("import") -- the import fn
import("import_nomodule") -- import code
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
f = import_nomodule.create_Foo()
import_nomodule.test1(f,42)

View file

@ -5,7 +5,9 @@ import("li_carrays") -- import code
for k,v in pairs(li_carrays) do _G[k]=v end
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- Testing for %array_functions(int,intArray)
ary = new_intArray(2)

View file

@ -4,7 +4,9 @@ import("li_std_string") -- import lib
for k,v in pairs(li_std_string) do _G[k]=v end -- move to global
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- helper to check type
function is_std_string(s)

View file

@ -2,7 +2,9 @@ require("import") -- the import fn
import("li_typemaps") -- import code
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- Check double INPUT typemaps
assert(li_typemaps.in_double(22.22) == 22.22)

View file

@ -8,7 +8,9 @@ for k,v in pairs(operator_overload) do _G[k]=v end -- move to global
Op_sanity_check()
-- catching undefined variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- test routine:
a=Op()

View file

@ -15,6 +15,24 @@ extern "C" {
#include <stdlib.h> /* for malloc */
#include <assert.h> /* for a few sanity tests */
/* -----------------------------------------------------------------------------
* compatibility defines
* ----------------------------------------------------------------------------- */
/* History of Lua C API length functions: In Lua 5.0 (and before?)
there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
but a compatibility define of "lua_strlen" was added. In Lua 5.2,
this function was again renamed, to "lua_rawlen" (to emphasize that
it doesn't call the "__len" metamethod), and the compatibility
define of lua_strlen was removed. All SWIG uses have been updated
to "lua_rawlen", and we add our own defines of that here for older
versions of Lua. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
# define lua_rawlen lua_strlen
#elif LUA_VERSION_NUM == 501
# define lua_rawlen lua_objlen
#endif
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */

View file

@ -30,7 +30,11 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
/* start with global table */
#ifdef LUA_RIDX_GLOBALS
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
#else
lua_pushvalue(L,LUA_GLOBALSINDEX);
#endif
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();

View file

@ -298,7 +298,7 @@ parmeters match which function
// special check for a char (string of length 1)
%typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& {
$1 = SWIG_lua_isnilstring(L,$input) && (lua_strlen(L,$input)==1);
$1 = SWIG_lua_isnilstring(L,$input) && (lua_rawlen(L,$input)==1);
}
%typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] {

View file

@ -41,18 +41,18 @@ but
Similarly for getting the string
$1 = (char*)lua_tostring(L, $input);
becomes
$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));
$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));
Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
*/
%typemap(in,checkfn="lua_isstring") std::string
%{$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));%}
%{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%}
%typemap(out) std::string
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in,checkfn="lua_isstring") const std::string& (std::string temp)
%{temp.assign(lua_tostring(L,$input),lua_strlen(L,$input)); $1=&temp;%}
%{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
%typemap(out) const std::string&
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}

View file

@ -30,7 +30,7 @@ wchar_t* str2wstr(const char *str, int len)
%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t *
%{
$1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input ));
$1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input ));
if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;}
%}

View file

@ -331,7 +331,7 @@ public:
Printf(s_dot_set, "\nconst LUA_REG_TYPE dot_set[] = {\n");
}
} else {
Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n");
Printf(s_cmd_tab, "\nstatic const struct luaL_Reg swig_commands[] = {\n");
Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n");
Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n");
Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");

View file

@ -1890,7 +1890,12 @@ else
# can we find lua?
if test "x$LUABIN" = xyes; then
AC_PATH_PROG(LUABIN, lua)
# We look for a versioned Lua binary first, as there can be
# multiple versions of Lua installed on some systems (like Debian).
# The search order should match the include-file and library search
# orders below (a Lua shared library built for one version may not
# work with a Lua binary of a different version).
AC_PATH_PROGS(LUABIN, [lua5.2 lua5.1 lua])
fi
# check version: we need Lua 5.x
@ -1938,8 +1943,11 @@ else
# if we didn't get it, going to have to look elsewhere (the hard way)
if test -z "$LUA_OK"; then
AC_MSG_CHECKING(for lua.h in other locations)
# note: ubuntu seems to like /usr/include/lua5.1/lua.h
dirs="/usr/include/lua* /usr/local/include"
# note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h
# The ordering of the include directories to search should match
# the ordering of libraries to search in the library test below.
inc=/usr/include
dirs="$inc/lua5.2 $inc/lua5.1 $inc/lua51 $inc/lua5.0 $inc/lua50 /usr/local/include"
for i in $dirs; do
#echo "$i"
if test -r $i/lua.h; then
@ -1962,7 +1970,7 @@ lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving
if test -n "$LUALIB"; then
AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=])
else
AC_SEARCH_LIBS(lua_close, [lua lua51 lua5.1 lua50 lua5.0], [LUALINK="-l$ac_lib"],[LUABIN=])
AC_SEARCH_LIBS(lua_close, [lua lua5.2 lua5.1 lua51 lua5.0 lua50], [LUALINK="-l$ac_lib"],[LUABIN=])
fi
# adding lualib for lua 5.0