Commit Graph

5 Commits

Author SHA1 Message Date
William S Fulton 294c944c10 [Lua] Restore Lua 5.1 and LuaJIT compatibility for non-director wrapping
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)
2026-07-14 20:15:39 +01:00
Erez Geva d483ae428b
Improve Lua test syntax (#3463)
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-06-01 23:23:41 +01:00
Erez Geva 74ff929bd4 Remove Lua 5.0 and Lua 5.1 and Lua options
- 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>
2026-05-30 17:24:17 +01:00
William S Fulton 0c291fa448 Fix one-byte buffer overflow in cdata.i memmove
The cdata.i (const void *BYTES, size_t LENGTH) typemap took LENGTH from
SWIG_AsCharPtrAndSize, whose psize includes a trailing NUL (data length
+ 1). When the destination buffer is sized exactly to the data, memmove
wrote one byte past the end. Confirmed with valgrind: "Invalid write of
size 1, 0 bytes after a block of size 512".

- Make SWIG_AsCharPtrAndSize binary aware in the languages that use the
  generic Lib/cdata.i (Python, Perl, Ruby, Octave, R): when the caller
  passes SWIG_BINARYSTR it now reports the exact byte count, not data
  + 1. Non cdata callers are unaffected as they never set the flag.
- Lua li_cdata_bytes tests looped to 0x99 instead of 0xff, verifying
  only 154 of the 256 byte values; corrected to 0xff.
- Tcl cdata.i passed an int * to Tcl_GetSizeIntFromObj, which expects
  a Tcl_Size * on Tcl 8.7 and 9; use Tcl_Size and reject values that
  are not a byte.
- CHANGES.current: document the cdata type change and the overflow fix.

Assisted-by: Claude Opus 4.7
2026-05-25 13:17:15 +01:00
Erez Geva cd569d122a cdata.i changes and new test li_cdata_bytes
Fix guile cdata.

Add SWIG_BINSTR flag
- Add SWIG_FromBinCharPtrAndSize with the new flag
  To add languages that use Lib/cdata.i.
- python use binary string by using the new SWIG_BINSTR
  in SWIG_AsCharPtrAndSize and SWIG_FromBinCharPtrAndSize.

Languages that were changed to uses list
- Tcl use list of integers.
- scilab use list of uint8.
  And support passing list of numbers to C.

Add support to JavaScript
- use Uint8Array instead of strings.
- Add li_cdata_carrays. tests.
- Add li_cdata_bytes tests.
- Use Debian node-addon-api package location.
- napi folder location to Examples/test-suite/javascript/Makefile.in.
- Update documentation.

Update cdata.i documentation

This new cdata test focus on:
- Ensure we can receive proper data from C and pass proper data back to C.
- Use all possoble byte values , i.e. the full range of 0 to 255
  and ensure values 128 to 255 do not pass Unicode transformation (UTF-8/16).
- Ensure zero is a valid value and not a string null termination
  nor a modified UTF-8 which transform U+0000 to 0xC0 0x80.
- Check mutability of the cdata object.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-05-25 13:16:09 +01:00