mirror of https://github.com/arendst/Tasmota.git
Berry bytes, add _change_buffer()
This commit is contained in:
parent
afceec1177
commit
aae745183e
|
@ -201,6 +201,7 @@ extern const bcstring be_const_str__available;
|
|||
extern const bcstring be_const_str__begin_transmission;
|
||||
extern const bcstring be_const_str__buffer;
|
||||
extern const bcstring be_const_str__ccmd;
|
||||
extern const bcstring be_const_str__change_buffer;
|
||||
extern const bcstring be_const_str__class;
|
||||
extern const bcstring be_const_str__cmd;
|
||||
extern const bcstring be_const_str__crons;
|
||||
|
|
|
@ -193,6 +193,7 @@ be_define_const_str(_available, "_available", 1306196581u, 0, 10, &be_const_str_
|
|||
be_define_const_str(_begin_transmission, "_begin_transmission", 2779461176u, 0, 19, &be_const_str__buffer);
|
||||
be_define_const_str(_buffer, "_buffer", 2044888568u, 0, 7, &be_const_str_power_off);
|
||||
be_define_const_str(_ccmd, "_ccmd", 2163421413u, 0, 5, &be_const_str_b);
|
||||
be_define_const_str(_change_buffer, "_change_buffer", 2101848693u, 0, 14, &be_const_str_add_cron);
|
||||
be_define_const_str(_class, "_class", 2732146350u, 0, 6, &be_const_str_yield);
|
||||
be_define_const_str(_cmd, "_cmd", 3419822142u, 0, 4, &be_const_str_set_style_pad_right);
|
||||
be_define_const_str(_crons, "_crons", 1000733579u, 0, 6, &be_const_str_dimmer);
|
||||
|
@ -1164,7 +1165,7 @@ static const bstring* const m_string_table[] = {
|
|||
(const bstring *)&be_const_str__X2Ew,
|
||||
(const bstring *)&be_const_str_init,
|
||||
(const bstring *)&be_const_str_connection_error,
|
||||
(const bstring *)&be_const_str_add_cron,
|
||||
(const bstring *)&be_const_str__change_buffer,
|
||||
(const bstring *)&be_const_str_arc_dsc,
|
||||
(const bstring *)&be_const_str_atan2,
|
||||
NULL,
|
||||
|
@ -1371,6 +1372,6 @@ static const bstring* const m_string_table[] = {
|
|||
|
||||
static const struct bconststrtab m_const_string_table = {
|
||||
.size = 448,
|
||||
.count = 919,
|
||||
.count = 920,
|
||||
.table = m_string_table
|
||||
};
|
||||
|
|
|
@ -1,39 +1,40 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_bytes_map) {
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(_X2E_X2E, -1), be_const_func(m_connect) },
|
||||
{ be_const_key(geti, -1), be_const_func(m_geti) },
|
||||
{ be_const_key(deinit, -1), be_const_func(m_deinit) },
|
||||
{ be_const_key(add, 18), be_const_func(m_add) },
|
||||
{ be_const_key(get, -1), be_const_func(m_getu) },
|
||||
{ be_const_key(asstring, 9), be_const_func(m_asstring) },
|
||||
{ be_const_key(_X2Ep, -1), be_const_var(0) },
|
||||
{ be_const_key(copy, 25), be_const_func(m_copy) },
|
||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
||||
{ be_const_key(getbits, -1), be_const_closure(getbits_closure) },
|
||||
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
|
||||
{ be_const_key(tob64, 3), be_const_func(m_tob64) },
|
||||
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||
{ be_const_key(_X2B, -1), be_const_func(m_merge) },
|
||||
{ be_const_key(setbits, -1), be_const_closure(setbits_closure) },
|
||||
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
|
||||
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
||||
{ be_const_key(_X2Elen, -1), be_const_var(1) },
|
||||
{ be_const_key(fromb64, 13), be_const_func(m_fromb64) },
|
||||
{ be_const_key(_X2Esize, 6), be_const_var(2) },
|
||||
{ be_const_key(resize, -1), be_const_func(m_resize) },
|
||||
{ be_const_key(_X2Elen, -1), be_const_var(0) },
|
||||
{ be_const_key(setbits, 13), be_const_closure(setbits_closure) },
|
||||
{ be_const_key(item, 15), be_const_func(m_item) },
|
||||
{ be_const_key(tostring, 6), be_const_func(m_tostring) },
|
||||
{ be_const_key(tob64, 18), be_const_func(m_tob64) },
|
||||
{ be_const_key(_X2Esize, -1), be_const_var(1) },
|
||||
{ be_const_key(seti, -1), be_const_func(m_set) },
|
||||
{ be_const_key(_X21_X3D, 5), be_const_func(m_nequal) },
|
||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||
{ be_const_key(deinit, -1), be_const_func(m_deinit) },
|
||||
{ be_const_key(get, -1), be_const_func(m_getu) },
|
||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
||||
{ be_const_key(clear, 16), be_const_func(m_clear) },
|
||||
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
|
||||
{ be_const_key(copy, 28), be_const_func(m_copy) },
|
||||
{ be_const_key(getbits, -1), be_const_closure(getbits_closure) },
|
||||
{ be_const_key(_X21_X3D, 8), be_const_func(m_nequal) },
|
||||
{ be_const_key(geti, 17), be_const_func(m_geti) },
|
||||
{ be_const_key(init, 22), be_const_func(m_init) },
|
||||
{ be_const_key(set, 23), be_const_func(m_set) },
|
||||
{ be_const_key(_change_buffer, -1), be_const_func(m_change_buffer) },
|
||||
{ be_const_key(add, -1), be_const_func(m_add) },
|
||||
{ be_const_key(resize, -1), be_const_func(m_resize) },
|
||||
{ be_const_key(_X2Ep, 19), be_const_var(2) },
|
||||
{ be_const_key(asstring, -1), be_const_func(m_asstring) },
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(_X2E_X2E, 9), be_const_func(m_connect) },
|
||||
{ be_const_key(_X2B, 27), be_const_func(m_merge) },
|
||||
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
|
||||
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
|
||||
{ be_const_key(fromstring, -1), be_const_func(m_fromstring) },
|
||||
{ be_const_key(clear, 24), be_const_func(m_clear) },
|
||||
{ be_const_key(set, 10), be_const_func(m_set) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_bytes_map,
|
||||
28
|
||||
29
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
|
|
@ -1125,6 +1125,32 @@ static int m_buffer(bvm *vm)
|
|||
be_return(vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the pointer to a mapped buffer.
|
||||
*
|
||||
* This call does nothing if the buffer is not mapped (i.e. memory is managed externally)
|
||||
*
|
||||
* It is typically used to reuse existing Berry object and avoid a complete reallocation
|
||||
*
|
||||
* `_change_buffer(comptr) -> comptr`
|
||||
*/
|
||||
static int m_change_buffer(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
if (argc >= 2 && be_iscomptr(vm, 2)) {
|
||||
buf_impl attr = m_read_attributes(vm, 1);
|
||||
if (!attr.mapped) {
|
||||
be_raise(vm, "type_error", "bytes() object must be mapped");
|
||||
}
|
||||
attr.bufptr = be_tocomptr(vm, 2);
|
||||
m_write_attributes(vm, 1, &attr); /* write attributes back to instance */
|
||||
be_pushcomptr(vm, attr.bufptr);
|
||||
be_return(vm);
|
||||
}
|
||||
be_raise(vm, "type_error", "operand must be a comptr");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* External API
|
||||
*/
|
||||
|
@ -1381,6 +1407,7 @@ void be_load_byteslib(bvm *vm)
|
|||
{ ".size", NULL },
|
||||
{ ".len", NULL },
|
||||
{ "_buffer", m_buffer },
|
||||
{ "_change_buffer", m_change_buffer },
|
||||
{ "init", m_init },
|
||||
{ "deinit", m_deinit },
|
||||
{ "tostring", m_tostring },
|
||||
|
@ -1419,6 +1446,7 @@ class be_class_bytes (scope: global, name: bytes) {
|
|||
.size, var
|
||||
.len, var
|
||||
_buffer, func(m_buffer)
|
||||
_change_buffer, func(m_change_buffer)
|
||||
init, func(m_init)
|
||||
deinit, func(m_deinit)
|
||||
tostring, func(m_tostring)
|
||||
|
|
Loading…
Reference in New Issue