diff options
Diffstat (limited to 'Source/tests/05-physfs/main.cpp')
-rw-r--r-- | Source/tests/05-physfs/main.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
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 <string> + +#include <asura-base/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; +}
\ No newline at end of file |