Guest User

Untitled

a guest
Jan 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. { /* add node's require() to lua searchers */
  2. lauxlib.luaL_requiref(L, lua.to_luastring("package"), lualib.luaopen_package, 0);
  3. if (lua.lua_getfield(L, -1, lua.to_luastring("searchers")) != lua.LUA_TTABLE)
  4. lauxlib.luaL_error(L, lua.to_luastring("'package.searchers' must be a table"));
  5. lua.lua_pushcfunction(L, function(L) {
  6. let name = lauxlib.luaL_checkstring(L, 1);
  7. let path;
  8. try {
  9. path = require.resolve(lua.to_jsstring(name));
  10. } catch(e) {
  11. lua.lua_pushnil(L);
  12. return 1;
  13. }
  14. lua.lua_pushcfunction(L, function(L) {
  15. interop.push(L, require(path));
  16. return 1;
  17. });
  18. lua.lua_pushliteral(L, path);
  19. return 2;
  20. });
  21. lua.lua_seti(L, -2, lauxlib.luaL_len(L, -2)+1);
  22. lua.lua_pop(L, 2); /* remove searchers + package */
  23. }
Add Comment
Please, Sign In to add comment