diff --git a/src/library/plugin/plugin.c b/src/library/plugin/plugin.c index 866a898..e7c3c90 100644 --- a/src/library/plugin/plugin.c +++ b/src/library/plugin/plugin.c @@ -1427,6 +1427,7 @@ uint8_t _bolt_plugin_add(const char* path, struct Plugin* plugin) { API_ADD_SUB(plugin->state, writeinteger, buffer) API_ADD_SUB(plugin->state, writenumber, buffer) API_ADD_SUB(plugin->state, writestring, buffer) + API_ADD_SUB(plugin->state, writebuffer, buffer) lua_settable(plugin->state, -3); lua_pushliteral(plugin->state, "__gc"); lua_pushcfunction(plugin->state, buffer_gc); @@ -2890,3 +2891,11 @@ static int api_buffer_writestring(lua_State* state) { memcpy((uint8_t*)buffer->data + offset, data, size); return 0; } + +static int api_buffer_writebuffer(lua_State* state) { + const struct FixedBuffer* buffer = require_self_userdata(state, "writebuffer"); + const struct FixedBuffer* source = require_userdata(state, 2, "writebuffer"); + const long offset = luaL_checklong(state, 3); + memcpy((uint8_t*)buffer->data + offset, source->data, source->size); + return 0; +} diff --git a/src/library/plugin/plugin_api.h b/src/library/plugin/plugin_api.h index 8e8b0f8..66df747 100644 --- a/src/library/plugin/plugin_api.h +++ b/src/library/plugin/plugin_api.h @@ -882,3 +882,8 @@ static int api_buffer_writenumber(lua_State*); /// Writes a string into the buffer. The first parameter is the string and the second is the offset /// into the buffer where the string should begin. static int api_buffer_writestring(lua_State*); + +/// [-3, +0, -] +/// Writes the contents of another buffer into this buffer. The first parameter is the buffer to be +/// copied from, and the second is the offset in this buffer where it should be copied to. +static int api_buffer_writebuffer(lua_State*);