2025-08-19 13:23:41 -05:00

1.5 KiB

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

print(testFunc2())

turns into:

...
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]))