lua-users home
lua-l archive

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


Hi all,

I am trying to use "luac" to build a bytecode file
which should be independent of the original
source files (I am using lua-5.1-beta).
My original approach was the following:

   file main.lua:
      require("mod")
      print(mod.f1())

   file mod.lua:
      local function f1()
        return "f1"
      end
      mod = {f1 = f1}
      return mod

   luac mod.lua main.lua
   lua  luac.out

It doesn't work without the original source files.
lua complains that module "mod" was not found.
My second approach was the following:

   file main.lua:
      require("mod")
      print(mod.f1())

   file mod.lua:
      local function f1()
        return "f1"
      end
      mod = {f1 = f1}
      module("mod")  <------ NEW
      return mod

   luac mod.lua main.lua
   lua  luac.out

Now it works without the original source files.
I have the following questions:

1. Is this the "right" approach ?
2. I understand that the order of the files passed
   to "luac" will be the order they will be executed
   by "lua", so if I have a project with several modules,
   with some modules depending on others I will have to
   specify the order correctly so a module which depends
   on another should be listed after.
   Is this correct ?


Thanks,
Claudio Leonel