lua-users home
lua-l archive

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


Put this function at the top of your main module file:

module("modname", package.seeall)

function include(fname)
    local f = assert(loadfile(fname))
    setfenv(f, getfenv(1))
    f()
end

now you can use

include("part1.lua")
include("part2.lua")

to include components. Note: 'local' functions and variables will not be visible outside of individual files, but
you can build a module from multiple source files, and recursively include files.

If you do not need to use recursive 'include' calls make 'include' a local function.



On Mar 6, 2007, at 12:17 PM, Norman Ramsey wrote:

I'm building a fairly large package consisting of a mix of C code and
Lua code.  Following previous advice I've made the C code a submodule,
which is working well.  But this is going to be a large package (probably
2000-3000 lines of Lua code), and while there are several well-defined
submodules in the package, some of the submodules (such as the module
containing all the package-specific commands intended for clients) are
too large to put in one file.  So, I would like to have multiple
files, each loaded with 'require', that all contribute to the same
submodule.

Does anyone have advice about sensible ways to do this?
(I have several ideas but feel I am treading on thin ice...)


Norman



--
Gé Weijers