From c270d033fa04873ee7a8925dbb00cae5edc4555c Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 30 Mar 2019 11:59:35 +0800 Subject: *misc --- .../asura-utils/io/binding/_data_buffer.cpp | 45 +++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'source/modules/asura-utils/io/binding/_data_buffer.cpp') 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(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(2); - self->Refactor(size); + size_t capacity = state.CheckValue(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(2); - size_t len = buffer->Load(*src); - state.Push(len); - return 1; + buffer->Load(*src); + return 0; } else { -- cgit v1.1-26-g67d0