Skip to content

Instantly share code, notes, and snippets.

@NicolBolas
Created May 20, 2019 15:11
Show Gist options
  • Save NicolBolas/79310803c8008774a37c4ab6d0d200f0 to your computer and use it in GitHub Desktop.
Save NicolBolas/79310803c8008774a37c4ab6d0d200f0 to your computer and use it in GitHub Desktop.
Lua precompiled concatenation test
local chunk1 = [[
foo = 12
]]
local chunk2 = [[
foo = 0
]]
chunk1 = loadstring(chunk1)
chunk2 = loadstring(chunk2)
local dumps =
{
string.dump(chunk1),
string.dump(chunk2),
}
--Put both chunks in one `load` call.
local function getDumper()
local count = 1
return function()
print(count)
local ret = dumps[count]
count = count + 1
return ret
end
end
local main = load(getDumper())
print(foo)
main()
print(foo)
chunk2()
print(foo)
foo = nil
--Concatenate chunks for a single `loadstring` call.
local single_dump = table.concat(dumps)
main = loadstring(single_dump)
print(foo)
main()
print(foo)
chunk2()
print(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment