2
0
Daniele Bartolini 10 жил өмнө
parent
commit
382ae1af23

+ 3 - 0
docs/lua_api.txt

@@ -737,6 +737,9 @@ ResourcePackage
 Device
 ======
 
+	**argv** () : table
+		Returns a table containing the command line parameters the engine was started with.
+
 	**platform** () : string
 		Returns a string identifying what platform the engine is running on.
 		It can be either ``android``, ``linux`` or ``windows``

+ 6 - 6
src/device.cpp

@@ -409,17 +409,17 @@ UnitManager* Device::unit_manager()
 void Device::read_config()
 {
 	TempAllocator4096 ta;
-	DynamicString project_path(ta);
+	DynamicString boot_dir(ta);
 
-	if (_device_options.project() != NULL)
+	if (_device_options.boot_dir() != NULL)
 	{
-		project_path += _device_options.project();
-		project_path += '/';
+		boot_dir += _device_options.boot_dir();
+		boot_dir += '/';
 	}
 
-	project_path += CROWN_BOOT_CONFIG;
+	boot_dir += CROWN_BOOT_CONFIG;
 
-	const StringId64 config_name(project_path.c_str());
+	const StringId64 config_name(boot_dir.c_str());
 
 	_resource_manager->load(CONFIG_TYPE, config_name);
 	_resource_manager->flush();

+ 6 - 0
src/device.h

@@ -83,6 +83,12 @@ public:
 	/// Shutdowns the engine freeing all the allocated resources.
 	void shutdown();
 
+	/// Returns the number of command line parameters.
+	int argc() const { return _device_options.argc(); }
+
+	/// Returns command line parameters.
+	const char** argv() const { return _device_options.argv(); }
+
 	/// Returns a string identifying what platform the engine is running on.
 	const char* platform() const { return CROWN_PLATFORM_NAME; }
 

+ 4 - 5
src/device_options.cpp

@@ -32,7 +32,7 @@ static void help(const char* msg = NULL)
 		"\nAvailable only in debug and development builds:\n\n"
 
 		"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
-		"  --project <name>           Start the project <name>.\n"
+		"  --boot-dir <path>          Boot the engine with the 'boot.config' from given <path>.\n"
 		"  --compile                  Do a full compile of the resources.\n"
 		"  --platform <platform>      Compile resources for the given <platform>.\n"
 		"      Possible values for <platform> are:\n"
@@ -49,7 +49,7 @@ DeviceOptions::DeviceOptions(int argc, char** argv)
 	, _argv(argv)
 	, _source_dir(NULL)
 	, _bundle_dir(NULL)
-	, _project(NULL)
+	, _boot_dir(NULL)
 	, _platform(NULL)
 	, _wait_console(false)
 	, _do_compile(false)
@@ -115,7 +115,7 @@ int DeviceOptions::parse()
 
 	_do_continue = cl.has_argument("continue");
 
-	_project = cl.get_parameter("project");
+	_boot_dir = cl.get_parameter("boot-dir");
 	_wait_console = cl.has_argument("wait-console");
 
 	const char* parent = cl.get_parameter("parent-window");
@@ -133,5 +133,4 @@ int DeviceOptions::parse()
 	return EXIT_SUCCESS;
 }
 
-}
-
+} // namespace crown

+ 4 - 2
src/device_options.h

@@ -25,7 +25,7 @@ class DeviceOptions
 	char** _argv;
 	const char* _source_dir;
 	const char* _bundle_dir;
-	const char* _project;
+	const char* _boot_dir;
 	const char* _platform;
 	bool _wait_console;
 	bool _do_compile;
@@ -49,9 +49,11 @@ public:
 	/// EXIT_SUCCESS if no error is found.
 	int parse();
 
+	int argc() const { return _argc; }
+	const char** argv() const { return (const char**)_argv; }
 	const char* source_dir() const { return _source_dir; }
 	const char* bundle_dir() const { return _bundle_dir; }
-	const char* project() const { return _project; }
+	const char* boot_dir() const { return _boot_dir; }
 	const char* platform() const { return _platform; }
 	bool wait_console() const { return _wait_console; }
 	bool do_compile() const { return _do_compile; }

+ 16 - 0
src/lua/lua_api.cpp

@@ -2240,6 +2240,21 @@ static int sound_world_tostring(lua_State* L)
 	return 1;
 }
 
+static int device_argv(lua_State* L)
+{
+	LuaStack stack(L);
+	const int argc = device()->argc();
+	const char** argv = device()->argv();
+	stack.push_table(argc);
+	for (int i = 0; i < argc; ++i)
+	{
+		stack.push_key_begin(i + 1);
+		stack.push_string(argv[i]);
+		stack.push_key_end();
+	}
+	return 1;
+}
+
 static int device_platform(lua_State* L)
 {
 	LuaStack stack(L);
@@ -3030,6 +3045,7 @@ void load_api(LuaEnvironment& env)
 	env.load_module_function("SoundWorld", "__index",    "SoundWorld");
 	env.load_module_function("SoundWorld", "__tostring", sound_world_tostring);
 
+	env.load_module_function("Device", "argv",                     device_argv);
 	env.load_module_function("Device", "platform",                 device_platform);
 	env.load_module_function("Device", "architecture",             device_architecture);
 	env.load_module_function("Device", "version",                  device_version);