version/os refactor;

This commit is contained in:
bjorn 2018-09-26 21:45:45 -07:00 committed by Bjorn Swenson
parent cee3c28f4e
commit 3e2259fc99
5 changed files with 23 additions and 40 deletions

View File

@ -1,23 +1,26 @@
#include "api.h"
#include "lovr.h"
#include "version.h"
#include "resources/logo.png.h"
static int l_lovrGetOS(lua_State* L) {
const char* os = lovrGetOS();
if (os) {
lua_pushstring(L, os);
} else {
lua_pushnil(L);
}
#ifdef _WIN32
lua_pushstring(L, "Windows");
#elif __APPLE__
lua_pushstring(L, "macOS");
#elif EMSCRIPTEN
lua_pushstring(L, "Web");
#elif __linux__
lua_pushstring(L, "Linux");
#else
lua_pushnil(L);
#endif
return 1;
}
static int l_lovrGetVersion(lua_State* L) {
int major, minor, patch;
lovrGetVersion(&major, &minor, &patch);
lua_pushinteger(L, major);
lua_pushinteger(L, minor);
lua_pushinteger(L, patch);
lua_pushinteger(L, LOVR_VERSION_MAJOR);
lua_pushinteger(L, LOVR_VERSION_MINOR);
lua_pushinteger(L, LOVR_VERSION_PATCH);
return 3;
}

View File

@ -110,23 +110,3 @@ bool lovrRun(int argc, char** argv, int* status) {
void lovrQuit(int status) {
lovrEventPush((Event) { .type = EVENT_QUIT, .data.quit = { false, status } });
}
const char* lovrGetOS() {
#ifdef _WIN32
return "Windows";
#elif __APPLE__
return "macOS";
#elif EMSCRIPTEN
return "Web";
#elif __linux__
return "Linux";
#else
return NULL;
#endif
}
void lovrGetVersion(int* major, int* minor, int* patch) {
*major = LOVR_VERSION_MAJOR;
*minor = LOVR_VERSION_MINOR;
*patch = LOVR_VERSION_PATCH;
}

View File

@ -1,11 +1,4 @@
#include <stdbool.h>
#define LOVR_VERSION_MAJOR 0
#define LOVR_VERSION_MINOR 11
#define LOVR_VERSION_PATCH 0
#define LOVR_VERSION_ALIAS "Ginormous Giraffe"
bool lovrRun(int argc, char** argv, int* status);
void lovrQuit(int status);
const char* lovrGetOS();
void lovrGetVersion(int* major, int* minor, int* patch);

View File

@ -1,10 +1,11 @@
#include "lovr.h"
#include "version.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv) {
if (argc > 1 && !strcmp(argv[1], "--version")) {
if (argc > 1 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))) {
printf("LOVR %d.%d.%d (%s)\n", LOVR_VERSION_MAJOR, LOVR_VERSION_MINOR, LOVR_VERSION_PATCH, LOVR_VERSION_ALIAS);
exit(0);
}

6
src/version.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#define LOVR_VERSION_MAJOR 0
#define LOVR_VERSION_MINOR 11
#define LOVR_VERSION_PATCH 0
#define LOVR_VERSION_ALIAS "Ginormous Giraffe"