lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2014-03-26 9:33 GMT+00:00 Michal Lisičan <>:
> i have 3 files x.lua, y.lua and main.lua. These files doing some mathematics
> operations (increment and decrement). If i use command for run:
> lua main.lua - it is very fast
> but when i delete all requires from main.lua and use commands for compiling:
> luac -o main.out -s x.lua y.lua main.lua
> and command for run:
> lua main.out - this is very slow
> please can you help me why second example is slow than first and how to
> remove this slowdown? Or how to create bytecode from multiple files without
> losing speed

You need to wrap your modules (x and y, not main) so that when they
are executed in the bytecode file, they are not run normally, but only
prepared. To do that, you need to add a line at the beginning of x.lua
and a line at the end:

package.preload.x = function(...)
<<<put your module code here>>>

Of course change preload.x to preload.y for file y.lua. Now the
modules body won't be executed (only compiled) until main.lua calls