diff options
Diffstat (limited to 'source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp')
-rw-r--r-- | source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp new file mode 100644 index 0000000..a9113a7 --- /dev/null +++ b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp @@ -0,0 +1,68 @@ +#include "../data_buffer.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace Filesystem + { + + LUAX_REGISTRY(DataBuffer) + { + luaL_Reg f[] = { + { "New", _New }, + { "SetContent", _SetContent }, + { "GetContent", _GetContent }, + { "GetContentLength", _GetContentLength }, + {0, 0} + }; + + state.RegisterMethods(f); + } + + LUAX_POSTPROCESS(DataBuffer) + { + + } + + LUAX_IMPL_METHOD(DataBuffer, _New) + { + + } + + // SetContent(dataBuffer, lString) + LUAX_IMPL_METHOD(DataBuffer, _SetContent) + { + LUAX_SETUP(L, "US"); + // params: + // 1: data buffer + // 2: lstring + + DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1); + size_t size = 0; + const char* str = lua_tolstring(L, 2, &size); + void* data = new char[size]; + memcpy(data, str, size); + self->SetContent(data, size); + return 0; + } + + LUAX_IMPL_METHOD(DataBuffer, _GetContent) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1); + lua_pushlstring(L, (const char*)self->data, self->size); + return 1; + } + + LUAX_IMPL_METHOD(DataBuffer, _GetContentLength) + { + LUAX_SETUP(L, "U"); + DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1); + lua_pushinteger(L, self->size); + return 1; + } + + } +}
\ No newline at end of file |