|
|
@@ -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
|