MV_INLINE: more better limitations expressed
This commit is contained in:
@@ -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 <var> = 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
|
||||
|
Reference in New Issue
Block a user