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

Add io.read and io.write capabilities. #1169

Open
creepersaur opened this issue Feb 17, 2024 · 5 comments
Open

Add io.read and io.write capabilities. #1169

creepersaur opened this issue Feb 17, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@creepersaur
Copy link

I know lua has io.read and io.write, but luau, being rebuilt from scratch it seems, doesn't. Roblox doesn't need io perhaps but it is much better looking at luau which is faster than base lua.

Currently, it's not possible to take user input through the terminal/console. And I would love if this was added.

@creepersaur creepersaur added the enhancement New feature or request label Feb 17, 2024
@UtoECat
Copy link

UtoECat commented Feb 17, 2024

All I/O support has been removed to provide sandboxing capabilities.

There are certain problems with the fact that several unsafe luau scripts will consume input from different threads at the same time, for example, or if the native application that embeds luau needs that input.

Additionally, both io.read() and io.write() can cause the thread to block until the operation completes or new data is received, which is not always acceptable.

If your task really requires terminal I/O and you understand all the implications, you can wrap the C getchar()/putchar() functions quite easily and add the wrapped functions to a global table. It won't take more than 10-20 lines of C/C++ code.

@creepersaur
Copy link
Author

All I/O support has been removed to provide sandboxing capabilities.

There are certain problems with the fact that several unsafe luau scripts will consume input from different threads at the same time, for example, or if the native application that embeds luau needs that input.

Additionally, both io.read() and io.write() can cause the thread to block until the operation completes or new data is received, which is not always acceptable.

If your task really requires terminal I/O and you understand all the implications, you can wrap the C getchar()/putchar() functions quite easily and add the wrapped functions to a global table. It won't take more than 10-20 lines of C/C++ code.

I was hoping it would be easier to take input, as I would assume most people who use Roblox or luau haven't done much C/C++ or know how to wrap lua with it (this includes me.) And it would make sense pausing a thread until I/O actions are completed.

Could you provide a resource for me to look through with regards to this though?

@UtoECat
Copy link

UtoECat commented Feb 17, 2024

as I would assume most people who use Roblox or luau haven't done much C/C++ or know how to wrap lua with it (this includes me.)
Could you provide a resource for me to look through with regards to this though?

Wait, are you using the luau CLI utility?

I think it would make a little more sense to have these functions included with the CLI... But at the same time, this can lead to some confusion, because the embedded luau does not have such functions.

Anyway, back to your situation. If you find it difficult to work with C/C++ code and the LUA C API, I would suggest using regular lua or luajit.
The lack of IO functions is not as critical as the lack of ability to dynamically load native code (compiled C/C++/any language) libraries to expand the capabilities of your scripts... And Luau does not support dynamic loading of theese libraries.

@creepersaur
Copy link
Author

creepersaur commented Feb 17, 2024

Wait, are you using the luau CLI utility?
I'm using the luau.exe file from the luau-lang.org website. I'm finding it really hard (and annoying) to build luajit. As they say "only source code" is available and you have to build the luajit.exe yourself.

And embedded luau doesn't need IO support, which I agree, but it generally is rather useful. Python is multipurpose and has IO, I wished it was faster though.

Is there a public luajit.exe file? I'm getting errors trying to build from source and it would be way simpler using an exe.

@vegorov-rbx
Copy link
Collaborator

vegorov-rbx commented Feb 19, 2024

While we might add more os library methods/IO/dynamic modules in the future specifically for luau build as an executable, right now we don't have this on our roadmap.

Like it was mentioned, users building Luau from source can add any methods they need to the global environment.

You can also look at this project that already extends default Luau environment with IO features and other things: https://github.com/lune-org/lune (note, this is not a project managed/supported by the Luau org)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants