Metatable Metamethods Fixes + Customization

Description

Were you, like me, angry that certain metatable metamethods just... Didn't work!??! Well, here's MY solution for you!

It's important that you DON'T modify the .__metatable parameter - as the mod requires it for indexing custom parameters

Mods you wish to be modified by this - must have metatable_metamethods specified in depends or optional_depends - or else this will likely load AFTER the mod

I modify certain functions as well as providing one, to permit the invocation of 3 metamethods:

.__pairs(tbl)

.__ipairs(tbl)

.__len(tbl) - with the provided length function (which permits any table, string, or vector if MT 5.5+)

Adds a new 4th metamethod:

.__setmetatable(table, metatable) - return false to prevent table metatable overwrite, return table for a custom setmetatable return. Return anything else to proceed with normal overwrite

This may hypothetically be laggier, since it's an implementation through Lua - but I personally didn't notice much lag. But then again I come with LuaJIT so who knows.

Related to https://github.com/luanti-org/luanti/issues/15133 and https://github.com/luanti-org/luanti/pull/1277

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.

Releases

1.1

Download

Luanti 5.0+

2025-08-18 16:36 UTC

`setmetatable` functionality, misc API changes 🔗

Fixes pairs permitting a key argument (it shouldn't)

Removes vector:length() from length function

Modifies setmetatable function to permit a new custom .__setmetatable(table, metatable) metamethod

1.0

Download

Luanti 5.0+

2025-08-16 12:42 UTC

1.0 - Initialization 🔗

Modifies ipairs and pairs to invoke .__ipairs(tbl) and .__pairs(tbl)

Adds length function to invoke .__len(tbl) and get the length of strings, other tables, and vectors (5.5+)

All releases

Information

Provides

metatable_metamethods

Dependencies

Required
No required dependencies

Information

Type
Mod
Technical Name
metatable_metamethods
Languages
English
License
MIT
Maintenance State
Actively Developed
Added
2025-08-16 12:41 UTC
Maintainers
TPH

Used By