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

filesystem bindings #1

Open
7 of 9 tasks
naturallymitchell opened this issue Oct 8, 2018 · 20 comments
Open
7 of 9 tasks

filesystem bindings #1

naturallymitchell opened this issue Oct 8, 2018 · 20 comments

Comments

@naturallymitchell
Copy link
Member

naturallymitchell commented Oct 8, 2018

improvements to filesystem bindings, from lighttouch's fs workarounds and gut's fs workarounds

@naturallymitchell naturallymitchell changed the title Filesystem bindings filesystem bindings Oct 9, 2018
@naturallymitchell
Copy link
Member Author

read file
...?

@naturallymitchell naturallymitchell added this to the 1 milestone Nov 8, 2018
@Arnaz87
Copy link
Contributor

Arnaz87 commented Nov 8, 2018

read file is in the lua standard io library

it's not crazy to have them separated, some languages have separate libraries for io (read/write file content) and filesystem (directories and metadata), rust being one

@Arnaz87 Arnaz87 closed this as completed Nov 8, 2018
@naturallymitchell
Copy link
Member Author

append to start of file (prepend)
copy

@naturallymitchell
Copy link
Member Author

open

@naturallymitchell
Copy link
Member Author

@sineemore
Copy link
Contributor

Need something like fs.chdir to change current working directory with Lua.

Example usage:

local err = fs.chdir("/this/path/exists")
assert(err == nil, "Failed to chdir to existing directory")

local err = fs.chdir("/no/such/path")
assert(err != nil, "Chdir to nonexistent directory succeeded")

err should be string describing the failed syscall.

@dariusc93
Copy link
Contributor

I dont believe rust have anything builtin to change the directory, but using libc, you could call libc::chdir but probably would need to create a wrapper around it since such call would be unsafe.

The current set of fs bindings have an unnatural feel and use due to lua bindings not having any direct access anything such as std::fs::File. While making use of fs::read and fs::write can be useful, improving the overall use of the fs bindings can help with functionality with little bottleneck. This can include making use of std::fs::File or even std::fs::OpenOptions (probably might be the preferred choice for a little more flexibility since they both will return std::fs::File anyway but OpenOptions expose more options), being able to read/write data seamlessly, be able to seek through the data and call any related functions in a safe manner (in terms of memory and security), which in theory can replace the io calls within lua (especially since rlua doesnt exactly provide safety with embedded lua it has so having alternatives would be best in this case).

@sineemore
Copy link
Contributor

@sineemore
Copy link
Contributor

sineemore commented Dec 18, 2018

While making use of fs::read and fs::write can be useful.

There is file:read("a") in Lua to read all file directly to memory from the start or current position of file handle.

Actually it makes sense to completely replaces the io with Rust implementation.

@dariusc93
Copy link
Contributor

Yea I saw that function not to long ago (I dont really look in std::env) so I can implement it in a few.

Yea, lua does have that but the problem is that such calls isnt exactly done in a safe manner and rlua doesnt exactly provide any safety for many (if not all) of lua internal functions.

@sineemore
Copy link
Contributor

@dariusc93
Oh, where can I read more about that?

@dariusc93
Copy link
Contributor

Alot of the information is in rlua description. Other parts can be done by reviewing rlua code and how it interact with the embedded lua code, though everything there is considered to be WIP so things will likely change (which may or may not be breaking on rust side).

@naturallymitchell
Copy link
Member Author

@naturallymitchell
Copy link
Member Author

@dariusc93
Copy link
Contributor

I have this already in a local branch. Let me rebase and ill push it

@naturallymitchell
Copy link
Member Author

is writeable

@naturallymitchell
Copy link
Member Author

#!/usr/bin/env torchbear

print(cwd)

returns nil

I think that's holding back jazzdotdev/jazz-libs#7

@dariusc93
Copy link
Contributor

There is no cwd in torchbear. You can use fs.current_dir() to get the current directory.

@naturallymitchell
Copy link
Member Author

cool. thanks

@naturallymitchell
Copy link
Member Author

dariusc93 added a commit that referenced this issue Feb 25, 2019
@naturallymitchell naturallymitchell removed this from the 2 milestone May 25, 2020
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

4 participants