-
Notifications
You must be signed in to change notification settings - Fork 1
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
Simplify engine version requirement method #5
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ static int kiavc_lua_method_kiavcrequire(lua_State *s); | |
static int kiavc_lua_method_getversion(lua_State *s); | ||
/* Return version string */ | ||
static int kiavc_lua_method_getversionstring(lua_State *s); | ||
/* Require version as major, minor, patch */ | ||
static int kiavc_lua_method_requireversion(lua_State *s); | ||
/* Logging, to use the same SDL-based logging as the rest of the application */ | ||
static int kiavc_lua_method_kiavclog(lua_State *s); | ||
/* Error logging, to use the same SDL-based logging as the rest of the application */ | ||
|
@@ -313,6 +315,7 @@ int kiavc_scripts_load(const char *path, const kiavc_scripts_callbacks *callback | |
lua_register(lua_state, "kiavcRequire", kiavc_lua_method_kiavcrequire); | ||
lua_register(lua_state, "getVersion", kiavc_lua_method_getversion); | ||
lua_register(lua_state, "getVersionString", kiavc_lua_method_getversionstring); | ||
lua_register(lua_state, "requireVersion", kiavc_lua_method_requireversion); | ||
lua_register(lua_state, "kiavcLog", kiavc_lua_method_kiavclog); | ||
lua_register(lua_state, "kiavcError", kiavc_lua_method_kiavcerror); | ||
lua_register(lua_state, "kiavcWarn", kiavc_lua_method_kiavcwarn); | ||
|
@@ -556,6 +559,36 @@ static int kiavc_lua_method_getversionstring(lua_State *s) { | |
return 1; | ||
} | ||
|
||
/* Require version as major, minor, patch */ | ||
static int kiavc_lua_method_requireversion(lua_State *s) { | ||
/* This method allows the Lua script to check whether the engine is of a compatible version (and quit if not) */ | ||
int n = lua_gettop(s), exp = 3; | ||
if(n != exp) { | ||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[Lua] Wrong number of arguments in requireVersion: %d (expected %d)\n", n, exp); | ||
kiavc_cb->quit(); | ||
return 0; | ||
} | ||
int major = luaL_checknumber(s, 1); | ||
if(major != KIAVC_VERSION_MAJOR) { | ||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[Lua] KIAVC major version number incompatible: %d (expected %d)\n", KIAVC_VERSION_MAJOR, major); | ||
kiavc_cb->quit(); | ||
return 0; | ||
} | ||
int minor = luaL_checknumber(s, 2); | ||
if(minor > KIAVC_VERSION_MINOR) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get the SemVer reference you made, but I think it can cause ambiguity if someone is interested in a specific version. Maybe there could be different checks, where one checks if the version is exactly that, and another one if it is at least that (which could loosen the check on the major version as well). We could even just keep the "exact version" check, and leave more flexible checks to the application (using the getters for the three version numbers that exist). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't want to loosen the major version in a minimum requirement, because that number is meant to signal breaking API changes that are not backwards-compatible. My proposed solution is to have two formats, like you said, one being the exact one (now |
||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[Lua] KIAVC minor version number too low: %d (expected %d)\n", KIAVC_VERSION_MINOR, minor); | ||
kiavc_cb->quit(); | ||
return 0; | ||
} | ||
int patch = luaL_checknumber(s, 3); | ||
if(patch > KIAVC_VERSION_PATCH) { | ||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "[Lua] KIAVC patch version number too low: %d (expected %d)\n", KIAVC_VERSION_PATCH, patch); | ||
kiavc_cb->quit(); | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
|
||
/* Logging, to use the same SDL-based logging as the rest of the application */ | ||
static int kiavc_lua_method_kiavclog(lua_State *s) { | ||
/* This method allows the Lua script to use the Janus internal logger */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems wrong in this checks and the ones below? Looks like you're using spaces instead of tabs (which I'd rather we use in this project, since it's what I'm used to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm used to the opposite, so I didn't notice, but it's fixed now.