mherkender/lua.js

require should return the loaded module

graue opened this issue · 0 comments

I've noticed that when calling require from Lua.js, it doesn't return anything. The code inserted into each compiled Lua module is:

G.str['require'] = function (name) {
  lua_require(G, name);
};

Lua's reference manual states that require should return a value:

Once a loader is found, require calls the loader with a single argument, modname. If the loader returns any value, require assigns the returned value to package.loaded[modname]. If the loader returns no value and has not assigned any value to package.loaded[modname], then require assigns true to this entry. In any case, require returns the final value of package.loaded[modname].

Lua.js isn't doing the bolded part.

I may submit a patch for this if I can figure it out. This is part of my attempt to get the table method of defining a module to work in Lua.js (see #13).