diff options
Diffstat (limited to 'source/libs')
-rw-r--r-- | source/libs/asura-lib-utils/exceptions/exception.h | 1 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/binding/_data_buffer.cpp | 38 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/binding/_file.cpp | 50 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/binding/_file_data.cpp | 14 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/binding/_file_system.cpp | 12 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/data_buffer.cpp | 22 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/data_buffer.h | 6 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/decoded_data.cpp | 7 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/file.cpp | 6 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/file.h | 2 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/file_data.cpp | 5 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/file_data.h | 3 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/io/file_system.h | 4 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/singleton.hpp | 2 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/utils.h | 6 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/utils_module.cpp | 7 | ||||
-rw-r--r-- | source/libs/asura-lib-utils/utils_module.h | 5 |
17 files changed, 121 insertions, 69 deletions
diff --git a/source/libs/asura-lib-utils/exceptions/exception.h b/source/libs/asura-lib-utils/exceptions/exception.h index bed8a9a..57c9ed6 100644 --- a/source/libs/asura-lib-utils/exceptions/exception.h +++ b/source/libs/asura-lib-utils/exceptions/exception.h @@ -1,6 +1,7 @@ #ifndef __ASURA_ENGINE_EXCEPTION_H__ #define __ASURA_ENGINE_EXCEPTION_H__ +#include <string> #include <exception> namespace AsuraEngine 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 d9eca36..c42888c 100644 --- a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp +++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp @@ -10,11 +10,12 @@ namespace AsuraEngine LUAX_REGISTRY(DataBuffer) { LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetBuffer", _GetData }, - { "GetSize", _GetSize }, - { "Load", _Load }, - { "Clear", _Clear } + { "New", _New }, + { "GetBuffer", _GetData }, + { "GetSize", _GetSize }, + { "Refactor", _Refactor }, + { "Load", _Load }, + { "Clear", _Clear } ); } @@ -30,9 +31,8 @@ namespace AsuraEngine if (state.IsType(1, LUA_TSTRING)) { - byte* bytes; size_t size; - lua_tolstring(L, 1, &size); + const byte* bytes = lua_tolstring(L, 1, &size); DataBuffer* buffer = new DataBuffer(bytes, size); buffer->PushLuaxUserdata(state); return 1; @@ -69,8 +69,18 @@ namespace AsuraEngine return 1; } - // databuffer:Load(lstring) - // databuffer:Load(src) + // databuffer:Refactor(size) + LUAX_IMPL_METHOD(DataBuffer, _Refactor) + { + LUAX_PREPARE(L, DataBuffer); + + size_t size = state.CheckParam<int>(2); + self->Refactor(size); + return 0; + } + + // size = databuffer:Load(lstring) + // size = databuffer:Load(src) LUAX_IMPL_METHOD(DataBuffer, _Load) { LUAX_STATE(L); @@ -81,14 +91,16 @@ namespace AsuraEngine if (state.IsType(2, LUA_TSTRING)) { data = lua_tolstring(L, 2, &size); - buffer->Load(data, size); - return 0; + size_t len = buffer->Load(data, size); + state.Push(len); + return 1; } else if(state.IsType(2, LUA_TUSERDATA)) { DataBuffer* src = state.CheckUserdata<DataBuffer>(2); - buffer->Load(*src); - return 0; + size_t len = buffer->Load(*src); + state.Push(len); + return 1; } else { diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp index 5c4c628..0baffd5 100644 --- a/source/libs/asura-lib-utils/io/binding/_file.cpp +++ b/source/libs/asura-lib-utils/io/binding/_file.cpp @@ -8,21 +8,23 @@ namespace AsuraEngine LUAX_REGISTRY(File) { LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "Open", _Open }, - { "Close", _Close }, - { "IsOpen", _IsOpen }, - { "GetMode", _GetMode }, - { "GetSize", _GetSize }, - { "Read", _Read }, - { "IsEOF", _IsEOF }, - { "Write", _Write }, - { "Flush", _Flush }, - { "Tell", _Tell }, - { "Seek", _Seek }, - { "SetBuffer", _SetBuffer }, - { "GetBuffer", _GetBuffer }, - { "GetFileName", _GetFileName } + { "New", _New }, + { "Open", _Open }, + { "Close", _Close }, + { "IsOpen", _IsOpen }, + { "GetMode", _GetMode }, + { "GetSize", _GetSize }, + { "Read", _Read }, + { "IsEOF", _IsEOF }, + { "Write", _Write }, + { "Flush", _Flush }, + { "Tell", _Tell }, + { "Seek", _Seek }, + { "SetBuffer", _SetBuffer }, + { "GetBuffer", _GetBuffer }, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName } ); } @@ -199,5 +201,23 @@ namespace AsuraEngine return 1; } + // name = file:GetExtension() + LUAX_IMPL_METHOD(File, _GetExtension) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetExtension()); + return 1; + } + + // name = file:GetName() + LUAX_IMPL_METHOD(File, _GetName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetName()); + return 1; + } + } }
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file_data.cpp b/source/libs/asura-lib-utils/io/binding/_file_data.cpp index 56f65f7..09a0643 100644 --- a/source/libs/asura-lib-utils/io/binding/_file_data.cpp +++ b/source/libs/asura-lib-utils/io/binding/_file_data.cpp @@ -7,10 +7,6 @@ namespace AsuraEngine namespace IO { -#define PREPARE(L) \ - LUAX_STATE(L); \ - FileData* self = state.GetUserdata<FileData>(1); - LUAX_REGISTRY(FileData) { LUAX_REGISTER_METHODS(state, @@ -28,7 +24,7 @@ namespace AsuraEngine // filename = filedata:GetFileName() LUAX_IMPL_METHOD(FileData, _GetFileName) { - PREPARE(L); + LUAX_PREPARE(L, FileData); string filename = self->GetFileName(); state.Push(filename); return 1; @@ -37,7 +33,7 @@ namespace AsuraEngine // extension = filedata:GetExtension() LUAX_IMPL_METHOD(FileData, _GetExtension) { - PREPARE(L); + LUAX_PREPARE(L, FileData); string extension = self->GetExtension(); state.Push(extension); return 1; @@ -46,7 +42,7 @@ namespace AsuraEngine // name = filedata:GetName() LUAX_IMPL_METHOD(FileData, _GetName) { - PREPARE(L); + LUAX_PREPARE(L, FileData); string extension = self->GetName(); state.Push(extension); return 1; @@ -55,10 +51,10 @@ namespace AsuraEngine // databuffer = filedata:GetDataBuffer() LUAX_IMPL_METHOD(FileData, _GetDataBuffer) { - PREPARE(L); + LUAX_PREPARE(L, FileData); self->PushLuaxMemberRef(state, self->mDataRef); return 1; } } -} +}
\ No newline at end of file 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 e790888..7132456 100644 --- a/source/libs/asura-lib-utils/io/binding/_file_system.cpp +++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp @@ -51,8 +51,8 @@ namespace AsuraEngine return 0; } - // successed = Filesystem.Mount(path, mountpoint, prepend) - // successed = Filesystem.Mount(data buffer, archievename, mountpoint, prepend) + // successed = Filesystem.Mount(path, mountpoint[, prepend = false]) + // successed = Filesystem.Mount(data buffer, archievename, mountpoint[, prepend = false]) LUAX_IMPL_METHOD(Filesystem, _Mount) { PREPARE(L); @@ -177,7 +177,7 @@ namespace AsuraEngine } // successed = Filesystem.Append(path, data buffer) - LUAX_IMPL_METHOD(Filesystem, _Write) + LUAX_IMPL_METHOD(Filesystem, _Append) { PREPARE(L); @@ -219,8 +219,6 @@ namespace AsuraEngine } // fileinfo = Filesystem.GetFileInfo(path) - // fileinfoĸʽ: - // {size = , modtime = , type =} LUAX_IMPL_METHOD(Filesystem, _GetFileInfo) { PREPARE(L); @@ -231,7 +229,7 @@ namespace AsuraEngine { lua_newtable(L); // info table state.SetField(-1, "size", info.size); - state.SetField(-1, "modetime", info.modtime); + state.SetField(-1, "modtime", info.modtime); state.SetField(-1, "type", info.type); } else @@ -264,4 +262,4 @@ namespace AsuraEngine } } -} +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp index 98675e9..3c0100b 100644 --- a/source/libs/asura-lib-utils/io/data_buffer.cpp +++ b/source/libs/asura-lib-utils/io/data_buffer.cpp @@ -32,19 +32,27 @@ namespace AsuraEngine delete[] mBytes; } - void DataBuffer::Load(DataBuffer& db) - { - Load(db.GetData(), db.GetSize()); - } - - void DataBuffer::Load(const void* data, std::size_t size) + void DataBuffer::Refactor(size_t size) { if (!mBytes || mSize != size) { delete[] mBytes; mBytes = new byte[size]; + mSize = size; } - memcpy(mBytes, data, size); + memset(mBytes, 0, size * sizeof(byte)); + } + + size_t DataBuffer::Load(DataBuffer& db) + { + return Load(db.GetData(), db.GetSize()); + } + + size_t DataBuffer::Load(const void* data, std::size_t size) + { + size_t len = mSize > size ? size : mSize; + memcpy(mBytes, data, len); + return len; } void DataBuffer::Move(void* bytes, std::size_t size) diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h index c7383fa..c63a248 100644 --- a/source/libs/asura-lib-utils/io/data_buffer.h +++ b/source/libs/asura-lib-utils/io/data_buffer.h @@ -28,8 +28,9 @@ namespace AsuraEngine byte* GetData(); size_t GetSize(); - void Load(DataBuffer& db); - void Load(const void* bytes, std::size_t size); + void Refactor(size_t size); + size_t Load(DataBuffer& db); + size_t Load(const void* bytes, std::size_t size); void Move(void* bytes, std::size_t size); void Clear(); @@ -41,6 +42,7 @@ namespace AsuraEngine LUAX_DECL_METHOD(_New); LUAX_DECL_METHOD(_GetData); LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_Refactor); LUAX_DECL_METHOD(_Load); LUAX_DECL_METHOD(_Clear); diff --git a/source/libs/asura-lib-utils/io/decoded_data.cpp b/source/libs/asura-lib-utils/io/decoded_data.cpp index b208455..358a7a5 100644 --- a/source/libs/asura-lib-utils/io/decoded_data.cpp +++ b/source/libs/asura-lib-utils/io/decoded_data.cpp @@ -1,12 +1,13 @@ -#include "DecodedData.h" -#include "Exceptions/Exception.h" +#include "../exceptions/exception.h" + +#include "decoded_data.h" namespace AsuraEngine { namespace IO { - DecodedData::DecodedData(const DataBuffer* databuffer) + DecodedData::DecodedData(const DataBuffer& databuffer) { Decode(databuffer); } diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp index 092a90d..976203d 100644 --- a/source/libs/asura-lib-utils/io/file.cpp +++ b/source/libs/asura-lib-utils/io/file.cpp @@ -38,7 +38,7 @@ namespace AsuraEngine throw Exception("Physfs is NOT initialized."); if (mode == FILE_MODE_CLOSED) - return; + return false; if (mode == FILE_MODE_READ && !PHYSFS_exists(mFileName.c_str())) throw Exception("Could NOT open file %s. Does not exist.", mFileName.c_str()); @@ -53,7 +53,7 @@ namespace AsuraEngine // Ѿ֮ǰͲٴµhandle if (mFileHandle != nullptr) - return; + return true; PHYSFS_getLastErrorCode(); @@ -83,7 +83,7 @@ namespace AsuraEngine mFileHandle = handle; mMode = mode; - if (mFileHandle != nullptr && !SetBuffer(mBufferMode,mBufferSize)) + if (mFileHandle && !SetBuffer(mBufferMode,mBufferSize)) { mBufferMode = BUFFER_MODE_NONE; mBufferSize = 0; diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h index e8f676e..b09eaaa 100644 --- a/source/libs/asura-lib-utils/io/file.h +++ b/source/libs/asura-lib-utils/io/file.h @@ -123,6 +123,8 @@ namespace AsuraEngine LUAX_DECL_METHOD(_SetBuffer); LUAX_DECL_METHOD(_GetBuffer); LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); }; diff --git a/source/libs/asura-lib-utils/io/file_data.cpp b/source/libs/asura-lib-utils/io/file_data.cpp index 47d9095..92333cf 100644 --- a/source/libs/asura-lib-utils/io/file_data.cpp +++ b/source/libs/asura-lib-utils/io/file_data.cpp @@ -23,11 +23,6 @@ namespace AsuraEngine { } - void FileData::BindData(DataBuffer* buffer) - { - mData = buffer; - } - const std::string& FileData::GetFileName() { return mFileName; diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h index e20f41b..106e068 100644 --- a/source/libs/asura-lib-utils/io/file_data.h +++ b/source/libs/asura-lib-utils/io/file_data.h @@ -24,6 +24,8 @@ namespace AsuraEngine LUAX_DECL_FACTORY(FileData); + ~FileData(); + /// /// ļݣͨDatabufferݺʹСڲӿڶData bufferΪҲdata buffer /// @@ -38,7 +40,6 @@ namespace AsuraEngine friend class Filesystem; FileData(const std::string& name); - ~FileData(); /// /// data buffer diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h index 1af0292..849cbb6 100644 --- a/source/libs/asura-lib-utils/io/file_system.h +++ b/source/libs/asura-lib-utils/io/file_system.h @@ -44,6 +44,8 @@ namespace AsuraEngine LUAX_DECL_SINGLETON(Filesystem); + ~Filesystem(); + void Init(const char* arg0); /// @@ -70,7 +72,7 @@ namespace AsuraEngine FileData* Read(const std::string& path); bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); - bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items); + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items) { return false; }; private: diff --git a/source/libs/asura-lib-utils/singleton.hpp b/source/libs/asura-lib-utils/singleton.hpp index 756209a..0d2777e 100644 --- a/source/libs/asura-lib-utils/singleton.hpp +++ b/source/libs/asura-lib-utils/singleton.hpp @@ -1,7 +1,7 @@ #ifndef __ASURA_SINGLETON_H__ #define __ASURA_SINGLETON_H__ -#include "Config.h" +#include "utils_config.h" namespace AsuraEngine { diff --git a/source/libs/asura-lib-utils/utils.h b/source/libs/asura-lib-utils/utils.h index e69de29..ce1c6a1 100644 --- a/source/libs/asura-lib-utils/utils.h +++ b/source/libs/asura-lib-utils/utils.h @@ -0,0 +1,6 @@ +#ifndef __ASURA_UTILS_H__ +#define __ASURA_UTILS_H__ + +#include "utils_module.h" + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp index f025cac..f335ec5 100644 --- a/source/libs/asura-lib-utils/utils_module.cpp +++ b/source/libs/asura-lib-utils/utils_module.cpp @@ -1,14 +1,17 @@ #include "utils_module.h" -#include "./filesystem/data_buffer.h" -using namespace AsuraEngine::Filesystem; +using namespace AsuraEngine::IO; namespace AsuraEngine { void UtilsModule::Initialize(Luax::LuaxState& state) { + // IO + LUAX_REGISTER_SINGLETON(state, Filesystem); LUAX_REGISTER_FACTORY(state, DataBuffer); + LUAX_REGISTER_FACTORY(state, FileData); + LUAX_REGISTER_FACTORY(state, File); } void UtilsModule::Finalize(Luax::LuaxState& state) diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h index c4b046b..bf80d27 100644 --- a/source/libs/asura-lib-utils/utils_module.h +++ b/source/libs/asura-lib-utils/utils_module.h @@ -1,6 +1,11 @@ #ifndef __ASURA_LIBS_UTIL_MODULE_H__ #define __ASURA_LIBS_UTIL_MODULE_H__ +#include "io/file_system.h" +#include "io/data_buffer.h" +#include "io/file_data.h" +#include "io/file.h" + #include "module.h" namespace AsuraEngine |