DumbLuaParser
DumbLuaParser copied to clipboard
Suggestion for optimize function
replaces calls to global functions with calls to local functions and generates a single line of local variable assignments at the top
so something like :
local function doSomething(s)
s = string.rep(s, 100)
print(s)
end
turns into
local string_rep, pring = string.rep, print
local function doSomething(s)
s = string_rep(s, 100)
print(s)
end
Since this would change the functionality of the code (e.g. prevent dynamic monkey-patching) it's not really fit for the general optimization function, but since this is pretty common to do in Lua I might add an example or code snippet or something that attempts to do this. There are many things to consider though, like functions inside functions. It's also pretty common to put global values used in loops into local variables right before the loop in performance-critical code.