Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua5_1, luajit and original luajit behave differently #189689

Closed
junchih opened this issue Sep 4, 2022 · 5 comments
Closed

lua5_1, luajit and original luajit behave differently #189689

junchih opened this issue Sep 4, 2022 · 5 comments

Comments

@junchih
Copy link

junchih commented Sep 4, 2022

Describe the bug

-- "tasting.lua"
print(string.gsub(package.path, ";", "\n").."\n")

Will behave differently on host luajit, nixpkg luajit and nixpkg lua5_1.

Expected behavior

  1. From LUA_PATH_DEFAULT of luaconf.h, there is not way lua runtime will automatically defaultly load something like ./myPkg/init.lua, but lua5_1 of nixpkg 22.05 will do this. I'm new to nix, can't see why?
  2. luajit and lua5_1 of nixpkg 22.05 behave differently. luajit will load all lua module from system path, lua5_1 will load all package from working directory. And both differently with my host luajit, which load module from both working directory and system path.
  3. Anyway, seems same patch both in lua5_1 and luajit, https://github.com/NixOS/nixpkgs/blob/22.05/pkgs/development/interpreters/luajit/default.nix#L62-L69, but luajit doesn't work expectly, so the default luajit from nixpkg 22.05 can't do anything as a standalone lua interpreter.

Screenshots

On macOS 12.5.1, LuaJIT 2.1.0-beta3

./?.lua
/usr/local/share/luajit-2.1.0-beta3/?.lua
/usr/local/share/lua/5.1/?.lua
/usr/local/share/lua/5.1/?/init.lua
/usr/local/share/lua/5.1/?.lua
/usr/local/share/lua/5.1/?/init.lua

On luajit of nixpkgs 22.05 with helping of shell.nix

/nix/store/db6sp8wgr97zn4qyyb7g42yhr00pqjiy-luajit-2.1.0-2022-04-05/share/lua/5.1/?.lua
/nix/store/db6sp8wgr97zn4qyyb7g42yhr00pqjiy-luajit-2.1.0-2022-04-05/share/lua/5.1/?/init.lua

On lua5_1 of nixpkgs 22.05 with helping of shell.nix

./share/lua/5.1/?.lua
./?.lua
./?/init.lua

Notify maintainers

@teto, 8884291

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
blabla...
blabla...
...
 - system: `"x86_64-darwin"`
 - host os: `Darwin 21.6.0, macOS 10.16`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.15`
 - channels(jack): `"nixpkgs-21.11pre306870.67c80531be6"`
 - nixpkgs: `/Users/jack/.nix-defexpr/channels/nixpkgs`
@teto
Copy link
Member

teto commented Sep 4, 2022

The lua ecosystem needs some love see:

The incentive for patching the interpreter is to increase purity and avoid loading inadvertendly stuff from /usr/local/share/. We could always wrap but someone using ";;" (i.e. "add default") in its LUA_PATH could inadvertendly break stuff.
What could be interesting is to add your test cases to #177556 .

you can use lua.withPackages(p: [ p.cqueues ]); to create a lua with the packages you need.

@junchih
Copy link
Author

junchih commented Sep 5, 2022

Sorry, don't have much free time to read all the resources.

Let's see how the issue infects daily development work.

  • issue 1, after I've done a few relating lua script development. There is some code such as require "mypkg", and the expecting loading file is mypkg/init.lua. Testing with nix-shell + lua5_1 will pass, but still could not be interpreted by downloaded original lua 5.1 without any additional configuration.
  • issue 3, obviously, if I just get luajit with nix-shell, and do nothing about configuration. The command luajit ./main.lua will surely failed. But weird, the ./main.lua was just tested by me with the luajit of the OS hosted one. With both same luajit version number, and both same zero configuration.

And of course, with correcting LUA_PATH env, this issue could be nonsense. But I don't think some logically unnecessary configurations is good idea for libraries to be portable and maintaining.

@teto
Copy link
Member

teto commented Sep 5, 2022

bottomline was: you are right, things are broken and this is bad. Patches/tests welcomes

@teto
Copy link
Member

teto commented Mar 16, 2024

should be fixed by #286822

@teto
Copy link
Member

teto commented Apr 5, 2024

should be fixed on master see those tests

"5.4" = "${lua}/share/lua/5.4/?.lua;${lua}/share/lua/5.4/?/init.lua;${lua}/lib/lua/5.4/?.lua;${lua}/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua";
. I'll let you close once you are confident that fixed the issue

@teto teto closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants