summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-26 09:09:02 +0800
committerchai <chaifix@163.com>2019-03-26 09:09:02 +0800
commitd9041d6e12ded456c17622f7f2e7bbacb9e99b1a (patch)
tree6fd4febeb79b9b5efb5341ea352e05cd7752f5e8 /source/libs/asura-lib-utils/io/binding/_data_buffer.cpp
parent70f8aa8d1a3c15bd1eee3cdd88b9b9ce8970fae5 (diff)
*misc
Diffstat (limited to 'source/libs/asura-lib-utils/io/binding/_data_buffer.cpp')
-rw-r--r--source/libs/asura-lib-utils/io/binding/_data_buffer.cpp38
1 files changed, 25 insertions, 13 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
{