Support lovr /path/to/game;

This commit is contained in:
bjorn 2016-08-08 13:51:22 -07:00
parent beacc9d287
commit bbc2a32937
5 changed files with 17 additions and 7 deletions

View File

@ -37,13 +37,13 @@ int lovrGraphicsSetClearColor(lua_State* L) {
float r = luaL_checknumber(L, 1);
float g = luaL_checknumber(L, 2);
float b = luaL_checknumber(L, 3);
float a = 1.0;
float a = 255.0;
if (lua_gettop(L) == 4) {
a = luaL_checknumber(L, 4);
}
glClearColor(r, g, b, a);
glClearColor(r / 255, g / 255, b / 255, a / 255);
return 0;
}

View File

@ -4,6 +4,8 @@
int lovrGraphicsClear(lua_State* L);
int lovrGraphicsPresent(lua_State* L);
int lovrGraphicsGetClearColor(lua_State* L);
int lovrGraphicsSetClearColor(lua_State* L);
int lovrGraphicsSetShader(lua_State* L);
int lovrGraphicsNewModel(lua_State* L);
int lovrGraphicsNewBuffer(lua_State* L);

View File

@ -74,10 +74,18 @@ void lovrDestroy() {
exit(EXIT_SUCCESS);
}
void lovrRun(lua_State* L) {
void lovrRun(lua_State* L, char* root) {
// Construct path to main.lua based on command line argument
char path[512];
if (root) {
snprintf(path, sizeof(path), "%s/main.lua", root);
} else {
snprintf(path, sizeof(path), "main.lua");
}
// Run "main.lua" which will override/define pieces of lovr
if (luaL_dofile(L, "main.lua")) {
if (luaL_dofile(L, path)) {
error("Failed to run main.lua");
lua_pop(L, 1);
exit(EXIT_FAILURE);

View File

@ -5,7 +5,7 @@
void lovrInit(lua_State* L);
void lovrDestroy();
void lovrRun(lua_State* L);
void lovrRun(lua_State* L, char* mainPath);
int lovrOnLuaError(lua_State* L);
void lovrOnGlfwError(int code, const char* description);
void lovrOnClose(GLFWwindow* window);

View File

@ -3,13 +3,13 @@
lua_State* L;
int main(int argc, char* argv[]) {
int main(int argc, char** argv) {
L = luaL_newstate();
luaL_openlibs(L);
initGlfw(lovrOnGlfwError, lovrOnClose);
lovrInit(L);
lovrRun(L);
lovrRun(L, argc > 1 ? argv[1] : NULL);
return 0;
}