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

Possible bug with paths #127

Closed
stefanos82 opened this issue Sep 22, 2021 · 9 comments
Closed

Possible bug with paths #127

stefanos82 opened this issue Sep 22, 2021 · 9 comments
Labels

Comments

@stefanos82
Copy link
Contributor

I have started writing a shell script to automate my Nelua tests and instead of going in the directory where the files are located, I have decided to let the script test them for me, from a separate location of course.

The script looks like this:

$ cat validatenelua.sh 
#!/bin/sh

tput reset

for name in /home/stefanos/code/nelua/*.nelua
do
    echo "$name"
    nelua -tb "$name"
done

for name in /home/stefanos/code/nelua/Overview/*.nelua
do
    echo "$name"
    nelua -tb "$name"
done

When executed from $HOME/programming/ directory that is located, it throws an error for this particular module only:

image

The interesting part is...when I go to /home/stefanos/code/nelua/Overview/ and run for name in *.nelua; do echo "$name"; nelua -tb "$name"; done, everything works as expected.

Is it something that has to do with the relative / absolute paths?

I always confuse these two how they should work or behave.

My suspicion is telling me is related to b17a77b where you introduced support for relative requires in the preprocessor.

@stefanos82 stefanos82 added the bug label Sep 22, 2021
@stefanos82
Copy link
Contributor Author

Seems like it was a bug in my code; actually not a bug, but the old way of doing things.

After I rewrote require 'globals to require ./globals.nelua, now it works.

Can we add a note in the documentation to make it obvious for end-users that this should be the way of requiring modules that are relative to project's path?

@edubart
Copy link
Owner

edubart commented Sep 22, 2021

Seems like it was a bug in my code; actually not a bug, but the old way of doing things.

After I rewrote require 'globals to require ./globals.nelua, now it works.

Can we add a note in the documentation to make it obvious for end-users that this should be the way of requiring modules that are relative to project's path?

This is not the proper way to require modules relative to the same path, because it is platform dependent, while Linux uses / as path separator, windows uses \, you could use require '.global' instead. I don't want to document relative require yet because I don't want to encourage people to use it, as Lua can't do that, and people should really setup their library path instead, so it's a hidden feature.

@stefanos82
Copy link
Contributor Author

This is not the proper way to require modules relative to the same path, because it is platform dependent, while Linux uses / as path separator, windows uses \, you could use require '.global' instead.

Like Python...interesting.

I don't want to document relative require yet because I don't want to encourage people to use it, as Lua can't do that, and people should really setup their library path instead, so it's a hidden feature.

In Lua, how do you handle paths under Windows?

@edubart
Copy link
Owner

edubart commented Sep 22, 2021

In Lua, how do you handle paths under Windows?

Lua does this way: When you do require 'path.to.file', the string path.to.file gets convert to path/to/file.lua on Linux and path\to\file.lua on Windows.

@stefanos82
Copy link
Contributor Author

Lua does this way: When you do require 'path.to.file', the string path.to.file gets convert to path/to/file.lua on Linux and path\to\file.lua on Windows.

...and Nelua does not do that already to match Lua's behavior?

@edubart
Copy link
Owner

edubart commented Sep 22, 2021

...and Nelua does not do that already to match Lua's behavior?

It does.

@stefanos82
Copy link
Contributor Author

So what should be the Lua way to require modules relative to the same path as the one we need to run?

@edubart
Copy link
Owner

edubart commented Sep 22, 2021

So what should be the Lua way to require modules relative to the same path as the one we need to run?

This is not possible in Lua, the only thing you can do in Lua is to add search paths, in Nelua you can also add search paths with --add-path flag or in your config.

@stefanos82
Copy link
Contributor Author

This is not possible in Lua, the only thing you can do in Lua is to add search paths, in Nelua you can also add search paths with --add-path flag or in your config.

I see...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants