lua: push characters as unformatted 1-character strings

Since Lua 5.3 the "%c" format character in lua_pushfstring will produce
the string "<\XXX>" (XXX being a decimal code sequence) when
given unprintable characters.

Use lua_pushlstring instead to reproduce the old behavior.
This commit is contained in:
Nils Gladitz 2015-07-01 12:24:12 +02:00
commit ca208cfe35
6 changed files with 37 additions and 4 deletions

View file

@ -185,7 +185,7 @@ use %include <std_except.i> instead
// char is changed to a string
%typemap(throws) char
%{lua_pushfstring(L,"%c",$1);SWIG_fail;%}
%{lua_pushlstring(L,&$1,1);SWIG_fail;%}
/*
Throwing object is a serious problem:

View file

@ -1841,7 +1841,10 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
break;
case SWIG_LUA_CHAR:
lua_pushstring(L,constants[i].name);
lua_pushfstring(L,"%c",(char)constants[i].lvalue);
{
char c = constants[i].lvalue;
lua_pushlstring(L,&c,1);
}
lua_rawset(L,-3);
break;
case SWIG_LUA_STRING:

View file

@ -122,14 +122,14 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
%{$1 = (lua_tostring(L, $input))[0];%}
%typemap(out) char
%{ lua_pushfstring(L,"%c",$1); SWIG_arg++;%}
%{ lua_pushlstring(L, &$1, 1); SWIG_arg++;%}
// by const ref
%typemap(in,checkfn="SWIG_lua_isnilstring",fragment="SWIG_lua_isnilstring") const char& (char temp)
%{temp = (lua_tostring(L, $input))[0]; $1=&temp;%}
%typemap(out) const char&
%{ lua_pushfstring(L,"%c",*$1); SWIG_arg++;%}
%{ lua_pushlstring(L, $1, 1); SWIG_arg++;%}
// pointers and references
// under SWIG rules, it is ok, to have a pass in a lua nil,