summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io/io_task.cpp
blob: 72031758007b70584ce287712b4bfc0f3c77b33f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "file_system.h"
#include "io_task.h"

#include <iostream>

using namespace AEScripting;
using namespace Luax;

namespace AsuraEngine
{
	namespace IO
	{

		IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type)
			: mPath(path)
			, mBuffer(buffer)
		{
		}

		IOTask::~IOTask()
		{
		}

		bool IOTask::Execute()
		{
			File file(mPath);
			if (mType == IOTASK_TYPE_WRITE)
			{

			}
			// pathȡݱmBuffer
			else if (mType == IOTASK_TYPE_READ)
			{
				file.Open(File::FILE_MODE_READ);
				file.ReadAll(mBuffer);
				file.Close();
			}
			return true;
		}

		void IOTask::Invoke()
		{
			if (mCallback)
			{
				LuaxScopedState state(LuaEnv::Get()->GetMainState());
				if (PushLuaxMemberRef(state, mCallback))
				{
					PushLuaxMemberRef(state, mBufferRef);
					state.Call(1, 0);
				}
			}
		}

	}
}