From 0a14bc975e3bcc31356f4ca6f2167965cd81470e Mon Sep 17 00:00:00 2001 From: cpunch Date: Tue, 19 Aug 2025 13:23:41 -0500 Subject: [PATCH] added MV_INLINE --- content/docs/macros/MV_INLINE.md | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 content/docs/macros/MV_INLINE.md diff --git a/content/docs/macros/MV_INLINE.md b/content/docs/macros/MV_INLINE.md new file mode 100644 index 0000000..2458283 --- /dev/null +++ b/content/docs/macros/MV_INLINE.md @@ -0,0 +1,83 @@ +--- +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(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 = 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])) +``` \ No newline at end of file