Ver código fonte

Add Device::argc()/argv() to C++ API and Device.argv() to Lua API

Daniele Bartolini 12 anos atrás
pai
commit
13996ad4ce
5 arquivos alterados com 40 adições e 3 exclusões
  1. 4 0
      engine/Device.cpp
  2. 12 0
      engine/Device.h
  3. 21 0
      engine/lua/LuaDevice.cpp
  4. 3 0
      engine/os/linux/main.cpp
  5. 0 3
      engine/os/win/main.cpp

+ 4 - 0
engine/Device.cpp

@@ -71,6 +71,10 @@ namespace crown
 //-----------------------------------------------------------------------------
 Device::Device()
 	: m_allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
+	
+	, m_argc(0)
+	, m_argv(NULL)
+
 	, m_is_init(false)
 	, m_is_running(false)
 	, m_is_paused(false)

+ 12 - 0
engine/Device.h

@@ -68,6 +68,15 @@ public:
 	/// Shutdowns the engine freeing all the allocated resources
 	void					shutdown();
 
+	/// Returns the number of command line arguments passed to
+	/// the engine executable.
+	int32_t					argc() const { return m_argc; }
+
+	/// Returns the string value of the command line arguments passed
+	/// to the engine executable.
+	/// The size of the returned array is given by Device::argc().
+	const char**			argv() const { return (const char**) m_argv; }
+
 	/// Returns wheter the engine is running (i.e. it is actually
 	/// doing work).
 	bool					is_running() const;
@@ -145,6 +154,9 @@ protected:
 	// Used to allocate all subsystems
 	LinearAllocator			m_allocator;
 
+	int32_t					m_argc;
+	char**					m_argv;
+
 	// Preferred settings
 	char					m_source_dir[MAX_PATH_LENGTH];
 	char 					m_bundle_dir[MAX_PATH_LENGTH];

+ 21 - 0
engine/lua/LuaDevice.cpp

@@ -33,6 +33,26 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int device_argv(lua_State* L)
+{
+	LuaStack stack(L);
+
+	const int32_t argc = device()->argc();
+	const char** argv = device()->argv();
+
+	stack.push_table();
+	for (int32_t i = 0; i < argc; i++)
+	{
+		// Be friendly to Lua's one-indexed arrays
+		stack.push_key_begin(i + 1);
+			stack.push_string(argv[i]);
+		stack.push_key_end();
+	}
+
+	return 1;
+}
+
 //-----------------------------------------------------------------------------
 CE_EXPORT int device_frame_count(lua_State* L)
 {
@@ -131,6 +151,7 @@ CE_EXPORT int device_destroy_resource_package(lua_State* L)
 //-----------------------------------------------------------------------------
 void load_device(LuaEnvironment& env)
 {
+	env.load_module_function("Device", "argv",                     device_argv);
 	env.load_module_function("Device", "frame_count",              device_frame_count);
 	env.load_module_function("Device", "last_delta_time",          device_last_delta_time);
 	env.load_module_function("Device", "start",                    device_start);

+ 3 - 0
engine/os/linux/main.cpp

@@ -165,6 +165,9 @@ public:
 		#endif
 
 		read_configuration();
+
+		m_argc = argc;
+		m_argv = argv;
 	}
 
 	//-----------------------------------------------------------------------------

+ 0 - 3
engine/os/win/main.cpp

@@ -871,9 +871,6 @@ public:
 	bool m_started;
 	bool m_exit;
 
-	int32_t m_argc;
-	char**	m_argv;
-
 	uint32_t m_parent_window_handle;
 	int32_t m_fullscreen;
 	int32_t m_compile;