lua-users home
lua-l archive

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


> 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

Just my own thoughts...

I think that by definition what is being requested is inconsistent with the
standard 1-file case.  I think the most flexible option would be to pass all
of the resulting chunks to one particular lua file (along with the
filenames).  Personally, I would pass the resulting chunks in one table and
the names in another (and names could be matched to chunks through
ordering).

Here is an example of such a call

luac -o MyOutput.luac -M MyMain.lua prog1.lua prog2.lua prog3.lua


The effective "default" implementation of such a "main" file could be
(assuming arg[1] is the table of chunks) ....

   table.foreachi(arg[1], function (i,f) do f(); return; end)
   return


An implementation that destroyed the ordering information, and returned a
table mapping from name to chunk could be....

   local RetTable = {}
   local Names = arg[2]

   table.foreachi(arg[1], function (i, f) do RetTable[Names[i]] = f; return;
end)
   return RetTable



And here is a representation of what would (effectively) be in the output
file...

   local Funcs = {loadfile("prog1.lua"), loadfile("prog2.lua"),
loadfile("prog3.lua")}
   local Names = {"prog1.lua", "prog2.lua", "prog3.lua"}
   local Main = loadfile("MyMain.lua")

   return Main(Funcs, Names)