[Debugging] using io.stdin:read for first time.

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

[Debugging] using io.stdin:read for first time.

#1 Post by zer0 » Fri Apr 17, 2009 7:11 am

Hey Elv, and sailor.

I've got this curious issue. In my scripts I'm going to allow a menu driven system.

I'm using the following function for input

Code: Select all

io.stdin:read'*l'
However when I call it for the first time, the script value that was entered is automatically entered.

For example MM loads, then I enter: "my_test.lua" then when calling the io.stdin:read function the script name shows.

I show u a nice quick example of what I mean:

Code: Select all

function main()
	local l_option = io.stdin:read'*l'
	print("l_option: \'" .. l_option .. "\'")
end

startMacro(main)
Displays:
Image

Any ideas how I can remove the script name from the buffer before I start asking for input? It is not a big deal for me since my scripts get called by batch files so nothing is in the buffer then, but just thought it's worth mentioning.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: [Debugging] using io.stdin:read for first time.

#2 Post by zer0 » Fri Apr 17, 2009 7:35 am

Nevermind I answered my own question, guess I should have looked in the MicroMacro manual harder. :roll:

Code: Select all

	keyboardBufferClear(); -- clear keyboard buffer
	io.stdin:flush(); -- clear standard input buffer
Fixes it, thanks.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: [Debugging] using io.stdin:read for first time.

#3 Post by Administrator » Fri Apr 17, 2009 9:33 am

Indeed. This can be confusing for people who are not familiar with working with console input. Generally, it's good practice to clear both the standard IO buffer and keyboard buffer directly before trying to read any information. In your example, you could get away with just clearing the keyboard buffer, since that information has already been popped from the IO buffer.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests