summaryrefslogtreecommitdiff
path: root/source/modules/asura-utils/io/binding/_data_buffer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-30 11:59:35 +0800
committerchai <chaifix@163.com>2019-03-30 11:59:35 +0800
commitc270d033fa04873ee7a8925dbb00cae5edc4555c (patch)
treeee27a45c5b946b08dd7a726a925028f6ca3eabf1 /source/modules/asura-utils/io/binding/_data_buffer.cpp
parent771df5c31cd5653467fd6e76c1a3e002ca39582c (diff)
*misc
Diffstat (limited to 'source/modules/asura-utils/io/binding/_data_buffer.cpp')
-rw-r--r--source/modules/asura-utils/io/binding/_data_buffer.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/source/modules/asura-utils/io/binding/_data_buffer.cpp b/source/modules/asura-utils/io/binding/_data_buffer.cpp
index cd73b31..ac240e5 100644
--- a/source/modules/asura-utils/io/binding/_data_buffer.cpp
+++ b/source/modules/asura-utils/io/binding/_data_buffer.cpp
@@ -10,12 +10,13 @@ namespace AsuraEngine
LUAX_REGISTRY(DataBuffer)
{
LUAX_REGISTER_METHODS(state,
- { "New", _New },
- { "GetData", _GetData },
- { "GetSize", _GetSize },
- { "Refactor", _Refactor },
- { "Load", _Load },
- { "Clear", _Clear }
+ { "New", _New },
+ { "GetData", _GetData },
+ { "GetSize", _GetSize },
+ { "GetCapacity", _GetCapacity },
+ { "Refactor", _Refactor },
+ { "Load", _Load },
+ { "Clear", _Clear }
);
}
@@ -24,7 +25,7 @@ namespace AsuraEngine
}
// databuffer = DataBuffer.New(lstring)
- // databuffer = DataBuffer.New(size)
+ // databuffer = DataBuffer.New(capacity)
LUAX_IMPL_METHOD(DataBuffer, _New)
{
LUAX_STATE(L);
@@ -39,8 +40,8 @@ namespace AsuraEngine
}
else if (state.IsType(1, LUA_TNUMBER))
{
- size_t size = lua_tonumber(L, 1);
- DataBuffer* buffer = new DataBuffer(size);
+ size_t capacity = lua_tonumber(L, 1);
+ DataBuffer* buffer = new DataBuffer(capacity);
buffer->PushLuaxUserdata(state);
return 1;
}
@@ -70,13 +71,23 @@ namespace AsuraEngine
return 1;
}
- // databuffer:Refactor(size)
+ // capacity = databuffer:GetCapacity()
+ LUAX_IMPL_METHOD(DataBuffer, _GetCapacity)
+ {
+ LUAX_SETUP(L, "U");
+
+ DataBuffer* self = state.GetUserdata<DataBuffer>(1);
+ lua_pushinteger(L, self->GetCapacity());
+ return 1;
+ }
+
+ // databuffer:Refactor(capacity)
LUAX_IMPL_METHOD(DataBuffer, _Refactor)
{
LUAX_PREPARE(L, DataBuffer);
- size_t size = state.CheckValue<int>(2);
- self->Refactor(size);
+ size_t capacity = state.CheckValue<int>(2);
+ self->Refactor(capacity);
return 0;
}
@@ -92,16 +103,14 @@ namespace AsuraEngine
if (state.IsType(2, LUA_TSTRING))
{
data = lua_tolstring(L, 2, &size);
- size_t len = buffer->Load(data, size);
- state.Push(len);
- return 1;
+ buffer->Load(data, size);
+ return 0;
}
else if(state.IsType(2, LUA_TUSERDATA))
{
DataBuffer* src = state.CheckUserdata<DataBuffer>(2);
- size_t len = buffer->Load(*src);
- state.Push(len);
- return 1;
+ buffer->Load(*src);
+ return 0;
}
else
{