From 0c391fdbce5a079cf03e483eb6174dd47806163d Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 7 Aug 2019 21:08:47 +0800 Subject: *misc --- Source/tests/05-physfs/main.cpp | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Source/tests/05-physfs/main.cpp (limited to 'Source/tests/05-physfs/main.cpp') diff --git a/Source/tests/05-physfs/main.cpp b/Source/tests/05-physfs/main.cpp new file mode 100644 index 0000000..cb74292 --- /dev/null +++ b/Source/tests/05-physfs/main.cpp @@ -0,0 +1,88 @@ +#include + +#include + +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; +} \ No newline at end of file -- cgit v1.1-26-g67d0