[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Problem with compiled modules
- From: Duncan Cross <duncan.cross@...>
- Date: Thu, 2 Dec 2010 11:40:53 +0000
2010/12/2 "J.Jørgen von Bargen" <jjvb.primus@gmx.de>:
> ==== sub/mod.lua ====
> module("sub.mod")
> local M={}
> M._VERSION="0.1"
> function M.Function()
> return "Result"
> end
> return M
> =================
You are creating and returning the M table yourself, but also calling
module(). Because of this, you are getting different effects based on
whether sub/mod.lua is being run inside the context of a require()
call (when you call 'lua main'), or if it is being run as a
freestanding script (when you execute the output of luac). In the
context of require(), the 'sub.mod' module takes the value of the
return value M, but run as a freestanding script, the return value is
ignored and the 'sub.mod' module is the table created by
module("sub.mod").
So, you either need to use the environment table created by module():
==== alternate sub/mod.lua #1 ====
module("sub.mod")
_VERSION="0.1"
function Function()
return "Result"
end
=================
...or you can avoid using module() altogether but you will need to
manually set package.loaded["sub.mod"]:
==== alternate sub/mod.lua #2 ====
local M={}
package.loaded["sub.mod"] = M
M._VERSION="0.1"
function M.Function()
return "Result"
end
return M
=================
-Duncan