Page 1 of 1

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

Posted: Fri Apr 17, 2009 7:11 am
by zer0
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.

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

Posted: Fri Apr 17, 2009 7:35 am
by zer0
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.

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

Posted: Fri Apr 17, 2009 9:33 am
by Administrator
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.