Hello, I just want to share a link to this article:
http://lua-users.org/wiki/LuaModuleFunctionCritiqued
Basically using lua's 5.1.4 module function is no longer recommended and will be removed from 5.2
don't use lua's module function
- EmmanuelOga
- Citizen
- Posts: 56
- Joined: Thu Apr 22, 2010 9:42 pm
- Location: Buenos Aires, Argentina
- Contact:
don't use lua's module function
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
http://EmmanuelOga.com
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: don't use lua's module function
Yeah. I never liked it in the first place.
Even when I read about it on PIL, it seemed like a half-baked solution. I'm glad it is being removed.
Even when I read about it on PIL, it seemed like a half-baked solution. I'm glad it is being removed.
When I write def I mean function.
-
- Prole
- Posts: 47
- Joined: Thu Sep 24, 2009 1:49 pm
Re: don't use lua's module function
FYI
Changes since Lua 5.1
Here are the main changes introduced in Lua 5.2. The reference manual lists the incompatibilities that had to be introduced.
Main changes
yieldable pcall and metamethods
new _ENV scheme
ephemeron tables
new library for bitwise operations
light C functions
emergency garbage collector
Here are the other changes introduced in Lua 5.2:
Language
no more fenv for threads or functions
tables honor the __len metamethod
hex and \* escapes in strings
order metamethods work for different types
no more verification of opcode consistency
hook event "tail return" replaced by "tail call"
empty statement
Libraries
new metamethods __pairs and __ipairs
arguments for function called through xpcall
optional 'mode' argument to load (to control binary x text)
new function loadin
loadlib may load libraries with global names (RTLD_GLOBAL)
new function package.searchpath
optional base in math.log
file:write returns file
closing a pipe returns exit status
os.exit may close state
new option 'isrunning' for collectgarbage and lua_gc
frontier patterns
\0 in patterns
new option *L for io.read
options for io.lines
C API
main thread predefined in the registry
new constants LUA_OK and LUA_ERRGCMM
new lua_compare, lua_arith, and lua_len
new lua_version and luaL_version
lua_pushstring and pushlstring return string
new luaL_testudata and luaL_setmetatable
new luaL_tolstring
new lua_copy
new lua_absindex
new lua_upvalueid and lua_upvaluejoin
nparams and isvarag available in debug API
new lua_Unsigned
Implementation
max constants per function raised to 226
internal (immutable) version of ctypes
simpler implementation for string buffers
udata with finalizers are kept in a separated list for the GC
CallInfo stack now is a linked list
parser uses much less C-stack space (no more auto arrays)
new hash for floats
handling of non-string error messages in the standalone interpreter
generational mode for garbage collection (experimental)
Changes since Lua 5.1
Here are the main changes introduced in Lua 5.2. The reference manual lists the incompatibilities that had to be introduced.
Main changes
yieldable pcall and metamethods
new _ENV scheme
ephemeron tables
new library for bitwise operations
light C functions
emergency garbage collector
Here are the other changes introduced in Lua 5.2:
Language
no more fenv for threads or functions
tables honor the __len metamethod
hex and \* escapes in strings
order metamethods work for different types
no more verification of opcode consistency
hook event "tail return" replaced by "tail call"
empty statement
Libraries
new metamethods __pairs and __ipairs
arguments for function called through xpcall
optional 'mode' argument to load (to control binary x text)
new function loadin
loadlib may load libraries with global names (RTLD_GLOBAL)
new function package.searchpath
optional base in math.log
file:write returns file
closing a pipe returns exit status
os.exit may close state
new option 'isrunning' for collectgarbage and lua_gc
frontier patterns
\0 in patterns
new option *L for io.read
options for io.lines
C API
main thread predefined in the registry
new constants LUA_OK and LUA_ERRGCMM
new lua_compare, lua_arith, and lua_len
new lua_version and luaL_version
lua_pushstring and pushlstring return string
new luaL_testudata and luaL_setmetatable
new luaL_tolstring
new lua_copy
new lua_absindex
new lua_upvalueid and lua_upvaluejoin
nparams and isvarag available in debug API
new lua_Unsigned
Implementation
max constants per function raised to 226
internal (immutable) version of ctypes
simpler implementation for string buffers
udata with finalizers are kept in a separated list for the GC
CallInfo stack now is a linked list
parser uses much less C-stack space (no more auto arrays)
new hash for floats
handling of non-string error messages in the standalone interpreter
generational mode for garbage collection (experimental)
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: don't use lua's module function
This is the one I liked the most. Being able to do #vector instead of vector.module()tables honor the __len metamethod
When I write def I mean function.
Re: don't use lua's module function
I like the bit library and the emergency garbage collector. Is Love getting updated to 5.2?
Re: don't use lua's module function
I wonder how build a module ?
I'm often using (in file mymodule.lua):
and use with :
I'm also see direct global var affectation like
What is the best ?
Is there a recommended way to define module for löve ?
Regards,
I'm often using (in file mymodule.lua):
Code: Select all
local M = {}
M.data = something
function M.func1(...) ... end
function M.func2(...) ... end
module("mymodule")
return M
Code: Select all
mymodule = require("mymodule")
-- or
local mymodule = require("mymodule")
Code: Select all
local M = {}
M.data = something
function M.func1(...) ... end
function M.func2(...) ... end
mymodule = M
module("mymodule")
Is there a recommended way to define module for löve ?
Regards,
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: don't use lua's module function
This topic is actually about that you shouldn't use the module() function. You can do something like:TsT wrote:I wonder how build a module ?
Code: Select all
local M = {}
M.data = something
function M.func1(...) ... end
function M.func2(...) ... end
return M
Code: Select all
mymodule = {}
mymodule.data = something
function mymodule.func1(...) ... end
function mymodule.func2(...) ... end
Help us help you: attach a .love.
Re: don't use lua's module function
Oh ok, it's just about the module() use.
Thanks !
Thanks !
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
Re: don't use lua's module function
You can also do this:
The package.loaded thing makes sure that the require function does not load the file twice.
Code: Select all
package.loaded[...] = true
local module_var = 'bar'
local function foo() print('foo') end
local function bar() print(module_var) end
return {
foo = foo,
bar = bar
}
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: don't use lua's module function
require() should fill that field, not module().
Who is online
Users browsing this forum: No registered users and 5 guests