Jump to content




[New Lua Function] os.getVersion (yes I know there is os.version)


  • You cannot reply to this topic
24 replies to this topic

#1 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#2 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 22 February 2013 - 12:05 AM

Maybe os.getVersionNum() for compatibility?

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 February 2013 - 12:16 AM

View Posttiin57, on 22 February 2013 - 12:05 AM, said:

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 matches
Spoiler

EDIT: Better title? :P

Edited by TheOriginalBIT, 22 February 2013 - 12:17 AM.


#4 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 22 February 2013 - 01:29 AM

... you can convert that string to a number yourself.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 February 2013 - 01:32 AM

View PostCloudy, on 22 February 2013 - 01:29 AM, said:

... you can convert that string to a number yourself.

View PostTheOriginalBIT, on 21 February 2013 - 11:39 PM, said:

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...

#6 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, 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.

#7 Cloudy

    Ex-Developer

  • Members
  • 2,543 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.

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 February 2013 - 02:35 AM

View PostCloudy, on 22 February 2013 - 02:30 AM, said:

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?

#9 Cloudy

    Ex-Developer

  • Members
  • 2,543 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?

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 February 2013 - 02:41 AM

View PostCloudy, on 22 February 2013 - 02:37 AM, said:

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.

#11 ChunLing

  • Members
  • 2,027 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.

#12 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 23 February 2013 - 12:51 AM

View PostChunLing, on 22 February 2013 - 09:23 AM, said:

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...

View Posttiin57, on 22 February 2013 - 12:05 AM, said:

Maybe os.getVersionNum() for compatibility?


#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 February 2013 - 01:00 AM

View Posttiin57, on 23 February 2013 - 12:51 AM, said:

View PostChunLing, on 22 February 2013 - 09:23 AM, said:

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...

View Posttiin57, on 22 February 2013 - 12:05 AM, said:

Maybe os.getVersionNum() for compatibility?
And also again... (aimed at ChunLing, not tiin57)

View PostTheOriginalBIT, on 22 February 2013 - 12:16 AM, said:

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.

#14 Cloudy

    Ex-Developer

  • Members
  • 2,543 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.

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 February 2013 - 04:37 AM

View PostCloudy, on 23 February 2013 - 04:34 AM, said:

_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.

#16 Shnupbups

  • Members
  • 596 posts
  • LocationThat 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.?

#17 ChunLing

  • Members
  • 2,027 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.

#18 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, 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.

#19 ChunLing

  • Members
  • 2,027 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.

#20 GopherAtl

  • Members
  • 888 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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users