lua-users home
lua-l archive

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


Hi,

It was difficult to me to understand how that work ...
this web page helped me: http://www.keplerproject.org/compat/
And that post also: http://lua-users.org/lists/lua-l/2004-09/msg00342.html

when you type:
mMyModule = require("modname")

require searches:
- try to execute function in package.preload.modname
- try to load modname.lua with pachage.path (LUA_PATH)
- try to load modname.so/dll with pachage.cpath (LUA_CPATH)

The result is placed in package.loaded.modname and returnd (in mMyModule)
I don't know what is the result of loading lua file ... maybe with
return statement even if it seems weird to me
The first argument is the module name

In the beginning of you lua module file you can place:
module("modname", package.seeall)

package.seeall if you want to have access to all global lua function
such as print() ...
all global variables/functions declared after module() will be inserted
in the module
local variables/functions won't be acessible outside of the module
module("modname") will place all that stuf in global table modname and
will also place it in package.loaded.modname. So require() will use it
directly.

Something I found ... If you don't want to create global variable
modname (because you don't like global variables so much) you can call:
module("package.loaded.modname")
Then when you call:
local mModName = require("modname")
no global modname variable will be created and the module can be acessed
in the local table mModName


Am I wrong ?
even If I mae some tests I'm not shure of that ... please tell me

now I verified evrything ... corrected some little mestakes, hope it's ok.

Mildred

-- 
<http://louve.dyndns.org> ou <http://mildred632.free.fr>
Le courrier E-mail est une correspondance privée. Merci de vous y conformer

Attachment: signature.asc
Description: OpenPGP digital signature