Fix overloading for non-pointers and NULL - Lua

This commit is contained in:
William S Fulton 2018-12-30 10:54:53 +00:00
commit cd7772a274
4 changed files with 55 additions and 8 deletions

View file

@ -0,0 +1,41 @@
require("import") -- the import fn
import("overload_null") -- import lib into global
o = overload_null.Overload()
x = overload_null.X()
assert(1 == o:byval1(x))
assert(2 == o:byval1(nil))
assert(3 == o:byval2(nil))
assert(4 == o:byval2(x))
assert(5 == o:byref1(x))
assert(6 == o:byref1(nil))
assert(7 == o:byref2(nil))
assert(8 == o:byref2(x))
assert(9 == o:byconstref1(x))
assert(10 == o:byconstref1(nil))
assert(11 == o:byconstref2(nil))
assert(12 == o:byconstref2(x))
-- const pointer references
assert(13 == o:byval1cpr(x))
assert(14 == o:byval1cpr(nil))
assert(15 == o:byval2cpr(nil))
assert(16 == o:byval2cpr(x))
-- forward class declaration
assert(17 == o:byval1forwardptr(x))
assert(18 == o:byval1forwardptr(nil))
assert(19 == o:byval2forwardptr(nil))
assert(20 == o:byval2forwardptr(x))
assert(21 == o:byval1forwardref(x))
assert(22 == o:byval2forwardref(x))

View file

@ -1765,7 +1765,12 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
{
swig_lua_userdata *usr;
swig_cast_info *cast;
if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */
/* special case: lua nil => NULL pointer */
if (lua_isnil(L,index))
{
*ptr=0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{

View file

@ -4,8 +4,9 @@
* all the runtime code for .
* ----------------------------------------------------------------------------- */
%runtime "swigrun.swg"; /* Common C API type-checking code */
%runtime "luarun.swg"; /* Lua runtime stuff */
%runtime "swigrun.swg" /* Common C API type-checking code */
%runtime "swigerrors.swg" /* SWIG errors */
%runtime "luarun.swg" /* Lua runtime stuff */
%insert(initbeforefunc) "swiginit.swg"

View file

@ -189,7 +189,7 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
// Also needed for object ptrs by const ref
// eg A* const& ref_pointer(A* const& a);
// found in mixed_types.i
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *const&($*ltype temp)
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE *const&($*ltype temp)
%{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname");
$1=($1_ltype)&temp;%}
@ -327,7 +327,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE & {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -336,7 +336,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -345,7 +345,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, 0)) {
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, SWIG_POINTER_NO_NULL)) {
$1 = 0;
} else {
$1 = 1;
@ -367,7 +367,7 @@ parameters match which function
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
{
void *ptr;
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) {
if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) {
$1 = 0;
} else {
$1 = 1;