This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
augustas656's profile picture

Anyone have a code for their own read function that has identical or even better features than io.read()?

Started by augustas656, 29 April 2014 - 07:39 PM
augustas656 #1
Posted 29 April 2014 - 09:39 PM
Regards
Augustas
MKlegoman357 #2
Posted 29 April 2014 - 09:45 PM
What features do you need? There are some read implementations with more features, just search for them. You can find the default read function in bios.lua file.
Lyqyd #3
Posted 29 April 2014 - 10:11 PM
It really depends on what you're trying to do. "More features" isn't always better, especially for something as simple as a read function. What do you need it to do? Limit line length, limit allowable characters, allow multiple lines? There are a lot of things one could do to modify read(), and trying to stuff all of them into one function would be a little absurd.
augustas656 #4
Posted 29 April 2014 - 10:35 PM
Can you explained how this works as good as you can, because I'm kind of confused with these parts:
term.write( string.rep(" ", w - x + 1) )
str = str:sub(1, pos - 1)..p1..str:sub(pos)

EDIT: Source: https://github.com/matheuscat/Computer-Craft-Programs/blob/master/lua/bios.lua
Edited on 29 April 2014 - 08:37 PM
CometWolf #5
Posted 29 April 2014 - 10:59 PM

term.write( string.rep(" ", w - x + 1) )
writes a string with as many empty spaces as (w - x + 1), this is probably used to clear the line for when you're eg pressing backspace


str = str:sub(1, pos - 1)..p1..str:sub(pos)
adds the string p1 to the string str, at the position of pos. Im assuming p1 is the result of a char event, so essentially this is used to add characters.

Just look up the functions yourself if you don't understand them, please.
http://lua-users.org...LibraryTutorial
Edited on 29 April 2014 - 09:00 PM
electrodude512 #6
Posted 30 April 2014 - 10:56 PM
I didn't write this version, and it's way more complicated, but it certainly has more features: http://www.computercraft.info/forums2/index.php?/topic/5866-cc-145-shell-tab-completion-v22/

It lets you use the tab key to autocomplete parts of paths. It works the same way it works in bash. It's very nice.