Kaynağa Gözat

LuaState removed, now ScriptSystem provides only utilities for lua-env

mikymod 12 yıl önce
ebeveyn
işleme
b76080e534
2 değiştirilmiş dosya ile 24 ekleme ve 126 silme
  1. 12 83
      src/script/ScriptSystem.cpp
  2. 12 43
      src/script/ScriptSystem.h

+ 12 - 83
src/script/ScriptSystem.cpp

@@ -1,11 +1,12 @@
+#include "Device.h"
 #include "ScriptSystem.h"
-#include "Filesystem.h"
-#include <cassert>
+
 
 namespace crown
 {
+// FIXME FIXME FIXME
+const char* ScriptSystem::BOOT_SCRIPT = "path/to/game.lua";
 
-const char* BOOT_SCRIPT = "lua/game.lua";
 
 //-----------------------------------------------------------
 // ScriptSystem
@@ -13,30 +14,11 @@ const char* BOOT_SCRIPT = "lua/game.lua";
 
 //-----------------------------------------------------------
 ScriptSystem::ScriptSystem() :
-m_state(),
-m_vec2_count(0),
-m_vec3_count(0),
-m_mat4_count(0),
-m_quat_count(0)
-{
-}
-
-//-----------------------------------------------------------
-void ScriptSystem::load(const char* script)
-{
-	assert(m_state.load_file(script) == 0);
-}
-
-//-----------------------------------------------------------
-void ScriptSystem::execute()
+	m_vec2_count(0),
+	m_vec3_count(0),
+	m_mat4_count(0),
+	m_quat_count(0)
 {
-	assert(m_state.execute() == 0);	
-}
-
-//-----------------------------------------------------------
-void ScriptSystem::unload(const char* script)
-{
-	(void*) script;
 }
 
 //-----------------------------------------------------------
@@ -129,64 +111,11 @@ uint32_t ScriptSystem::quat_used()
 	return m_quat_count;
 }
 
-//-----------------------------------------------------------
-ScriptSystem g_script;
-
-ScriptSystem* scripter()
-{
-	return &g_script;
-}
 
 //-----------------------------------------------------------
 // Lua State
 //-----------------------------------------------------------
 
-//-----------------------------------------------------------
-LuaState::LuaState()
-{
-	m_state = luaL_newstate();
-
-    luaL_openlibs(m_state);
-}
-
-//-----------------------------------------------------------
-LuaState::~LuaState()
-{
-	lua_close(m_state);
-}
-
-//-----------------------------------------------------------
-int32_t LuaState::load_buffer(const char* buf, size_t len)
-{
-	int32_t s = luaL_loadbuffer(m_state, buf, len, "");
-
-	return s;
-}
-
-//-----------------------------------------------------------
-int32_t LuaState::load_string(const char* str)
-{
-	int32_t s = luaL_loadstring(m_state, str);
-
-	return s;
-}
-
-//-----------------------------------------------------------
-int32_t LuaState::load_file(const char* file)
-{
-	int32_t s = luaL_loadfile(m_state, file);
-
-	return s;
-}
-
-//-----------------------------------------------------------
-int32_t LuaState::execute()
-{
-    int32_t s = lua_pcall(m_state, 0, LUA_MULTRET, 0);
-
-    return s;
-}
-
 //-----------------------------------------------------------
 // Extern C
 //-----------------------------------------------------------
@@ -194,25 +123,25 @@ int32_t LuaState::execute()
 //-----------------------------------------------------------
 uint32_t script_system_vec2_used()
 {
-	return scripter()->vec2_used();
+	return device()->script_system()->vec2_used();
 }
 
 //-----------------------------------------------------------
 uint32_t script_system_vec3_used()
 {
-	return scripter()->vec3_used();
+	return device()->script_system()->vec3_used();
 }
 
 //-----------------------------------------------------------
 uint32_t script_system_mat4_used()
 {
-	return scripter()->mat4_used();
+	return device()->script_system()->mat4_used();
 }
 
 //-----------------------------------------------------------
 uint32_t script_system_quat_used()
 {
-	return scripter()->quat_used();
+	return device()->script_system()->quat_used();
 }
 
 } // namespace crown

+ 12 - 43
src/script/ScriptSystem.h

@@ -14,45 +14,12 @@
 namespace crown
 {
 
-/// Abstraction of lua state.
-/// It provides 2 ways for loading lua code, as a buffer or as a string.
-/// It must be included only by ScriptSystem. 
-class LuaState
-{
-public:
-	/// Constructor, private for singleton
-								LuaState();
-	/// Destructor
-								~LuaState();
-	/// Load lua chunk as buffer
-	int32_t 					load_buffer(const char* buf, size_t len);
-	/// Load lua chunk as string
-	int32_t						load_string(const char* str);
-	/// Load lua chunk as file
-	int32_t 					load_file(const char* file);
-	/// Executes lua chunk loaded in stack
-	int32_t 					execute();
-
-private:
-
-								/// Lua state incapsulated by this class
-	lua_State*					m_state;
-};
-
-/// ScriptSystem allows to execute lua code or bytecode chunks
-/// It also provides some utilities for crown-lua environment
+/// ScriptSystem provides some utilities for crown-lua environment
 class ScriptSystem
 {
 public:
 								/// Constructor
 								ScriptSystem();
-
-								/// Loads script resource
-	void						load(const char* script);
-								/// Executes
-	void						execute();
-								/// Unloads script resource
-	void						unload(const char* script);
 								/// Returns the first free Vec2
 	Vec2&						next_vec2(float nx, float ny);
 								/// Returns the first free Vec3
@@ -68,7 +35,7 @@ public:
 								/// Returns the number of mat4 used in lua environment
 	uint32_t					mat4_used();
 								/// Returns the number of quat used in lua environment
-	uint32_t 					quat_used();
+	uint32_t					quat_used();
 
 								/// First file loaded by ScriptSystem
 	static const char*			BOOT_SCRIPT;
@@ -77,23 +44,25 @@ public:
 
 
 private:
-	LuaState 					m_state;							
 								/// Vec2 used by lua environment
 	Vec2 						m_vec2_list[MAX_TEMP_OBJECTS];
-								/// Counter which points to the next free Vec2
-	uint32_t					m_vec2_count;
 								/// Vec3 used by lua environment
 	Vec3						m_vec3_list[MAX_TEMP_OBJECTS];
-								/// Counter which points to the next free Vec3
-	uint32_t					m_vec3_count;
 								/// Mat4 used by lua environment
 	Mat4						m_mat4_list[MAX_TEMP_OBJECTS];
-								/// Counter which points to the next free Mat4
-	uint32_t					m_mat4_count;
 								/// Quaternions used by lua environment
 	Quat						m_quat_list[MAX_TEMP_OBJECTS];
-								/// Counter which points to the nect free Quat
+
+								/// Counter which points to the next free Vec2
+	uint32_t					m_vec2_count;
+								/// Counter which points to the next free Vec3
+	uint32_t					m_vec3_count;
+								/// Counter which points to the next free Mat4
+	uint32_t					m_mat4_count;
+								/// Counter which points to the next free Quat
 	uint32_t					m_quat_count;
+
+
 };