2015-07-28 23:32:02 +02:00
|
|
|
#include "lua_script_manager.h"
|
|
|
|
|
2016-05-10 08:24:31 +02:00
|
|
|
#include "engine/crc32.h"
|
|
|
|
#include "engine/log.h"
|
|
|
|
#include "engine/fs/file_system.h"
|
2015-07-28 23:32:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace Lumix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2016-07-25 01:02:36 +02:00
|
|
|
LuaScript::LuaScript(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
|
2015-07-28 23:32:02 +02:00
|
|
|
: Resource(path, resource_manager, allocator)
|
|
|
|
, m_source_code(allocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-02 11:57:20 +02:00
|
|
|
LuaScript::~LuaScript()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-03 01:14:38 +02:00
|
|
|
void LuaScript::unload()
|
2015-07-28 23:32:02 +02:00
|
|
|
{
|
2015-08-28 17:31:20 +02:00
|
|
|
m_source_code = "";
|
2015-07-28 23:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool isWhitespace(char c)
|
|
|
|
{
|
|
|
|
return c == ' ' || c == '\n' || c == '\t' || c == '\r';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-19 00:14:16 +02:00
|
|
|
static const char* getToken(const char* src, char* dest, int size)
|
2015-07-28 23:32:02 +02:00
|
|
|
{
|
|
|
|
const char* in = src;
|
|
|
|
char* out = dest;
|
|
|
|
--size;
|
|
|
|
while (*in && isWhitespace(*in))
|
|
|
|
{
|
|
|
|
++in;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*in && !isWhitespace(*in) && size)
|
|
|
|
{
|
|
|
|
*out = *in;
|
|
|
|
++out;
|
|
|
|
++in;
|
|
|
|
--size;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
2015-10-19 00:14:16 +02:00
|
|
|
return in;
|
2015-07-28 23:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-03 01:14:38 +02:00
|
|
|
bool LuaScript::load(FS::IFile& file)
|
2015-07-28 23:32:02 +02:00
|
|
|
{
|
2015-10-03 01:14:38 +02:00
|
|
|
m_source_code.set((const char*)file.getBuffer(), (int)file.size());
|
|
|
|
m_size = file.size();
|
|
|
|
return true;
|
2015-07-28 23:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LuaScriptManager::LuaScriptManager(IAllocator& allocator)
|
|
|
|
: ResourceManagerBase(allocator)
|
|
|
|
, m_allocator(allocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LuaScriptManager::~LuaScriptManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Resource* LuaScriptManager::createResource(const Path& path)
|
|
|
|
{
|
2016-07-25 01:02:36 +02:00
|
|
|
return LUMIX_NEW(m_allocator, LuaScript)(path, *this, m_allocator);
|
2015-07-28 23:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaScriptManager::destroyResource(Resource& resource)
|
|
|
|
{
|
2015-11-11 23:25:44 +01:00
|
|
|
LUMIX_DELETE(m_allocator, static_cast<LuaScript*>(&resource));
|
2015-07-28 23:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Lumix
|