diff options
author | chai <chaifix@163.com> | 2019-03-29 00:43:25 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-29 00:43:25 +0800 |
commit | f4c338c63f3456a8eccd56c35e233843687d55be (patch) | |
tree | 7278fe4723320c9ef310c5a04d92bf0be1bc778c /source/libs/asura-lib-utils/io/binding | |
parent | 3bced067a4144381e59ce4bd0eb749eeff5ad1f4 (diff) |
*thread
Diffstat (limited to 'source/libs/asura-lib-utils/io/binding')
4 files changed, 40 insertions, 30 deletions
diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp index c42888c..6725bc4 100644 --- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp +++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp @@ -10,12 +10,12 @@ namespace AsuraEngine LUAX_REGISTRY(DataBuffer) { LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetBuffer", _GetData }, - { "GetSize", _GetSize }, - { "Refactor", _Refactor }, - { "Load", _Load }, - { "Clear", _Clear } + { "New", _New }, + { "GetData", _GetData }, + { "GetSize", _GetSize }, + { "Refactor", _Refactor }, + { "Load", _Load }, + { "Clear", _Clear } ); } @@ -49,14 +49,14 @@ namespace AsuraEngine } } - // lsting, len = databuffer:GetBuffer() + // lsting, len = databuffer:GetData() LUAX_IMPL_METHOD(DataBuffer, _GetData) { LUAX_SETUP(L, "U"); DataBuffer* self = state.GetUserdata<DataBuffer>(1); lua_pushlstring(L, self->GetData(), self->GetSize()); - return 2; + return 1; } // length = databuffer:GetSize() @@ -74,7 +74,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, DataBuffer); - size_t size = state.CheckParam<int>(2); + size_t size = state.CheckValue<int>(2); self->Refactor(size); return 0; } diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp index 0670379..c44bc90 100644 --- a/source/libs/asura-lib-utils/io/binding/_file.cpp +++ b/source/libs/asura-lib-utils/io/binding/_file.cpp @@ -49,7 +49,7 @@ namespace AsuraEngine { LUAX_STATE(L); - cc8* name = state.CheckParam<cc8*>(1); + cc8* name = state.CheckValue<cc8*>(1); File* file = new File(name); file->PushLuaxUserdata(state); return 1; @@ -60,7 +60,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, File); - File::FileMode mode = (File::FileMode)state.CheckParam<int>(2); + File::FileMode mode = (File::FileMode)state.CheckValue<int>(2); state.Push(self->Open(mode)); return 1; } @@ -115,7 +115,7 @@ namespace AsuraEngine DataBuffer* db = state.CheckUserdata<DataBuffer>(2); if (!db) return state.ErrorType(2, "DataBuffer"); - int len = state.CheckParam<int>(3); + int len = state.CheckValue<int>(3); int size = self->Read(db, len); state.Push(size); return 1; @@ -164,7 +164,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, File); - int pos = state.CheckParam<int>(2); + int pos = state.CheckValue<int>(2); state.Push(self->Seek(pos)); return 1; } @@ -174,8 +174,8 @@ namespace AsuraEngine { LUAX_PREPARE(L, File); - BufferMode mode = (BufferMode)state.CheckParam<int>(2); - int size = state.CheckParam<int>(3); + BufferMode mode = (BufferMode)state.CheckValue<int>(2); + int size = state.CheckValue<int>(3); state.Push(self->SetBuffer(mode, size)); return 1; } diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp index 7132456..3843451 100644 --- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp +++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp @@ -46,7 +46,7 @@ namespace AsuraEngine { PREPARE(L); - const char* arg0 = state.CheckParam<const char*>(1); + const char* arg0 = state.CheckValue<const char*>(1); fs->Init(arg0); return 0; } @@ -111,7 +111,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); std::string mp; if (fs->GetMountPoint(path, ASURA_OUT mp)) state.Push(mp); @@ -126,7 +126,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* dir = state.CheckParam<cc8*>(1); + cc8* dir = state.CheckValue<cc8*>(1); fs->SetWriteDirectory(dir); return 0; } @@ -146,7 +146,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* name = state.CheckParam<cc8*>(1); + cc8* name = state.CheckValue<cc8*>(1); File* file = fs->NewFile(name); if (file) file->PushLuaxUserdata(state); @@ -160,7 +160,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); state.Push(fs->NewDirectory(path)); return 1; } @@ -170,7 +170,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); DataBuffer* db = state.CheckUserdata<DataBuffer>(2); state.Push(fs->Write(path, db)); return 1; @@ -181,7 +181,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); DataBuffer* db = state.CheckUserdata<DataBuffer>(2); state.Push(fs->Append(path, db)); return 1; @@ -192,7 +192,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); state.Push(fs->Remove(path)); return 1; } @@ -202,7 +202,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); FileData* fd = fs->Read(path); if (fd) { @@ -223,7 +223,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); FileInfo info; if (fs->GetFileInfo(path, &info)) { @@ -244,7 +244,7 @@ namespace AsuraEngine { PREPARE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); std::vector<std::string> items; if(fs->GetDirectoryItems(path, ASURA_OUT items)) { diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp index c03ff2a..b3c5988 100644 --- a/source/libs/asura-lib-utils/io/binding/_io_task.cpp +++ b/source/libs/asura-lib-utils/io/binding/_io_task.cpp @@ -16,19 +16,29 @@ namespace AsuraEngine LUAX_POSTPROCESS(IOTask) { + LUAX_REGISTER_ENUM(state, "EIOTaskType", + { "READ", IOTASK_TYPE_READ }, + { "WRITE", IOTASK_TYPE_WRITE }, + { "APPEND", IOTASK_TYPE_APPEND } + ); } - // task = IOTask.New(path, dst) + // task = IOTask.New(path, buffer, type, callback) LUAX_IMPL_METHOD(IOTask, _New) { LUAX_STATE(L); - cc8* path = state.CheckParam<cc8*>(1); + cc8* path = state.CheckValue<cc8*>(1); DataBuffer* db = state.CheckUserdata<DataBuffer>(2); - IOTask* task = new IOTask(path, db); + IOTaskType type = (IOTaskType)state.CheckValue<int>(3); + bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION); + + IOTask* task = new IOTask(path, db, type); + task->SetLuaxMemberRef(state, task->mBufferRef, 2); + if(cbk) + task->SetLuaxMemberRef(state, task->mCallback, 4); task->PushLuaxUserdata(state); - task->SetLuaxMemberRef(state, task->mDstRef, 2); return 1; } |