Jump to content




Path prefixes

lua computer

  • You cannot reply to this topic
10 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 07 April 2016 - 12:22 PM

I found some path prefixes, when I browsed throw the bios of CC:

'/'
'.:'
':'

What they do and are there more path prefixes? =)

Edited by Sewbacca, 07 April 2016 - 12:24 PM.


#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 07 April 2016 - 12:40 PM

From bash:

I know / is root, I don't know what the others are.

I know that .. is the parent directory but you are showing .:

Additionally . is the current directory but again you're asking about :

Note sure if these could be the same from bash.

#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 07 April 2016 - 12:53 PM

Lupus you're right, .: and : don't show up in that context for files. . and .. show up in the bios for fs.complete. Lines 705 and 707.

#4 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 07 April 2016 - 01:01 PM

":" is the separator for the shell path. For instance "rom/programs:rom/programs/advanced" would look in "rom/programs" and then "rom/programs/advanced" to find the program. ".:rom/programs" would first look in the current directory (".") and then in "rom/programs" if it cannot be found.

Edited by SquidDev, 07 April 2016 - 01:02 PM.


#5 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 07 April 2016 - 01:07 PM

So what you're saying is that : is a sort of "If I don't find it here, check here as well" kind of operator? Is it possible to nest it in such a way like ternary?

"." .. ":.." .. ":../.."
Check current, then up one, then up two?

Edited by Dragon53535, 07 April 2016 - 01:07 PM.


#6 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 07 April 2016 - 01:11 PM

View PostDragon53535, on 07 April 2016 - 01:07 PM, said:

So what you're saying is that : is a sort of "If I don't find it here, check here as well" kind of operator? Is it possible to nest it in such a way like ternary?
It isn't an "operator" as such, the shell program splits the path on the character ":" and tries each one in turn.

View PostDragon53535, on 07 April 2016 - 01:07 PM, said:

"." .. ":.." .. ":../.."
Check current, then up one, then up two?
I'd guess that would work. You'd have to try.

Edited by SquidDev, 07 April 2016 - 01:11 PM.


#7 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 07 April 2016 - 05:57 PM

thaks

#8 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 07 April 2016 - 06:11 PM

I tested it in the interactive lua, because in my program it doesn't worked:

lua> dofile('./shell')
lua:1: File not found

I wonder, because '.' is the current directory and the current directory of lua is rom/programs, isn't?

Edited by Sewbacca, 07 April 2016 - 06:12 PM.


#9 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 07 April 2016 - 06:14 PM

dofile does not use these prefixes, only the shell program. Were you to do dofile(shell.resolve("./shell")) it will work (though the ./ is implicit here).

#10 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 07 April 2016 - 06:27 PM

*headbang*

Fun fact:

View PostSquidDev, on 07 April 2016 - 06:14 PM, said:

dofile does not use these prefixes, only the shell program. Were you to do dofile(shell.resolve("./shell")) it will work (though the ./ is implicit here).
doesn't works from the running path.

fs.getDir(shell.getRunningProgram()) works

Edited by Sewbacca, 07 April 2016 - 06:28 PM.


#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 April 2016 - 06:39 PM

View PostSewbacca, on 07 April 2016 - 06:11 PM, said:

the current directory of lua is rom/programs, isn't?

The current directory of the Lua console is whatever directory you started it from, not the directory it's stored in (that is to say, it's the shell's working directory), assuming you don't later set it to something else.

dofile() always uses an absolute path and doesn't care about the working directory (most path-based commands in ComputerCraft behave this way). If you use shell.resolve() then the working directory will be included in the returned path.

Truth be told, ComputerCraft doesn't handle the other fancy relative paths correctly - . stands for the current directory, .. stands for the parent, and it gets that right. But ..., ...., ........, etc should all also point to the current directory, and last I checked they've never been properly accounted for - you can actually crash shell with "cd ........" as a result of this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users