Ver Fonte

remove lua_State in LuaEnvironment constructor

mikymod há 12 anos atrás
pai
commit
052d08fa18
3 ficheiros alterados com 26 adições e 28 exclusões
  1. 1 3
      src/Device.cpp
  2. 3 2
      src/lua/LuaEnvironment.cpp
  3. 22 23
      src/lua/LuaEnvironment.h

+ 1 - 3
src/Device.cpp

@@ -469,9 +469,7 @@ void Device::create_debug_renderer()
 //-----------------------------------------------------------------------------
 void Device::create_lua_environment()
 {
-	lua_State* L = luaL_newstate();
-
-	m_lua_environment = CE_NEW(m_allocator, LuaEnvironment)(L);
+	m_lua_environment = CE_NEW(m_allocator, LuaEnvironment)();
 
 	m_lua_environment->create();
 

+ 3 - 2
src/lua/LuaEnvironment.cpp

@@ -34,8 +34,9 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-LuaEnvironment::LuaEnvironment(lua_State* L) :
-	m_state(L)
+LuaEnvironment::LuaEnvironment() :
+	m_state(luaL_newstate())
+
 {
 	// Open Lua default libraries
 	luaL_openlibs(m_state);

+ 22 - 23
src/lua/LuaEnvironment.h

@@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Config.h"
 #include "LuaStack.h"
+#include "LinearAllocator.h"
 
 #ifdef WINDOWS
 	#define CE_EXPORT extern "C" __declspec(dllexport)
@@ -48,51 +49,49 @@ class LuaEnvironment
 
 public:
 	/// Constructor
-					LuaEnvironment(lua_State* L);
+						LuaEnvironment();
 
-	lua_State*		state();
+	lua_State*			state();
 
-	const char*		error();
+	const char*			error();
 
-	void			create();
+	void				create();
 
-	void			destroy();
+	void				destroy();
 
-	void			load_buffer(const char* buffer, size_t len);
+	void				load_buffer(const char* buffer, size_t len);
 
-	void			load_file(const char* file);
+	void				load_file(const char* file);
 
-	void 			load_string(const char* str);
+	void 				load_string(const char* str);
 
-	void			get_global_symbol(const char* symbol);
+	void				get_global_symbol(const char* symbol);
 
-	void			execute(int32_t args, int32_t results);
-
-	void			init();
+	/// Load a function to proper module
+	void				load_module_function(const char* module, const char* name, const lua_CFunction func);
 
-	void			shutdown();
+	void				execute(int32_t args, int32_t results);
 
-	void			frame(float dt);
+	void				init();
 
-//-----------------------------------------------------------------------------
+	void				shutdown();
 
-	/// Load a function to proper module
-	void			load_module_function(const char* module, const char* name, const lua_CFunction func);
+	void				frame(float dt);
 
 private:
 
-	void			lua_error();
+	void				lua_error();
 	// Disable copying
-					LuaEnvironment(const LuaEnvironment&);
-	LuaEnvironment& operator=(const LuaEnvironment&);
+						LuaEnvironment(const LuaEnvironment&);
+	LuaEnvironment& 	operator=(const LuaEnvironment&);
 
 private:
 
-	lua_State*		m_state;
+	lua_State*			m_state;
 
-	char			m_error_buffer[1024];
+	char				m_error_buffer[1024];
 
-	char			m_tmp_buffer[1024];
+	char				m_tmp_buffer[1024];
 };