83 lines
1.5 KiB
Markdown
83 lines
1.5 KiB
Markdown
---
|
|
weight: 100
|
|
title: "MV_INLINE"
|
|
description: "Make preprocessor macros"
|
|
icon: "code_blocks"
|
|
date: "2025-05-01T18:47:58-05:00"
|
|
lastmod: "2025-05-01T18:47:58-05:00"
|
|
---
|
|
|
|
`declare function MV_INLINE<A..., R...>(inlineFunction: (A...) -> R...): (A...) -> R...`
|
|
|
|
will mark the passed function to be inlined where used.
|
|
|
|
Some limitations apply:
|
|
- The passed function cannot be variadic (i.e. no ... usage)
|
|
- 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)`
|
|
|
|
## Valid Usage
|
|
|
|
```lua
|
|
local testFunc = MV_INLINE(function(start, endn)
|
|
local total = 0
|
|
for i = start, endn do
|
|
total = total + i
|
|
end
|
|
return total
|
|
end)
|
|
|
|
local testFunc2 = MV_INLINE(function()
|
|
return testFunc(1, 10), testFunc(11, 20), testFunc(1, 10)
|
|
end)
|
|
|
|
print(testFunc2())
|
|
```
|
|
|
|
turns into:
|
|
|
|
```lua
|
|
...
|
|
local i=l(nil)
|
|
repeat
|
|
local b=l(nil)
|
|
repeat
|
|
local f=0
|
|
for o=1,10 do
|
|
f=f+o
|
|
end
|
|
do
|
|
b=l(f)
|
|
break
|
|
end
|
|
until true
|
|
local n=l(nil)
|
|
repeat
|
|
local a=0
|
|
for e=11,20 do
|
|
a=a+e
|
|
end
|
|
do
|
|
n=l(a)
|
|
break
|
|
end
|
|
until true
|
|
local h=l(nil)
|
|
repeat
|
|
local k=0
|
|
for q=1,10 do
|
|
k=k+q
|
|
end
|
|
do
|
|
h=l(k)
|
|
break
|
|
end
|
|
until true
|
|
do
|
|
i=l(j(b[1],1,b[2]),j(n[1],1,n[2]),j(h[1],1,h[2]))
|
|
break
|
|
end
|
|
until true;
|
|
|
|
print(j(i[1],1,i[2]))
|
|
``` |