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

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

using namespace Luax;
using namespace std;

string code = R"(
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())

	io.read()
end

function err(msg) 
	print(msg)
end 

xpcall(main, err)
)";

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

	lua_State* L = LuaxRuntime::Get().Open();
	LuaxState& state = LuaxRuntime::Get().GetLuaxState(L);
	state.OpenLibs();
	state.PushGlobalNamespace();
	if(argc > 0)
		state.SetField(-1, "arg0", args[0]);
	utils.Initialize(state);
	state.PopNamespace();
	state.DoString(code);

	LuaxRuntime::Get().Close(L);

	return 0;
}