summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp
blob: a9113a7cadf7164ad550111a3d09801640d84acd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;
		}

	}
}