Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lua request] Get BizHawk version with client.getversion #1271

Closed
brunovalads opened this issue Aug 14, 2018 · 10 comments

Comments

Projects
None yet
3 participants
@brunovalads
Copy link

commented Aug 14, 2018

In order to make my scripts more accessible, would be interesting a function like client.getversion (not sure if client is the best class, seems to be) that returns the BizHawk version as a string (this information is already stored somewhere), and it can be used to forbid features in the scripts that use lua functions developed later (e.g. a lot of lua functions doesn't exist in 1.X). This is interesting to avoid making multiple versions of the same script.

@Asnivor

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

So currently it looks like the BizHawk version is generated on every release (and must be updated somewhere in the build chain as the codebase version in master is still 2.0.0). If you are using a development build just the git commit is returned using the VersionInfo method within BizHawk itself.

As you say, this version is returned fairly easily elsewhere within BizHawk so it will be a very simple addition to Lua.

Before I go ahead and start on a PR, the following would be the case (utilising the existing bizhawk VersionInfo method):

  • Running a developer build, this will return a string in the format:
    "GIT " + SubWCRev.GIT_BRANCH + "#" + SubWCRev.GIT_SHORTHASH
    e.g.:

image

Not particularly helpful. Overriding VersionInfo.GetEmuVersion() (or creating a new method just for Lua) you could return the local version instead. However, this is hardcoded as 2.0.0 (as mentioned earlier). This isnt such of a problem if the next main Lua changes are only going to be happening in version 3.x.x, but I dont know if that is the case.

Of course, we could just make the effort to keep VersionInfo.MainVersion updated in the codebase at every release. I'm not sure whether it is the way it is because 2.0.0 was the last big version jump, or perhaps it has just been forgotten along the way. Maybe @adelikat or @vadosnaprimer would know.

  • Running a new release build (lets say it would be 2.4.0), this would return a string:
    "Version 2.4.0"
    This is helpful.

  • Running a release build < 2.4.0:, you will get an NLua exception, eg:
    NLua.Exceptions.LuaScriptException: [string "main"]:3: attempt to call field 'getversion' (a nil value)

I don't know enough about Lua to know if this is a problem, or whether there is some easy way of suppressing errors caused by non-existing functions.

Ultimately though, you have no way of differentiating between v1.x.x clients and v2 clients up to 2.3.0 (as none of these will have the new Lua method).

Lots of variables and potential pitfalls. I'm happy to get this implemented (as it is easy), but I'd kinda like to know the most effective way of implementing it first. So we are not all wasting loads of time going back and forth :)

@brunovalads

This comment has been minimized.

Copy link
Author

commented Aug 23, 2018

Oh nice!

Ultimately though, you have no way of differentiating between v1.x.x clients and v2 clients up to 2.3.0 (as none of these will have the new Lua method).

Yea that's exactly what I thought when I was reading your reply, this feature will only be really useful in the future when older BizHawk versions are completely forgotten. So for now, the way I'm used to identify the version is the way Amaraticando did in the SMW script:

biz.features = {
  backcolor_default_arg = (emu.setislagged == nil), -- < 1.11.5
  gui_text_backcolor = (gui.DrawFinish == nil), -- < 1.11.7
  support_extra_padding = (client.SetGameExtraPadding ~= nil) and (gui.DrawFinish ~= nil), -- 1.11.7
}

So in the future, I would need to make the following:

local bizhawk_version

if client.getversion ~= nil then -- is "2.4.0" or higher
  bizhawk_version = client.getversion()
else -- 2.3.X or lower
  if emu.getregisters().H ~= nil then bizhawk_version = "2.3.0"
  elseif emu.getluacore ~= nil then bizhawk_version = "2.2.2"
  elseif memory.hash_region ~= nil then bizhawk_version = "2.2.1"
  elseif tastudio.getbranches ~= nil then bizhawk_version = "2.2.0"
  --elseif  ~= nil then bizhawk_version = "2.1.1"
  elseif forms.pictureBox ~= nil then bizhawk_version = "2.1.0"
  elseif SQL ~= nil then bizhawk_version = "2.0.1"
  elseif LuaCanvas.defaultForeground ~= nil then bizhawk_version = "2.0.0"
end

and make a few more conditionals to detect the 1.X versions as well.

@vadosnaprimer

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

Yeah even if we add this now, all the previous releases would have to use hacks like this.

@Asnivor

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

@vadosnaprimer presumably we could hardcode these hacks on the c# side, and return a version specifically for Lua.

The question is...should we..

@Asnivor

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

actually, ignore me. That wouldnt work for older versions :/

@brunovalads

This comment has been minimized.

Copy link
Author

commented Aug 23, 2018

Well, implement it now (if it's simple) and in 1 year it will be used without problems, because people wouldn't dare to use older versions (the only reasonable argument for using older versions is to finish a TAS you started there)

@Asnivor

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

@vadosnaprimer can you think of any reason why we shouldnt be manually keeping this up to date in master?

public const string Mainversion = "2.0.0"; // Use numbers only or the new version notification won't work

It makes no difference for release as this is generated at release time (as far as I can tell). But it would help from the point of view of getting the actual version from a dev build...

@vadosnaprimer

This comment has been minimized.

Copy link
Contributor

commented Aug 29, 2018

For old versions one can simply host a manually created empty file with the emu version as its name, lua checking this file's existence. Or a file called version.txt, lua reading the version from it.

@vadosnaprimer

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2018

@Asnivor since you probably have this set up already, just make a PR, and then we'll deal with manual version assigning.

@Asnivor

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2018

@vadosnaprimer

To be clear, we are going to keep this updated going forward? : 49d067a

And Lua will handle checking for a version txt file if the version <= 2.3 ?

If so, I will push a PR soon (as yes, I have a local branch somewhere with client.getversion in place)

Asnivor added a commit that referenced this issue Sep 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.