Kaynağa Gözat

Pass LuaResource directly

Daniele Bartolini 11 yıl önce
ebeveyn
işleme
2886913b98
2 değiştirilmiş dosya ile 13 ekleme ve 32 silme
  1. 5 19
      engine/lua/lua_environment.cpp
  2. 8 13
      engine/lua/lua_environment.h

+ 5 - 19
engine/lua/lua_environment.cpp

@@ -24,16 +24,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include <stdarg.h>
 
-#include "lua_environment.h"
+#include "config.h"
 #include "assert.h"
-#include "string_utils.h"
+#include "lua_environment.h"
 #include "lua_stack.h"
-#include "device.h"
 #include "lua_resource.h"
-#include "resource_manager.h"
-#include "config.h"
+#include <stdarg.h>
 
 namespace crown
 {
@@ -47,22 +44,11 @@ LuaEnvironment::LuaEnvironment(lua_State* L)
 }
 
 //-----------------------------------------------------------------------------
-void LuaEnvironment::load_and_execute(const char* res_name)
+void LuaEnvironment::execute(const LuaResource* lr)
 {
-	ResourceManager* resman = device()->resource_manager();
-
-	// Load the resource
-	const ResourceId res_id("lua", res_name);
-	resman->load(res_id);
-	resman->flush();
-	LuaResource* lr = (LuaResource*) resman->get(res_id);
-
 	lua_pushcfunction(m_L, lua_system::error_handler);
-	luaL_loadbuffer(m_L, (const char*) lr->program(), lr->size(), res_name);
+	luaL_loadbuffer(m_L, (const char*) lr->program(), lr->size(), "<unknown>");
 	lua_pcall(m_L, 0, 0, -2);
-
-	// Unloading is OK since the script data has been copied to Lua
-	resman->unload(res_id);
 }
 
 //-----------------------------------------------------------------------------

+ 8 - 13
engine/lua/lua_environment.h

@@ -26,13 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "lua.hpp"
 #include "config.h"
 #include "types.h"
 #include "macros.h"
-
-// HACK
-#include "math_types.h"
+#include "math_types.h" // HACK
+#include "lua.hpp"
 
 namespace crown
 {
@@ -49,14 +47,11 @@ struct Unit;
 
 /// LuaEnvironment is a wrapper of a subset of Lua functions and
 /// provides utilities for extending Lua
-class LuaEnvironment
+struct LuaEnvironment
 {
-public:
-
 	LuaEnvironment(lua_State* L);
 
-	/// Loads and execute the given @a res_name Lua resource.
-	void load_and_execute(const char* res_name);
+	void execute(const LuaResource* lr);
 
 	/// Loads and executes the given @a s lua string.
 	void execute_string(const char* s);
@@ -82,13 +77,13 @@ public:
 
 private:
 
-	// Disable copying
-	LuaEnvironment(const LuaEnvironment&);
-	LuaEnvironment& operator=(const LuaEnvironment&);
+	lua_State* m_L;
 
 private:
 
-	lua_State* m_L;
+	// Disable copying
+	LuaEnvironment(const LuaEnvironment&);
+	LuaEnvironment& operator=(const LuaEnvironment&);
 };
 
 } // namespace crown