lua-users home
lua-l archive

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

It took me a while to figure this out also, but to create a module I do this:

module "mod";
method = function ()

Then in another script:

require "mod";
mod.method ();

>From what I understand, after a call to module the current environment gets replaced with a new table.  This table is what is returned by require.  To keep the old environment visible after a call to module, you use the seeall function:

module ("mod", module.seeall);
method = function ()
     print ("hello world"); --print would otherwise not be in this environment!

-----Original Message-----
From: on behalf of Jeff Sheets
Sent: Sun 1/15/2006 1:25 PM
Subject: How to use module()
Though I see in the manual what the module function does, I'm wondering 
how one uses it properly.

I am assuming it is intended to be used at the beginning of a module lua 
file, which is intended to be required into another lua file.  Am I 

Also, when are the functions given as extra parameters to module() 
executed, and what environment do they have before execution?