summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io/binding
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/asura-lib-utils/io/binding')
-rw-r--r--source/libs/asura-lib-utils/io/binding/_data_buffer.cpp38
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file.cpp50
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_data.cpp14
-rw-r--r--source/libs/asura-lib-utils/io/binding/_file_system.cpp12
4 files changed, 70 insertions, 44 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 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