Browse Source

Merge pull request #1857 from premek/help-option

print usage when there is no game and when --help option is used
slime73 2 years ago
parent
commit
3228a3b436
2 changed files with 33 additions and 0 deletions
  1. 22 0
      src/love.cpp
  2. 11 0
      src/modules/love/boot.lua

+ 22 - 0
src/love.cpp

@@ -141,6 +141,21 @@ enum DoneAction
 	DONE_RESTART,
 	DONE_RESTART,
 };
 };
 
 
+static void print_usage()
+{
+    // when editing this message, change it at boot.lua too
+    printf("LÖVE is an *awesome* framework you can use to make 2D games in Lua\n"
+        "https://love2d.org\n"
+        "\n"
+        "usage:\n"
+        "    love --version                  prints LÖVE version and quits\n"
+        "    love --help                     prints this message and quits\n"
+        "    love path/to/gamedir            runs the game from the given directory which contains a main.lua file\n"
+        "    love path/to/packagedgame.love  runs the packaged game from the provided .love file\n"
+        "    love path/to/file.lua           runs the game from the given .lua file\n"
+        );
+}
+
 static DoneAction runlove(int argc, char **argv, int &retval, love::Variant &restartvalue)
 static DoneAction runlove(int argc, char **argv, int &retval, love::Variant &restartvalue)
 {
 {
 	// Oh, you just want the version? Okay!
 	// Oh, you just want the version? Okay!
@@ -155,6 +170,13 @@ static DoneAction runlove(int argc, char **argv, int &retval, love::Variant &res
 		return DONE_QUIT;
 		return DONE_QUIT;
 	}
 	}
 
 
+	if (argc > 1 && strcmp(argv[1], "--help") == 0)
+	{
+		print_usage();
+		retval = 0;
+		return DONE_QUIT;
+	}
+
 	// Create the virtual machine.
 	// Create the virtual machine.
 	lua_State *L = luaL_newstate();
 	lua_State *L = luaL_newstate();
 	luaL_openlibs(L);
 	luaL_openlibs(L);

+ 11 - 0
src/modules/love/boot.lua

@@ -135,6 +135,17 @@ function love.boot()
 	end
 	end
 
 
 	if not can_has_game then
 	if not can_has_game then
+        -- when editing this message, change it at love.cpp too
+        print([[LÖVE is an *awesome* framework you can use to make 2D games in Lua
+https://love2d.org
+
+usage:
+    love --version                  prints LÖVE version and quits
+    love --help                     prints this message and quits
+    love path/to/gamedir            runs the game from the given directory which contains a main.lua file
+    love path/to/packagedgame.love  runs the packaged game from the provided .love file
+    love path/to/file.lua           runs the game from the given .lua file
+]]);
 		local nogame = require("love.nogame")
 		local nogame = require("love.nogame")
 		nogame()
 		nogame()
 	end
 	end