summaryrefslogtreecommitdiff
path: root/source/tests/05-physfs/main.cpp
blob: 4ae05b8a58ebe1e15a6778f461c160ed5f6b8773 (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
88
#include <string>

#include <asura-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()
	local content = ""
	local cont = "ok"
	if true then 
		local buff=DataBuffer.New(10)
		print(buff:GetCapacity())
		buff = nil
	end
	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)
		thread:Stop()
	end)
	thread:AddTask(task)
	task = nil
	thread:Start()	

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

end

function err(msg) 
	print(msg)
end 

xpcall(main, err)
)";

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

	// ÿһasura򱣴һlua stateһһlua߳
	Luax::LuaxVM* vm = new Luax::LuaxVM();
	vm->Setup();
	Luax::LuaxState state = vm->GetMainState();

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

	state.DoString(code);

	delete vm;

	return 0;
}