You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e2ce77e
Browse filesBrowse the repository at this point in the historyBrowse files
It also works with member function pointers, where the bound object is not counted as a Lua-visible parameter:
625
+
It also works with member function pointers. The bound object is not counted as a Lua-visible parameter, so `bind_front` turns a member function into a plain callable that Lua sees as a regular function:
ns.addFunction ("addBase", luabridge::bind_front ([base](int offset, int v) { return base + offset + v; }, 2));
641
+
// Lua: addBase(30) == 42
642
+
```
643
+
644
+
### 2.5.2 - Partial Application with luabridge::bind_back
645
+
646
+
`luabridge::bind_back` is the trailing-argument counterpart to `bind_front`: it pre-binds the **last** arguments of a callable, leaving the **leading** arguments for Lua to supply.
647
+
648
+
```cpp
649
+
intadd (int a, int b) { return a + b; }
650
+
651
+
// bind_back fixes the trailing argument; Lua supplies the leading one
For member function pointers, `bind_back` automatically prepends the class pointer to the remaining (Lua-visible) parameter list so that LuaBridge can dispatch it as a proxy function. This lets you pre-bind a method's trailing arguments while the object still comes from Lua:
// Lua: v:x() returns v.coord[0], v:y() returns v.coord[1], etc.
667
+
```
668
+
669
+
`bind_back` also accepts lambdas:
670
+
671
+
```cpp
672
+
int base = 10;
673
+
ns.addFunction ("addBase", luabridge::bind_back ([base](int v, int offset) { return base + offset + v; }, 2));
674
+
// Lua: addBase(30) == 42
635
675
```
636
676
637
-
### 2.5.2 - Function Overloading
677
+
### 2.5.3 - Function Overloading
638
678
639
679
When specifying more than one method to the `addFunction` or `addStaticFunction` of both `Namespace` and `Class`, those overloads will be invoked in case of a call. Only overloads that have matched arguments arity will be considered, and they will be tried from first to last until the call succeeds.
0 commit comments