mirror of
https://github.com/Adamcake/Bolt.git
synced 2026-04-24 19:06:53 -04:00
library: buffer_writebuffer api
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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*);
|
||||
|
||||
Reference in New Issue
Block a user