Skip to content

Commit

Permalink
Fix to manual again
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Apr 21, 2023
1 parent 40fdb2a commit d332368
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ luabridge::getGlobalNamespace (L)
.endClass ()
.endNamespace ();

FlexibleExtensibleClassClass clazz;
ExtensibleClass clazz;
luabridge::pushGlobal (L, &clazz, "clazz");
```
Expand All @@ -763,6 +763,36 @@ end
print (clazz:newMethod(), ExtensibleClass.newStaticMethod())
```

This way extending an already existing method will raise a lua error when trying to do so. To be able to override existing methods, pass `luabridge::allowOverridingMethods` together with `luabridge::extensibleClass`.

```cpp
struct ExtensibleClass
{
int existingMethod() { return 42; }
};

luabridge::getGlobalNamespace (L)
.beginNamespace ("test")
.beginClass<ExtensibleClass> ("ExtensibleClass", luabridge::extensibleClass | luabridge::allowOverridingMethods)
.addFunction ("existingMethod", &ExtensibleClass::existingMethod)
.endClass ()
.endNamespace ();

ExtensibleClass clazz;
luabridge::pushGlobal (L, &clazz, "clazz");
```
```lua
function ExtensibleClass:existingMethod()
return "this has been replaced"
end
print (clazz:existingMethod())
```




In case storing instance properties is needed, storage needs to be provided per instance. See the next chapter for an explanation on how to add custom properties per instance.

### 2.7.2 - Index and New Index Metamethods Fallback
Expand Down

0 comments on commit d332368

Please sign in to comment.