Forum: Programming and Scripting
Topic: functions5.lua
started by: mikshaw

Posted by mikshaw on July 16 2007,00:00
function getbootparam uses io.input("/proc/cmdline") to read the boot parameters from /proc/cmdline
Should there be an io.input() with no argument to return the default input to stdin?

I assume there is no issue with DSL in the way it uses functions5.lua, but i was wondering mostly if "standard" use of the io.input function would say it should be reset to stdin

Posted by roberts on July 16 2007,00:40
Yes!  Good observation! Lazy me. My bad.
Although, upon program termination it is reset. But still it much better to reset it when done with task at hand.

Posted by mikshaw on July 16 2007,04:01
I was guessing there probably wasn't a problem when used in the way DSL uses it. I was mainly asking in order to be sure to present the most reliable and universal way to use io.input to other users.

Thank you.

Posted by mikshaw on July 17 2007,01:43
I don't want to be a pain, but I think there might be a bug (sort of) in this very same function.

Here's what I assume is the intended behavior of the function:
If you have a boot option foo=bar, you use getbootparam("foo=") and it will return "bar".
If you have the boot option "foo", you use getbootparam("foo") and it will return foo. Maybe I'm wrong about this second one, but it seems to (sort of) work this way.

However, depending on how you have written your boot line, it may not return what you expect.  If you have a boot option "foobar=bar" or "bar=foo" or "foobar", and you use getbootparam("foo"), it will return "foo".

Of course the more I think about it, the more I wonder if it is actually not intended to be used without "=" as part of the function parameter. In that case, I apologize for bringing this up. If it wasn't intended to be used this way, I think it *could* possibly be fixed to do so, and then you could use the same function to grab either "foo" or "foo=bar" type of boot parameters.

Posted by roberts on July 20 2007,07:03
No problem to discuss to all. My intended use was with the "=" sign.
At the time, I was writing hundreds of lines of Lua code and probably rushed somethings to work as I wanted, at the moment and likely not the most general or best of breed.

You do bring up good ideas to reflect upon for further improvement.

Your presentation made me think of Klaus' bash functions, checkbootparam and getbootparam. The checkbootparam function behaves as in one of your examples, which would likely not be what would be intended, i.e., foobar=bar, checkbootparam(foo) returns sucess. I have had to always be wary of this, as it has tripped me on occasion.

But I think with all things code, there is always room for improvement especially when revisted.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.