summaryrefslogtreecommitdiff
path: root/source/tests/05-physfs/main.cpp
blob: b547f1f6a3f73dfead11f999eee6fd8ade48cfed (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <string>

#include <asura-lib-utils/utils.h>

using namespace std;
using namespace AEScripting;

string code = R"(
local thread = nil
local dst = nil
function main() 
	local suc = Filesystem.Init(arg0)
	print(suc)
	suc = Filesystem.Mount("./", "root", true)
	print(suc)
	Filesystem.SetWriteDirectory("./")
	local databuffer = DataBuffer.New(1024)
	local str = "hello, world"
	databuffer:Refactor(#str)
	databuffer:Load(str)
	local file = Filesystem.CreateFile("physfs.txt")
	file:Open(EFileMode.WRITE)
	file:Write(databuffer)
	file:Close()
	print(file:GetFileName())
	print(file:GetExtension())
	print(file:GetName())

	dst = DataBuffer.New(138567) 
	thread = Thread.New("IO thread")
	local content = ""
	local cont = "ok"
	local task = IOTask.New("root/physfs2.txt", dst, EIOTaskType.READ, function(db)
		function _r() 
			print("test..............")
			local c = db:GetData()
			print(c)
		end
		function err(msg) 
			print(msg)
		end 
		xpcall(_r, err)
	end)
	thread:AddTask(task)
	thread:Start()
	
	print("-------------end-------------")

	print(thread:GetName())

	while(true) do 
		thread:Post()
		Thread.Sleep(100)
	end 

	io.read()
end

function err(msg) 
	print(msg)
end 

xpcall(main, err)
)";

int main(int argc, char* args[])
{
	AsuraEngine::UtilsModule utils; 

	// ÿһasura򱣴һlua stateһһlua߳
	AEScripting::LuaEnv::Get()->Init();

	Luax::LuaxState& state = LuaEnv::Get()->GetMainLuaxState();

	state.OpenLibs();
	state.PushGlobalNamespace();
	if(argc > 0)
		state.SetField(-1, "arg0", args[0]);
	utils.Initialize(state);
	state.PopNamespace();

	state.DoString(code);

	LuaEnv::Get()->Exit();

	return 0;
}