mherkender / lua.js

An ECMAscript framework to compile and run Lua code, allowing Lua to run in a browser or in Flash
http://blog.brokenfunction.com/
600 stars 73 forks source link

require should return the loaded module #26

Open graue opened 11 years ago

graue commented 11 years ago

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).