[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Problems with compat-5.1 release 3
- From: Renato Maia <maia@...>
- Date: Mon, 20 Jun 2005 10:47:34 -0300 (BRT)
Hello everybody,
I'm writing to report a problem with compat-5.1-r3. Currently, it is not
possible create sub-modules with the same name as global variables. For
example, one cannot create the module 'mymodule.assert' or
'mymodule.error' if the basic library is loaded in the Lua state. To
overcome this problem I did the following change:
--- compat-5.1.lua 2005-05-20 18:40:50.000000000 -0300
+++ compat-5.1r3/lua/compat-5.1.lua 2005-05-26 11:55:11.000000000
-0300
@@ -8,7 +8,7 @@
local LUA_OFSEP = ''
local POF = 'luaopen_'
-local assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv,
setmetatable, type = assert, error, getfenv, ipairs, loadfile, loadlib,
pairs, setfenv, setmetatable, type
+local assert, error, getfenv, ipairs, loadfile, loadlib, pairs, rawget,
setfenv, setmetatable, type = assert, error, getfenv, ipairs, loadfile,
loadlib, pairs, rawget, setfenv, setmetatable, type
local format, gfind, gsub = string.format, string.gfind, string.gsub
--
@@ -51,7 +51,7 @@
assert (type(f)=="string", "not a valid field name
("..tostring(f)..")")
for w in gfind(f, "[%w_]+") do
if not t then return nil end
- t = t[w]
+ t = rawget(t, w)
end
return t
end
There is also another small difference in compat-5.1-r3 with Lua 5.1 work
6 that makes me wonder why. Is there any special reason why module
function of Lua 5.1 work 6 does not return the namespace table used for
the module? I ask that because sometimes it is interesting to access the
table directly (e.g. to access numeric index positions or access its
metatable). I know I can access it by means of getfenv or the like, but
since module function may not only be called once, most probably at
application/script start up, this may not impact its performance.
--
Renato Maia