Commit graph

177 commits

Author SHA1 Message Date
William S Fulton
319442a8c4 More move semantics improvements
More removal of casts in the out typemaps when copying objects to enable
C++ compilers to possibly make use of move semantics.
2022-07-04 11:19:50 +01:00
William S Fulton
bf36bf7d8a Movable and move-only types supported in "out" typemaps.
Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.

Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.

The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:

  SwigValueWrapper::operator T&() const;

to

  #if __cplusplus >=201103L
    SwigValueWrapper::operator T&&() const;
  #else
    SwigValueWrapper::operator T&() const;
  #endif

This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:

1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
   __cplusplus macro if all versions of C++ need to be supported.

Issue #999
Closes #1044

More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.

Ruby std::set fix for SwigValueWrapper C++11 changes.
2022-06-30 17:26:48 +01:00
William S Fulton
6860e2bc03 Document argc argv library 2022-05-15 19:12:39 +01:00
William S Fulton
e4cdf9d98f argcargv.i cosmetic updates 2022-05-15 18:32:53 +01:00
Konrad Eisele
f3ee3f2b12 Add argcargv.i to Lua
Found in https://stackoverflow.com/questions/9860362/swig-lua-call-mint-argv-char-argc
2022-05-06 13:26:17 +02:00
Olly Betts
b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
Olly Betts
b5544a1812 Remove commented out redundant code
This was an alternate version without NULL checks on free() and
delete, but we removed those checks globally in
7ec2f89fe2 so now it's just the
same as the active code.
2022-02-27 18:15:46 +13:00
Olly Betts
31af3ce9bf Avoid -Wempty-body warnings from SWIG_contract_assert 2022-02-11 18:39:08 +13:00
Seth R Johnson
de78b80de9 Renames performed by %namewarn with rename= are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
Olly Betts
7ec2f89fe2
Remove redundant NULL checks before free()/delete (#2184)
Remove redundant NULL checks before free()/delete

The ISO C and C++ standards guarantee that it's safe to call these
on a NULL pointer, so it's not necessary for the calling code to
also check.

Fixes https://sourceforge.net/p/swig/feature-requests/70/
2022-01-29 22:03:48 +13:00
tytan652
fa2f9dc5da [lua] Fix maybe-uninitialized warning in generated code 2021-12-15 09:31:13 +13:00
William S Fulton
01eb2e0aa9 Lua int ref typemap improvements
Fixes complex typedefs to const int& and const unsigned int&.
Fixes cpp11_type_aliasing testcase
2021-11-12 19:30:53 +00:00
William S Fulton
13158bda9a Member function pointer typemap tweaks
Use sizeof variable name rather than variable type.
Workaround Visual C++ unable to parse some complex C++11 types, such as
  sizeof(short (Funcs::*)(bool) const &&)
2021-04-26 22:32:52 +01:00
Olly Betts
f198ff0a43 Fix more "allows to" and other typos 2021-04-21 15:54:46 +12:00
Ryan Nevell
33c59614fc Fix unwrapping of LUA lightuserdata type. Add test case. 2020-02-17 09:16:24 -08:00
Shane Liesegang
49a8e28eb9 removing unnecessary bits 2019-08-02 23:10:19 +02:00
Shane Liesegang
fe758f3e05 closer match to Python's output 2019-08-02 23:05:53 +02:00
Shane Liesegang
9c5b97ae36 typo 2019-07-28 00:43:01 +02:00
Shane Liesegang
b145c49375 actually seeing both is useful 2019-07-27 20:47:18 +02:00
Shane Liesegang
ac47e4b76a matching code conventions 2019-07-20 07:09:24 +02:00
Shane Liesegang
0c2b454eb3
Lua userdata print pointing to wrapped memory
This is actually a fix to some functionality that I submitted many years ago. :) At the time I set the string conversion to output the userdata address, but since that points to an internal SWIG structure, it's way more useful to the user to point to the actual memory being wrapped in that userdata.
2019-07-20 07:05:38 +02:00
William S Fulton
52063a732b Consistent parameter names for std::pair 2019-02-14 22:44:27 +00:00
William S Fulton
6d27ead9c0 Add STL container copy constructors where missing
Also provide consistent copy constructor declarations.
2019-02-14 18:53:05 +00:00
William S Fulton
e26f6bb4e2 Add missing typedefs to std::vector + typedef corrections
Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
2019-02-13 22:46:28 +00:00
William S Fulton
a47c2553f5 Add missing typedefs to std::pair 2019-02-13 22:46:28 +00:00
William S Fulton
9dd33e6367 Add missing typedefs to std::map 2019-02-13 22:46:27 +00:00
William S Fulton
6d0c495fd0 Add missing parameter names in STL container wrappers
Mostly in STL copy constructors.

Best to have parameter names as they make their way into the wrappers in
some target languages.
2019-02-13 22:45:47 +00:00
William S Fulton
cd7772a274 Fix overloading for non-pointers and NULL - Lua 2018-12-30 10:54:53 +00:00
William S Fulton
ca287ae13b Add support for non-default compare template argument in std::map wrappers 2018-10-09 19:44:00 +01:00
luz.paz
60dfa31a67 Misc. typos
found via `codespell` and `grep`
2018-05-17 10:04:23 -04:00
Olly Betts
90f9117e10 Fix various comment and documentation typos 2017-08-13 18:04:33 +12:00
William S Fulton
50e6611a9c Merge branch 'jleveque-warning_fix'
* jleveque-warning_fix:
  [Lua] Fix compiler warnings
2017-04-25 07:31:31 +01:00
William S Fulton
7b9d94db2e Fix Lua warning for missing (SWIGTYPE CLASS::*) typemaps for C wrappers 2017-04-25 07:29:54 +01:00
Joe LeVeque
e66d8125aa [Lua] Fix compiler warnings 2017-03-31 01:45:26 -07:00
William S Fulton
72ba741d1c Fix wrapping of references/pointers and qualifiers to member pointers
Also fix Go wrapping of member const function pointers.
2017-03-16 21:04:38 +00:00
Daniel Vollmer
ce1cb85d86 Add <typeinfo> header for std::bad_cast 2016-09-17 13:24:32 +02:00
Daniel Vollmer
2dc87d7485 Add std::bad_cast to std_except.i
This exception occurs when dynamic_cast<T&> fails.

Fixes #783.
2016-09-17 10:26:54 +02:00
Alexander Warg
4363160400 Fix lua base class methods with __getitem
When a C++ class defined a __getitem function the base classes where
never used for resolving methods. This fix first scans the '.get' and
'.fn' tables of all base classes and only if there is no result does the
same for __getitem functions.
2016-03-17 07:46:44 +01:00
Nils Gladitz
ca208cfe35 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.
2015-07-01 12:24:12 +02:00
Alexander Warg
ece1009c5d lua: push integer constants as integer
This allows better compatibility with Lua 5.3. Otherwise function
overloading assuming integer parameters might not work.
2015-04-28 17:09:57 +02:00
Thomas Trocha
4e7af7db80 [lua/luarun] change return type from int to void on functions not returning anything
Using emscripten compiler to crosscompile to javascript lead to "traps" on this functions which results in a crash
2015-01-11 15:34:07 +01:00
William S Fulton
cb4d0dbba5 %constant and structs support for Lua 2014-12-29 17:36:56 +00:00
Artem Serebriyskiy
4457d96e54 Moving variable declaration to the beginning of the block 2014-05-28 22:02:47 +04:00
Artem Serebriyskiy
2b4c49d017 Add default __eq implementation
* Renamed SWIG_Lua_equal to SWIG_Lua_class_equal
* If class has no __eq implemented, then default __eq is provided.
  Default __eq compares actual pointers stored inside Lua userdata
2014-05-28 22:01:23 +04:00
Olly Betts
703862dc3a Fix unused variable warning in Lua bindings 2014-05-28 23:04:06 +12:00
William S Fulton
10cbd2781f Refactor Lua class base search to make ISO c/c++ compliant 2014-05-24 14:13:24 +01:00
William S Fulton
3191473523 Fix compiler warnings in generated code when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type 2014-05-24 14:13:19 +01:00
Olly Betts
1a0b8abec7 Fix comment typo 2014-05-24 11:11:51 +12:00
Olly Betts
8d3902a666 Work towards C90 compatibility for Lua 2014-05-24 11:10:57 +12:00
Olly Betts
95f09b49d2 Don't use // comments in C code. 2014-05-18 20:38:43 +12:00