7508 posts
Location
Australia
Posted 21 February 2013 - 11:39 PM
this one is nice and simple.
currently os.version returns "CraftOS <version>" as a string. I think it would be nice if we were able to get just the number portion of this. It would make checking os compatibility a breeze.
if os.getVersion() < 1.4 then
print("Sorry this program is only for CC1.4+")
end
Now I know there are ways to check like checking existence of term.clear and wrapping a modem and checking if a function exists, etc… I also know its possible to do this
local ver = os.version()
if tonumber(ver:sub(#ver - 3, #ver)) < 1.4 then
print("Sorry this program is only for CC1.4+")
end
But again, I feel it would just make it nicer with just a single function call to get a number.
Thanks for reading,
— TheOriginalBIT
1243 posts
Location
Indiana, United States
Posted 22 February 2013 - 12:05 AM
Maybe os.getVersionNum() for compatibility?
7508 posts
Location
Australia
Posted 22 February 2013 - 12:16 AM
Maybe os.getVersionNum() for compatibility?
yeh, bad wording of the title, but notice how in the code example I did os.getVersion :P/>
kinda matches the current functions in CC, except there will be a difference :P/>
What I mean by matchesSpoiler
os.getComputerLabel()
os.computerLabel()
os.getComputerID()
os.computerID()
EDIT: Better title? :P/>
Edited on 21 February 2013 - 11:17 PM
2447 posts
Posted 22 February 2013 - 01:29 AM
… you can convert that string to a number yourself.
7508 posts
Location
Australia
Posted 22 February 2013 - 01:32 AM
… you can convert that string to a number yourself.
I also know its possible to do this
local ver = os.version()
if tonumber(ver:sub(#ver - 3, #ver)) < 1.4 then
print("Sorry this program is only for CC1.4+")
end
But again, I feel it would just make it nicer with just a single function call to get a number.
Unless to course that you mean that tonumber( os.version() ) returns the version portion of the string…
1243 posts
Location
Indiana, United States
Posted 22 February 2013 - 01:41 AM
If I still used Lua, I would agree with TheOriginalBIT. This would be simple to implement in Java and helpful for newer coders.
2447 posts
Posted 22 February 2013 - 02:30 AM
Sorry, not a fan. Possible using the string, I'm not adding new functions just because you're too lazy to parse a string.
7508 posts
Location
Australia
Posted 22 February 2013 - 02:35 AM
Sorry, not a fan. Possible using the string, I'm not adding new functions just because you're too lazy to parse a string.
Very well. Not lazy, just thought it might be nice for new users that are not familiar with string functions. also what is the point of leaving in _G._VERSION?
2447 posts
Posted 22 February 2013 - 02:37 AM
String manipulation is probably the most basic thing in any language. And what's the point in removing _G._VERSION?
7508 posts
Location
Australia
Posted 22 February 2013 - 02:41 AM
String manipulation is probably the most basic thing in any language. And what's the point in removing _G._VERSION?
And yet so many don't know how to do it. Not everyone who uses the mod are programmers. Idk whats the point in keeping it? it just shows the LuaJ version.
2005 posts
Posted 22 February 2013 - 09:23 AM
The point of keeping things the same is to avoid breaking existing programs. Which this really would tend to do…ironically breaking the very programs that had made an effort to be upgrade safe (oh, the irony).
It's a major reason that I'm typically against most suggestions by default, but at least with other things you wouldn't break the primary mechanism that people have to make their programs safe across upgrades. Still, I'm perversely delighted by it for that very reason…irony.
But that's not really an endorsement.
1243 posts
Location
Indiana, United States
Posted 23 February 2013 - 12:51 AM
The point of keeping things the same is to avoid breaking existing programs. Which this really would tend to do…ironically breaking the very programs that had made an effort to be upgrade safe (oh, the irony).
It's a major reason that I'm typically against most suggestions by default, but at least with other things you wouldn't break the primary mechanism that people have to make their programs safe across upgrades. Still, I'm perversely delighted by it for that very reason…irony.
But that's not really an endorsement.
Again…
Maybe os.getVersionNum() for compatibility?
7508 posts
Location
Australia
Posted 23 February 2013 - 01:00 AM
The point of keeping things the same is to avoid breaking existing programs. Which this really would tend to do…ironically breaking the very programs that had made an effort to be upgrade safe (oh, the irony).
It's a major reason that I'm typically against most suggestions by default, but at least with other things you wouldn't break the primary mechanism that people have to make their programs safe across upgrades. Still, I'm perversely delighted by it for that very reason…irony.
But that's not really an endorsement.
Again…
Maybe os.getVersionNum() for compatibility?
And also again… (aimed at ChunLing, not tiin57)
but notice how in the code example I did os.getVersion :P/>
Not once did I mention anything that would break existing programs as its a NEW function, not a change to the existing.
And if you were talking about my remark of the point of keeping _G._VERSION: It wouldn't break any existing programs, I don't see ANY use case that would ever require the use of this variable.
2447 posts
Posted 23 February 2013 - 04:34 AM
_VERSION is a standard Lua variable. If you're trying to use that as an argument for us adding a function it's a poor argument.
7508 posts
Location
Australia
Posted 23 February 2013 - 04:37 AM
_VERSION is a standard Lua variable. If you're trying to use that as an argument for us adding a function it's a poor argument.
Nope it wasn't an argument to get you to add a function. was just a question as to why it existed in the environment.
671 posts
Location
That place over there. Y'know. The one where I am.
Posted 23 February 2013 - 08:52 AM
Maybe, if this was added, it could return the whole CC version number? So instead of 1.4 it would return 1.41 or 1.45 etc.?
2005 posts
Posted 23 February 2013 - 08:54 AM
Oh, I missed the thrust of the suggestion due to it being the only way this made sense as a suggestion.
This is simply too easily coded in Lua to be worth implementing as part of the core mod. There would have been a point (admittedly not a very good one) in changing the existing function, but just adding a new function, particularly one this simple, is simply not worth suggesting at all.
3790 posts
Location
Lincoln, Nebraska
Posted 23 February 2013 - 09:42 AM
It still seems kinda silly for the devs to add something you could easily do yourself using string manipulation. If you don't know how to do it, I suggest learning how.
2005 posts
Posted 23 February 2013 - 10:02 AM
He does know how, he wrote a function to do it right into the first post. Which is why I assumed the suggestion was to change the base function rather than add the new one he wrote.
871 posts
Posted 23 February 2013 - 10:13 AM
uhm. Just for the record, string comparison does, in fact, work as well. "CraftOS 1.5" >= "CraftOS 1.4" returns true. "CraftOS 1.5" >= "CraftOS 1.51" would work too, if they ever started including that kind of subversion info. So even string manipulation is not necessary, you can just compare the string versions.
88 posts
Location
UK
Posted 23 February 2013 - 10:21 AM
Version identifiers are not decimals and should not be treated as such. Consider:
1.0
1.1
1.2
...
1.8
1.9
1.10
1.11
Those are in order of increasing version, but not numeric or lexographic order.
Keep it as a string, or switch to an array of integers.
392 posts
Location
Christchurch, New Zealand
Posted 25 February 2013 - 02:20 PM
Might want to look in to why Str>Str works.
http://puu.sh/27V18I know it's garbage, but I had to check.
871 posts
Posted 25 February 2013 - 04:44 PM
nevercast, uhm. if you're pointing out it compares the first part of the string, then I would think that was rather obvious. Unless they change the name of CraftOS or change their version numbering conventions, the direct string comparison should work at least until version 10.x or x.10, at which point the new version will register as < the earlier, required version, and anyone using this will be forced to update their programs.
997 posts
Location
Wellington, New Zealand
Posted 25 February 2013 - 04:44 PM
Might want to look in to why Str>Str works.
http://puu.sh/27V18I know it's garbage, but I had to check.
"b" comes after "a".
392 posts
Location
Christchurch, New Zealand
Posted 25 February 2013 - 05:48 PM
Yeah heard that it's the sum of the bytes of the string that are used for the compare.