lua-users home
lua-l archive

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


2009/11/23 spir <denis.spir@free.fr>:
> Hello,
>
> I'm looking for a straightforward way to define what a module exports -- other than setting all the rest global. Ideally, this would be something like:
>
> -- module mod
> require("mod_test")
> __export = {CONST=CONST, config=start_config, test=mod_test.test, do=safe_do}
>
> CONST = 3.14
> start_config = {...}
> do = function(...) ... end
> safe_do = function(...) ... do(...) ... end
>
> Then, as you guess, requiring "mod" would export only the content of __export.
> Is there method analog to this?
>

At the bottom of the file put "return __export", it will be used as
the return value from require, and saved in package.loaded[modulename]
for future calls.

Matthew