Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { /* add node's require() to lua searchers */
- lauxlib.luaL_requiref(L, lua.to_luastring("package"), lualib.luaopen_package, 0);
- if (lua.lua_getfield(L, -1, lua.to_luastring("searchers")) != lua.LUA_TTABLE)
- lauxlib.luaL_error(L, lua.to_luastring("'package.searchers' must be a table"));
- lua.lua_pushcfunction(L, function(L) {
- let name = lauxlib.luaL_checkstring(L, 1);
- let path;
- try {
- path = require.resolve(lua.to_jsstring(name));
- } catch(e) {
- lua.lua_pushnil(L);
- return 1;
- }
- lua.lua_pushcfunction(L, function(L) {
- interop.push(L, require(path));
- return 1;
- });
- lua.lua_pushliteral(L, path);
- return 2;
- });
- lua.lua_seti(L, -2, lauxlib.luaL_len(L, -2)+1);
- lua.lua_pop(L, 2); /* remove searchers + package */
- }
Add Comment
Please, Sign In to add comment