mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Berry improve introspect.toptr()
(#13178)
* Berry improve `introspect.toptr()` * Fix unwanted change
This commit is contained in:
parent
74bd4cfd53
commit
036430ec65
@ -6,7 +6,7 @@
|
||||
#ifdef USE_LVGL
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
extern __attribute__((noreturn)) void be_raisef(bvm *vm, const char *except, const char *msg, ...);
|
||||
|
||||
// binary search within an array of sorted strings
|
||||
// the first 4 bytes are a pointer to a string
|
||||
@ -259,6 +259,14 @@ int be_ctypes_setmember(bvm *vm) {
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
// If the value is a pointer, replace with an int of same value (works only on 32 bits CPU)
|
||||
if (be_iscomptr(vm, 3)) {
|
||||
void * v = be_tocomptr(vm, 3);
|
||||
be_pushint(vm, (int32_t) v);
|
||||
be_moveto(vm, -1, 3);
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
be_getmember(vm, 1, ".def");
|
||||
const be_ctypes_structure_t *definitions;
|
||||
definitions = (const be_ctypes_structure_t *) be_tocomptr(vm, -1);
|
||||
@ -304,9 +312,10 @@ int be_ctypes_setmember(bvm *vm) {
|
||||
be_pop(vm, 5);
|
||||
be_return_nil(vm);
|
||||
}
|
||||
} else {
|
||||
be_raisef(vm, "attribute_error", "class '%s' cannot assign to attribute '%s'",
|
||||
be_classname(vm, 1), be_tostring(vm, 2));
|
||||
}
|
||||
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_bytes;
|
||||
|
@ -84,7 +84,7 @@ static int m_toptr(bvm *vm)
|
||||
if (top >= 1) {
|
||||
bvalue *v = be_indexof(vm, 1);
|
||||
if (var_basetype(v) >= BE_GCOBJECT) {
|
||||
be_pushint(vm, (int) var_toobj(v));
|
||||
be_pushcomptr(vm, var_toobj(v));
|
||||
be_return(vm);
|
||||
} else {
|
||||
be_raise(vm, "value_error", "unsupported for this type");
|
||||
@ -97,7 +97,12 @@ static int m_fromptr(bvm *vm)
|
||||
{
|
||||
int top = be_top(vm);
|
||||
if (top >= 1) {
|
||||
int v = be_toint(vm, 1);
|
||||
void* v;
|
||||
if (be_iscomptr(vm, 1)) {
|
||||
v = be_tocomptr(vm, 1);
|
||||
} else {
|
||||
v = (void*) be_toint(vm, 1);
|
||||
}
|
||||
if (v) {
|
||||
bgcobject * ptr = (bgcobject*) v;
|
||||
if (var_basetype(ptr) >= BE_GCOBJECT) {
|
||||
@ -106,8 +111,8 @@ static int m_fromptr(bvm *vm)
|
||||
} else {
|
||||
be_raise(vm, "value_error", "unsupported for this type");
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
@ -97,6 +97,9 @@ static bstring* sim2str(bvm *vm, bvalue *v)
|
||||
case BE_MODULE:
|
||||
module2str(sbuf, v);
|
||||
break;
|
||||
case BE_COMPTR:
|
||||
sprintf(sbuf, "<ptr: %p>", var_toobj(v));
|
||||
break;
|
||||
default:
|
||||
strcpy(sbuf, "(unknow value)");
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user