Commit graph

72 commits

Author SHA1 Message Date
Robin Gareus
0fd67d36d9
Fix adding C++ class instances to Lua STL containers
This is because Userdata::getClass() doesn't handle
negative stack indexes. It worked fine for Lua built-in types.
2025-11-09 03:48:39 +01:00
Robin Gareus
7b74faaf57
Tidy up libs/lua/LuaBridge/detail/Userdata.h 2024-10-19 18:38:59 +02:00
Alejandro Domínguez
e326426dbc
Replace boost type traits with std version 2024-10-19 01:04:14 +02:00
Mads Kiilerich
0352ff8c5e
warnings: Remove redundant/illegal/undefined-behaviour template-id for constructor
GCC 14 educates us:

	In file included from ../libs/ardour/ardour/io.h:44,
									 from ../libs/ardour/ardour/route.h:50,
									 from ../libs/ardour/ardour/session.h:92,
									 from ../libs/ctrl-interface/midi_surface/midi_surface.cc:30:
	../libs/ardour/ardour/port_set.h:92:37: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
		 92 |                 iterator_base<PS,P>(PS& list, DataType type, size_t index)
				|                                     ^~
	../libs/ardour/ardour/port_set.h:92:37: note: remove the ‘< >’
2024-07-24 01:50:11 +02:00
Robin Gareus
f2c5f9da25
Lua: allow to reserve STL vector size 2023-07-12 18:23:51 +02:00
Robin Gareus
5bbd248384
Add Lua bindings for std::list/vector clear 2023-05-13 17:38:41 +02:00
Robin Gareus
7094c82e75
Add Lua bindings to std::shared_ptr<T const>
This is required after the recent RCU change to return
const shared pointers for read (295dbd8e1).
2023-04-19 01:46:58 +02:00
Robin Gareus
dbc3008163
Add Lua Bindings for const shared_ptr lists (295dbd8e1e) 2023-04-12 20:47:35 +02:00
Paul Davis
b35518e212 switch from boost::{shared,weak}_ptr to std::{shared,weak}_ptr
This is mostly a simple lexical search+replace but the absence of operator< for
std::weak_ptr<T> leads to some complications, particularly with Evoral::Sequence
and ExportPortChannel.
2023-03-24 14:19:15 -06:00
Paul Davis
39ed528e25 std-ize: convert all boost shared/weak ptr includes to <memory>
Also fix stdint.h -> cstdint and alphabetically order std includes
2023-03-24 14:19:15 -06:00
Robin Gareus
9914732004
Potential fix for C++20 std::set::* ambiguity
(until C++20) bool empty() const noexcept;
(since C++20) [[nodiscard]] bool empty() const noexcept;
2022-10-19 16:06:47 +02:00
Robin Gareus
46b14498f8
Prepare Lua bindings for std::set::insert 2022-10-17 23:09:04 +02:00
Robin Gareus
e98fe4729e
LuaBridge - add API to try convert a value
This in in preparation to overload operators
2022-09-26 21:39:21 +02:00
Raphael Isemann
3dfcbf17b2
Fix memory leak in ctorNilPtrPlacementProxy 2022-04-08 18:21:55 +02:00
Robin Gareus
d51a1ccd99
Add API to modify Lua Metatable and set Metamethods
This allows to map C++ operators to be used as Lua
arithmetic and relational operations.
2022-01-24 06:23:16 +01:00
Robin Gareus
1c0593201c
Allow Lua bindings up to 12 method arguments 2021-12-03 13:32:49 +01:00
Robin Gareus
115c79874a
Fix Lua bindings for C++17/C++20 -- #8683
std::list/vector/map declarations change, requiring
explicit cast to avoid FuncTraits ambiguities.
2021-05-02 16:36:30 +02:00
John Emmas
b625461132 Guard some code which isn't currently buildable with VS2019
For some unknown reason, VC++2019 won't let us take the address of std::list::unique() - although other std::list members seem okay. I've spent weeks tracking this down but there's no fix available AFAICT.

I've flagged it up to the MSVC development team - just don't hold your breath !!
2021-03-06 11:12:02 +00:00
Robin Gareus
038307fef6
Allow Lua bindings up to 11 args 2021-01-08 22:50:37 +01:00
Robin Gareus
7c6eadd84a
Fix some doxygen warnings 2020-03-02 17:58:03 +01:00
Robin Gareus
34c4602e61
Lua Array, assert indices > 0 2020-02-06 17:30:21 +01:00
Robin Gareus
fbacb13d2d
Extend Lua binding for static methods
This add support for Lua bindings for static member
functions in weak/share ptr class bindings.
2020-02-06 17:30:21 +01:00
Robin Gareus
5e1a73a28c
Add Lua typecast from C++ vector to C-Array
This is useful for MIDI bytes amongst other things
2019-12-01 21:32:10 +01:00
Robin Gareus
bed2eb2e33
Fix std::list<hared_ptr<>> front/back methods
Shared pointer reference accessors can't be const
2019-05-17 12:09:07 +02:00
Robin Gareus
3da07e6736
Special case Lua copy-construction of trackable instances
This fixes an crashing issue with ArdourUI.SelectionList a bug
introduced in 6dc3bdf252 and 35dcd46d7d.

Since removal of the special cases in 35dcd46d7d, when using
a C-pointer in a std::list<>,
  std::list<class*>::push_back(TypeListValue)
TypeListValues<>'s Head was expanded to  "class*& const"
implied by void ::push_back(const T& value);

This resulted in lifetime issues with a classes that derive
from sigc::trackable (e.g. Ardour's Selection).
The reference leaves scope and isn't duplicated when it is pushed back
to the std::list<>.

The script scripts/select_every_2nd_region.lua crashed because entries
in the SelectionList were no longer valid.

Previously (before 6dc3bdf252) TypeListValues explicitly
copy-constructed the value to work around the lifetime issue.
This new solution bypasses the issue by directly using the c-pointer
without dereferencing it.
2019-04-12 05:45:27 +02:00
Robin Gareus
e951e68780 Add luaRef is Boolean 2017-08-18 20:42:55 +02:00
Robin Gareus
ea8c6e9fc8 Fix hiding Lua __metatable -- prevent setmetatable() override 2017-03-30 05:06:34 +02:00
Robin Gareus
412b6a4cb9 Lua: make external (static) functions available for const objects.
This fixes iterators on const std::lists<>& and const std::map<>&
2017-03-30 04:15:28 +02:00
Robin Gareus
4a180e68ba Special case const std::string& Lua binding.
since 6dc3bdf, a const string reference would leave scope with Lua code
     fn("text")
calling a C++
     fn (const std::string&)
before the C++ function is called.
2017-03-22 16:59:02 +01:00
Robin Gareus
35dcd46d7d remove cruft (following 6dc3bdf) 2017-03-22 16:55:19 +01:00
Robin Gareus
6dc3bdf252 Fix LuaBindings TypeList copy-ctor
Determining the class type copy constructed references.
Const-references passed to C++ functions were copies.
2017-03-18 18:30:51 +01:00
Robin Gareus
bc300ddab7 Make Lua std::set bindings more generic, (prepare for multiset etc) 2017-03-18 14:35:29 +01:00
Robin Gareus
51d43c6e14 drop lua documentation for deprecated "sameinstance()" 2017-03-16 20:56:32 +01:00
Robin Gareus
a2094b6831 Lua: provide instance-equal check as '==' comparator.
This deprecated explicit the "sameinstance()" method
2017-03-16 20:08:17 +01:00
Robin Gareus
71fd94b422 LuaBridge: Dedicated type for pointer-lists and const version
"class C*" cannot be defined nor resolved, so STL containers
to class instance pointers need to be special-cased.
2017-02-23 22:32:32 +01:00
Robin Gareus
37dc93b40a luaBridge support const references to class-instance pointers
Support passing "T*" as as "const T* &"  argument
e.g. std::list<T*>::push_back ( const T* & )
2017-02-23 22:32:32 +01:00
Robin Gareus
226b2a526e Add Lua bindings for std::list ::front() and ::back() 2017-02-20 00:30:15 +01:00
Robin Gareus
659701c59b Fix lua-doc (Null pointer c'tor doc) 2017-02-14 14:44:22 +01:00
Robin Gareus
6f7f527e1d Lua add an Empty/Nil shared-pointer constructor 2017-01-21 20:18:27 +01:00
Robin Gareus
d0b42aee0e LuaBindings: prefer shared_ptr over weak_ptr 2017-01-21 20:18:27 +01:00
Robin Gareus
b25cd7683b Allow Lua bindings up to 10 args 2017-01-20 21:23:05 +01:00
Robin Gareus
134b69f267 Fix shared-pointer list creation from Lua 2017-01-08 00:30:41 +01:00
Robin Gareus
86bfe4eff6 Lua binding for std::map<>::at() 2016-10-07 03:39:22 +02:00
Robin Gareus
c64b8662a6 fix copy/paste typo in 1d7c14496 2016-08-27 15:53:38 +02:00
Robin Gareus
a4da0747e1 allow to access data-members in weak/shared ptr classes 2016-08-26 19:01:09 +02:00
Robin Gareus
1d7c144967 add "sameinstance()" lua binding for all shared/weak ptrs 2016-08-26 18:25:15 +02:00
Robin Gareus
bc0bb6cae9 extend lua-doc to show properties 2016-08-16 00:25:59 +02:00
Robin Gareus
3b7dbdfeb8 Re-enable luabridge addProperty()
In preparation to expose ARDOUR::SessionConfiguration.
Also change the return-type to bool to match Ardour's set/get API
2016-08-15 22:25:56 +02:00
Robin Gareus
520dcf8cdf rework lua-bridge C++ variable references
Since lua functions are closures, C++ methods that pass arguments by
reference cannot be used directly. The previous approach (boost::ref)
failed with clang. Assume the following:

  void foo (float&) { }
  static inline float& bar () {
    boost::reference_wrapper<float> r (42);
    return r.get ();
  }

  foo ( bar () );

With gcc, "r" goes out of scope after foo's arguments are processed
and all is well.
But with clang,  "r" already leave scope when *inlined* bar() returns.

Solution: allocate some user-data on the lua-stack to hold the reference.
There is no reference to this user-data so lua will eventually
garbage collect it.

(theoretically, creating the table which holds the return-values
could trigger an emergency garbage collection when memory is low and
free the reference just while they're being pushed to the table, then
gain FuncArgs<Params> already dereferenced them all as variable on the
C stack -- probably again compiler specific)
2016-07-18 23:52:40 +02:00
Robin Gareus
44a3f042a7 prepare sharing C++ class instances across lua-interpreters
in particular: lua-lifefime (!) C++ instances.
This allows for dynamic allocation of custom user-data, bound to
the lifetime of the allocating lua-context.
2016-07-07 15:37:11 +02:00