Can you explicitly ask the Lua compiler to inline? What about the LuaJIT?

801 Views Asked by At

Is there a keyword or some other functionality in the standard Lua compiler that allows you to explicitly inline? What about the LuaJIT?

2

There are 2 best solutions below

0
On BEST ANSWER

There is no function inlining in vanilla Lua interpreter. Some tools exist to inline the code on a source level, but that's not what you're asking.

LuaJIT does some inlining while generating the native code, but that can't be controlled from outside, there's no explicit 'inline' keyword. And there's limits on what could be inlined. I.e. the call to native code using FFI library will be inlined, but the calls to functions registered via classic Lua/C interface can't be.

0
On

No.

It could only apply to functions that aren't closures, though. (It doesn't seem worth it to have some other way to implement closures; because where would the time savings be?)

In some cases, a tail-call would give more of an advantage, particularly if your concern is stack space.