lua-users home
lua-l archive

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


>this file i's build like this
>
>luac -o files.dat prog1.lua prog2.lua prog3.lua
>
>What I'm trying to do is to call, say, "prog2.lua", that it's in "files.dat".
>
>It's that possible?

No, because when you compile 3 Lua files together, luac fixes things so that
when you run the precompiled code it executes all three files.

Try luac -l prog1.lua prog2.lua prog3.lua and see the main function.

Now, there is no real reason for this being as it is. It's just the simplest
thing that is compatible with the old idea of dofile, before the loadfile days.
If someone can argue that having different options for luac to select what to
do in the created main, it can be done, but I don't think it'll be easy to come
up with something simple that is consistent with the case of 1 file.

Right now, luac prog1.lua prog2.lua prog3.lua generates a main that is
equivalent to

	dofile"prog1.lua"
	dofile"prog2.lua"
	dofile"prog3.lua"

except that dofile is not called at all.

Note for instance that this ignores any values returned by the chunks. Like
I said, it is easy to implement different mains, but it'll not be easy to
do it consistently with the 1-file case.
--lhf