SWIG_Lua_director_has_method() and SWIG_Lua_director_call_method() in
director.swg are not referenced by the generated code or anywhere else. The
generated director methods look up the method override themselves, via
SWIG_Lua_get_director_override(), and make the lua_pcall() inline.
Assisted-by: Claude Code (Opus 4.8)
Directors store the table of Lua method overrides for an object in the
userdata's uservalue. Uservalues were added in Lua 5.2, so directors did not
compile at all for Lua 5.1 or LuaJIT, failing with:
error: 'lua_getuservalue' was not declared in this scope
error: 'lua_setuservalue' was not declared in this scope
Uservalues replaced the userdata environments of Lua 5.1, so use the
environment functions, lua_getfenv and lua_setfenv, when wrapping for Lua 5.1.
The two are not quite interchangeable and simply defining lua_getuservalue to
lua_getfenv is subtly wrong. A new userdata has no uservalue (nil) in Lua 5.2
and later, but in Lua 5.1 it inherits the environment of the C function
creating it, which turns out to be Lua's package table, shared by every
userdata the module creates. The "is there a table of overrides yet?" test
would then always succeed and every object's overrides would be written into
that one shared table - overrides set on one object would be seen by all other
objects and the package table would be corrupted. So the tables created for
overrides are marked with a key that is not a valid C++ method name, and an
unmarked environment is reported as nil to match Lua 5.2.
The override lookup was inlined into every generated director method, so it is
now generated as a call to a new SWIG_Lua_get_director_override() in
director.swg instead. This puts the uservalue handling in one place and makes
the generated code smaller.
The Lua examples and the whole Lua test-suite, including all the director
tests, now pass with Lua 5.1, and continue to pass with Lua 5.3. A director
wrapper also compiles against LuaJIT's headers.
Assisted-by: Claude Code (Opus 4.8)
the new Lua directors feature uses lua_setuservalue, added in Lua 5.2.
Removing the LUA_VERSION_NUM-guarded compatibility defines for lua_rawlen,
lua_pushglobaltable and lua_rawsetp/lua_rawgetp from Lib/lua/luarun.swg.
LuaJIT implements the Lua 5.1 API and, per its own documentation, is
"API+ABI-compatible with Lua 5.1, which prevents implementing features
that would otherwise break the Lua/C API and ABI" (https://luajit.org/extensions.html,
"Extensions from Lua 5.2" section) - so it never defines these Lua 5.2 additions.
Noticed when rebuilding obs-studio's LuaJIT-based Lua bindings against SWIG master.
Restore those compatibility defines, scoped to 5.1 and later only (the old
Lua 5.0-only shims are not restored).
Also revert an incidental ok!=LUA_OK comparison introduced by #3394
back to ok!=0, since LUA_OK isn't defined pre-5.2 either and luaL_dostring()
already returns 0 on success on every Lua version.
Fix the examples and test-suite where they themselves used Lua 5.2 only
features: LUA_OK in Examples/lua/embed/embed.c, _ENV in helpers.lua, and
string.format("%c", ...) in li_cdata_bytes, which yields an empty string for a
NUL byte in Lua 5.1 as strlen() is applied to the formatted result, so
string.char() is used instead.
Directors continue to require Lua 5.2 or later and are unaffected by this
change; the Lua 5.1 director test failures are addressed separately.
Assisted-by: Claude Code (Sonnet 5)
A 'char *&' (a reference to a char pointer) was only marshalled as a string by
C#, D, Go, Java and PHP; every other language treated it as an opaque char **
pointer. Add char *& string typemaps to the languages that were missing them,
so a char *& function argument, return value or variable is marshalled as a
string in every target language. SWIG's const reference stripping means this
also covers char *const&.
- Lib/typemaps/strings.swg: add Char *& to the %typemaps_string in, freearg,
out, typecheck and director typemaps. This gives char *& to the languages
that use the Unified Typemap Library (Python, Ruby, Perl, Tcl, Octave, Scilab,
R and JavaScript). The shared in typemap now casts &buf to $1_ltype so that a
const char * reference hidden behind a typedef also compiles.
- Lib/lua/luatypemaps.swg, Lib/guile/typemaps.i, Lib/ocaml/ocaml.swg: these
define their own char * string typemaps; give each char *& and const char *&
in/out/freearg typemaps too.
- Lib/r/rtype.swg: the C wrapper returned the char *& string correctly but the R
proxy wrapped it as an undefined _p_p_char S4 class; add char *& to the
scoerceout char list so it is returned as a plain character value.
char_strings.i is now exercised by a runme in every target language, all testing
the same set of functions (get/set/pingpong/global variables and all four char *&
functions), giving complete char *& typemap coverage and testing.
Where a language genuinely cannot support part of the char array portion of the
test (a char[] global has no varin typemap in most scripting languages, a char[16]
parameter is bounds checked, and Guile/OCaml reject char[] parameters), that one
assertion is adapted or skipped with an inline comment; the char *& coverage is
complete everywhere.
Assisted-by: Claude Code (Opus 4.8)
- configure.ac: fix "Bellow" -> "below" in the unsupported version warning
- Doc/Manual/Lua.html: fix grammar in the eLua status sentence
- Lib/lua/luarun.swg: collapse a two-line comment to one line
Assisted-by: Claude Opus 4.7
- configure.ac
- Use minimum version 5.2 for Lua
- Add lua 5.5, it was released in dec 2025
- Syntax improvements
- GHA CI
- Remove 'default' Lua version, it is confusing.
Just select the version explicitly.
- Add Lua 5.4 test, we need to test all supported versions 5.2, 5.3 and 5.4
Lua 5.5 is not available on Ubuntu yet.
- Lua documentation Doc/Manual/Lua.html
- Update version to 5.2
- Remove mention to older SWIG version,
whom wishes to go to the very old history can look on CHANGES.
- Add references on missing operators in Lua.
- _ENV exist from Lua 5.2.
- Remove old compatibility code from Lib/lua/luarun.swg.
- Remove LUA_VERSION_NUM from Lua C wrapping code.
It was used for old Lua 5.0 and Lua 5.1.
- Remove _VERSION from Lua tests.
Note: _VERSION remains a keyword and developers may use it in interface files!
- Remove Example/lua/import.lua and Examples/test-suite/lua/import.lua
as they are not used or needed any longer.
- Remove old Lua import.
- Add Examples/test-suite/lua/helpers.lua
- include it in all tests in test-suite.
- Add catch "undefined" global variables enable function.
- Add import_to_globs function.
To add module functions, variables and classes to global scope.
- Remove the -squash-bases option as it is broken
The der.new_func from the example
in the document, "29.3.18.3 Inheritance",
pass from base object to derived object
regardless of using the flag or not.
- Remove -no-old-metatable-bindings as it is deprecated in the last 12 years
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
- [Lua] Fix off-by-one when nil terminates the table early: use $1 = i
(not i + 1) to match the count of strings actually copied, and pop
the nil from the Lua stack before breaking.
- [Python] In SWIG_AsCharPtrAndSize (pystrings.swg) decref bytes / obj
on the SWIG_MemoryError early returns added by the previous commits,
so an allocation failure no longer leaks the temporary PyObject.
- [Octave, Python] In argcargv.i free already-allocated string entries
and the array itself before failing on a per-element OOM (Python uses
the existing break path so the freearg typemap performs the cleanup).
- [Perl, PHP, Tcl] Drop unreachable `goto fail` after SWIG_croak /
SWIG_PHP_Error / SWIG_exception_fail, all of which already invoke
SWIG_fail. Compilers warning on unreachable code complained.
- Standardise the OOM error wording across languages and fix the
3- and 5-space indentation introduced by the previous commits.
- Update Examples/perl5/xmlstring/xmlstring.i to the new
%typemaps_string signature (it picks up the missing WarningLeakMsg
argument too) and add a SWIG_NewCopyXMLChArray fragment.
- CHANGES.current: document the API breakages introduced by removing
%new_copy_array, removing %typemaps_string_alloc and extending
%typemaps_string, including the actual error text users will see.
Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
* char_binary_java_fix-tidyup:
Move SWIGStringWithLengthHelper to csharphead.swg
cdata whitespace/cosmetic fixups
cdata doc updates
Rename `typemaps/cdata_struct.swg` to `typemaps/cdata_begin.swg`. And `typemaps/cdata.swg` to `typemaps/cdata.swg`. Move `cdata_apply.swg` content to `typemaps/cdata.swg`.
Group the C# marshalling of STRING-LENGTH typemap into C# class named SWIGStringWithLengthHelper.
Leave Length & string reverse order typemap in typemaps/strings.swg
Support old C# as "LPUTF8Str" was add in 2017.
Improve documentation. Follow @wsfulton reviews.
Use a dummy for MzScheme and untested OCaml cdate. To prevent compilation error.
Further fixing follow reviews.
Reorganise raw data typemap, so typemaps folder contain only common part. Improve document.
Inline SWIG_string_to_utf8_bytes SWIG_utf8_bytes_to_string code
Fixes of STRING/BYTES LENGTH typemaps.
Conflicts:
CHANGES.current
And `typemaps/cdata.swg` to `typemaps/cdata.swg`.
Move `cdata_apply.swg` content to `typemaps/cdata.swg`.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
Removes warning 472:
./../cpp11_move_only.i:78: Warning 472: Overloaded method ConstructorTester::ConstructorTester(MovableCopyable) with no explicit typecheck typemap for arg 0 of type 'MoveOnly'
./../cpp11_move_only.i:78: Warning 472: Dispatching calls to this method may not work correctly, see the 'Typemaps and Overloading' section in Typemaps chapter of the documentation
Fix Java STRING LENGTH typemap.
Use string type in static typed languages (Java, C#, D and Go).
Add BYTES LENGTH typemap and apply it for binary data.
Use byte type in static typed languages.
Add li_cdata_cpp, li_cdata and char_binary
tests for most of languages(apart from R and experimental).
Fix the director_binary_string test and add it to C#, D, Go,
Perl, PHP, Python, Ruby and octave.
Update documents.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
Order of evaluation of C++ function arguments is not defined, and if
lua_rawlen() was called before lua_tostring() then it would return 0
(because the value was still a number) and an empty string would be
passed.
The same issue affects std::string_view too, but that's not been in
a release yet.
The new testcases fail without the fix with GCC 12.2 on x86-64 Linux.
SWIG_LUA_CONSTTAB_INT can be called with a constant expression
containing commas (e.g. `SizeOf< int,int >::size`). This was
addressed in b13f584258 by making
its second argument variadic, but (a) this doesn't work with
our baseline of C90/C++98 and (b) the variadic syntax used is
a GCC extension which doesn't work with all compilers (e.g. MSVC).
We can solve this without needing variadic macros by simply wrapping
this argument in an extra pair of parentheses when calling.
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.
Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this
Closes#1050
Ensure that SWIG_VERSION is defined both at SWIG-time and in the
generated C/C++ wrapper code (it was only defined in the wrapper
for some target languages previously).
SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers
to match behaviour for all other target languages.
Stop defining SWIGVERSION in the wrapper. This only happened as a
side-effect of how SWIG_VERSION was defined but was never documented and
is redundant.
The new testcase also checks that SWIG is defined at SWIG-time but not
in the generated wrapper, and that exactly one of a list of
target-language specific macros is defined.
Fixes#1050
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.
Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).
Issue #999
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 #999Closes#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.