[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require in 5.1 work6
- From: Mike Pall <mikelu-0508@...>
- Date: Tue, 2 Aug 2005 13:12:37 +0200
Hi,
Bernardo Signori wrote:
> I've built lua 5.1-work6 under cygwin and I'm playing with the new
> package functionality. I found this behaviour: if I call
> require("anything") and the package can't be found, I get the
> corresponding "package 'anything' not found" error; but if I
> immediately call require("anything") again, this time I don't get any
> error, although the package isn't loaded, of course. It seems like
> package.loaded["anything"] is set to true the first time, even if the
> package can't be found. Is this a bug or something wrong with my
> installation?
More a misfeature than a bug. Patch for this one below.
But this still doesn't cover the case where a module loads,
but the main chunk throws an error. No easy solution here
(using pcall in require would clear the (useful) backtrace).
Bye,
Mike
--- lua-5.1-work6/src/loadlib.c 2005-05-17 21:49:15 +0200
+++ lua51w6-cumulative/src/loadlib.c 2005-08-02 13:04:15 +0200
@@ -383,8 +383,10 @@
luaL_error(L, LUA_QL("package.loaders") " must be a table");
for (i=1;; i++) {
lua_rawgeti(L, -1, i); /* get a loader */
- if (lua_isnil(L, -1))
+ if (lua_isnil(L, -1)) {
+ lua_setfield(L, 2, name); /* _LOADED[name] = nil */
return luaL_error(L, "package " LUA_QS " not found", name);
+ }
lua_pushstring(L, name);
lua_call(L, 1, 1); /* call it */
if (lua_isnil(L, -1)) lua_pop(L, 1);