From ca94e59b534b86712eeeb5e4a3c60d4277f3eda1 Mon Sep 17 00:00:00 2001 From: cpunch Date: Mon, 13 Oct 2025 01:41:44 -0600 Subject: [PATCH] MV_INLINE: more better limitations expressed --- content/docs/macros/MV_INLINE.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/content/docs/macros/MV_INLINE.md b/content/docs/macros/MV_INLINE.md index 4162eef..f7c4175 100644 --- a/content/docs/macros/MV_INLINE.md +++ b/content/docs/macros/MV_INLINE.md @@ -16,6 +16,23 @@ Some limitations apply: - The passed function cannot tailcall or otherwise recursively call itself. - You must use this macro in it's specific form, i.e. `local = MV_INLINE(function() ... end)` +Note that this pass acts more like a preprocessor that replaces the function calls with the results of the function (if any), and can have strange effects in some cases. + +For example, when an inlined function is called, its function body is inserted right before the statement the call is in. This can lead to some unexpected behavior when used in `or` or `if` expressions: + +```lua +local called = false +local testFunc = MV_INLINE(function() + called = true + return 'hi' +end) + +local foo = 'bar' or testFunc() +print(foo, called) +``` + +Will print `bar true`, where under normal circumstances testFunc should not be executed. This is because the `or` expression is evaluated after the inserted body. + ## Valid Usage ```lua