Files
MoonVeil-Docs/content/docs/macros/MV_INLINE.md
2025-09-09 19:37:27 -05:00

1.5 KiB

weight, title, description, icon, date, lastmod
weight title description icon date lastmod
100 MV_INLINE Make preprocessor macros code_blocks 2025-05-01T18:47:58-05:00 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

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, 15)
end)

print(testFunc2())

turns into:

...
local b=o(nil)
repeat
    local j=nil
    repeat
        local c=0
        for e=1,10 do
            c=c+e
        end
        do
            j=c
            break
        end
    until true
    local a=nil
    repeat
        local f=0
        for g=11,20 do
            f=f+g
        end
        do
            a=f
            break
        end
    until true
    local p=nil
    repeat
        local l=0
        for i=1,15 do
            l=l+i
        end
        do
            p=l
            break
        end
    until true
    do
        b=o(j,a,p)
        break
    end
until true;

print(m(b[1],1,b[2]))