Преглед на файлове

replace LuaStack with lua_State* in LuaEnvironment

mikymod преди 12 години
родител
ревизия
3cf27d03e0
променени са 2 файла, в които са добавени 26 реда и са изтрити 19 реда
  1. 15 15
      src/lua/LuaEnvironment.cpp
  2. 11 4
      src/lua/LuaEnvironment.h

+ 15 - 15
src/lua/LuaEnvironment.cpp

@@ -35,10 +35,10 @@ namespace crown
 
 //-----------------------------------------------------------------------------
 LuaEnvironment::LuaEnvironment(lua_State* L) :
-	m_stack(L)
+	m_state(L)
 {
 	// Open Lua default libraries
-	luaL_openlibs(m_stack.state());
+	luaL_openlibs(m_state);
 
 	string::strncpy(m_error_buffer, "", 1024);
 
@@ -46,22 +46,22 @@ LuaEnvironment::LuaEnvironment(lua_State* L) :
 }
 
 //-----------------------------------------------------------------------------
-void LuaEnvironment::init()
+void LuaEnvironment::create()
 {
 	// Open Crown library
-	lua_cpcall(m_stack.state(), luaopen_libcrown, NULL);
+	lua_cpcall(m_state, luaopen_libcrown, NULL);
 }
 
 //-----------------------------------------------------------------------------
-void LuaEnvironment::shutdown()
+void LuaEnvironment::destroy()
 {
-	lua_close(m_stack.state());
+	lua_close(m_state);
 }
 
 //-----------------------------------------------------------------------------
-LuaStack LuaEnvironment::stack()
+lua_State* LuaEnvironment::state()
 {
-	return m_stack;
+	return m_state;
 }
 
 //-----------------------------------------------------------------------------
@@ -77,7 +77,7 @@ const char* LuaEnvironment::error()
 //-----------------------------------------------------------------------------
 void LuaEnvironment::load_buffer(const char* buffer, size_t len)
 {
-	int32_t loaded = luaL_loadbuffer(m_stack.state(), buffer, len, "");
+	int32_t loaded = luaL_loadbuffer(m_state, buffer, len, "");
 
 	if (loaded != 0)
 	{
@@ -88,7 +88,7 @@ void LuaEnvironment::load_buffer(const char* buffer, size_t len)
 //-----------------------------------------------------------------------------
 void LuaEnvironment::load_file(const char* file)
 {
-	int32_t loaded = luaL_loadfile(m_stack.state(), file);
+	int32_t loaded = luaL_loadfile(m_state, file);
 
 	if (loaded != 0)
 	{
@@ -99,7 +99,7 @@ void LuaEnvironment::load_file(const char* file)
 //-----------------------------------------------------------------------------
 void LuaEnvironment::load_string(const char* str)
 {
-	int32_t loaded = luaL_loadstring(m_stack.state(), str);
+	int32_t loaded = luaL_loadstring(m_state, str);
 
 	if (loaded != 0)
 	{
@@ -110,13 +110,13 @@ void LuaEnvironment::load_string(const char* str)
 //-----------------------------------------------------------------------------
 void LuaEnvironment::get_global_symbol(const char* symbol)
 {
-	lua_getglobal(m_stack.state(), symbol);
+	lua_getglobal(m_state, symbol);
 }
 
 //-----------------------------------------------------------------------------
 void LuaEnvironment::execute(int32_t args, int32_t results)
 {
-	int32_t executed = lua_pcall(m_stack.state(), args, results, 0);
+	int32_t executed = lua_pcall(m_state, args, results, 0);
 
 	if (executed != 0)
 	{
@@ -129,7 +129,7 @@ void LuaEnvironment::lua_error()
 {
 	string::strncpy(m_error_buffer, "", 1024);
 
-	string::strncpy(m_error_buffer, lua_tostring(m_stack.state(), -1), 1024);
+	string::strncpy(m_error_buffer, lua_tostring(m_state, -1), 1024);
 }
 
 //-----------------------------------------------------------------------------
@@ -143,7 +143,7 @@ void LuaEnvironment::load_module_function(const char* module, const char* name,
 	entry[1].name = NULL;
 	entry[1].func = NULL;
 
-	luaL_register(m_stack.state(), module, entry);
+	luaL_register(m_state, module, entry);
 }
 
 //-----------------------------------------------------------------------------

+ 11 - 4
src/lua/LuaEnvironment.h

@@ -50,13 +50,13 @@ public:
 	/// Constructor
 					LuaEnvironment(lua_State* L);
 
-	LuaStack		stack();
+	lua_State*		state();
 
 	const char*		error();
 
-	void			init();
+	void			create();
 
-	void			shutdown();
+	void			destroy();
 
 	void			load_buffer(const char* buffer, size_t len);
 
@@ -68,6 +68,12 @@ public:
 
 	void			execute(int32_t args, int32_t results);
 
+	void			init();
+
+	void			shutdown();
+
+	void			frame(float dt);
+
 //-----------------------------------------------------------------------------
 
 	/// Load a function to proper module
@@ -82,13 +88,14 @@ private:
 
 private:
 
-	LuaStack		m_stack;
+	lua_State*		m_state;
 
 	char			m_error_buffer[1024];
 
 	char			m_tmp_buffer[1024];
 };
 
+
 void load_int_setting(LuaEnvironment& env);
 void load_float_setting(LuaEnvironment& env);
 void load_string_setting(LuaEnvironment& env);