mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 06:47:17 +00:00
Merge pull request #15202 from s-hadinger/berry_ctype_fix
Berry minor changes in ctypes class wrapper
This commit is contained in:
commit
34c1914190
@ -309,16 +309,14 @@ int be_check_arg_type(bvm *vm, int arg_start, int argc, const char * arg_type, i
|
||||
p_idx++;
|
||||
}
|
||||
|
||||
// special case when no parameters are passed but all are optional
|
||||
if (NULL != arg_type && arg_type[arg_idx] == '[') {
|
||||
arg_optional = btrue;
|
||||
arg_idx++;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < argc; i++) {
|
||||
type_short_name[0] = 0; // clear string
|
||||
// extract individual type
|
||||
if (NULL != arg_type) {
|
||||
if (arg_type) {
|
||||
if (arg_type[arg_idx] == '[' || arg_type[arg_idx] == ']') { // '[' is a marker that following parameters are optional and default to NULL
|
||||
arg_optional = btrue;
|
||||
arg_idx++;
|
||||
}
|
||||
switch (arg_type[arg_idx]) {
|
||||
case '-':
|
||||
arg_idx++;
|
||||
@ -355,10 +353,6 @@ int be_check_arg_type(bvm *vm, int arg_start, int argc, const char * arg_type, i
|
||||
arg_type = NULL; // stop iterations
|
||||
break;
|
||||
}
|
||||
if (arg_type && (arg_type[arg_idx] == '[' || arg_type[arg_idx] == ']')) { // '[' is a marker that following parameters are optional and default to NULL
|
||||
arg_optional = btrue;
|
||||
arg_idx++;
|
||||
}
|
||||
}
|
||||
// berry_log_C(">> be_call_c_func arg %i, type %s", i, arg_type_check ? type_short_name : "<null>");
|
||||
p[p_idx] = be_convert_single_elt(vm, i + arg_start, arg_type_check ? type_short_name : NULL, &buf_len);
|
||||
@ -376,7 +370,7 @@ int be_check_arg_type(bvm *vm, int arg_start, int argc, const char * arg_type, i
|
||||
}
|
||||
|
||||
// check if we are missing arguments
|
||||
if (!arg_optional && arg_type && arg_type[arg_idx] != 0) {
|
||||
if (!arg_optional && arg_type && arg_type[arg_idx] != 0 && arg_type[arg_idx] != '[') {
|
||||
be_raisef(vm, "value_error", "Missing arguments, remaining type '%s'", &arg_type[arg_idx]);
|
||||
}
|
||||
return p_idx;
|
||||
@ -487,9 +481,8 @@ int be_call_c_func(bvm *vm, const void * func, const char * return_type, const c
|
||||
} else { // class name
|
||||
be_find_global_or_module_member(vm, return_type);
|
||||
be_pushcomptr(vm, (void*) ret); // stack = class, ptr
|
||||
be_pushcomptr(vm, (void*) -1); // stack = class, ptr, -1
|
||||
be_call(vm, 2); // instanciate with 2 arguments, stack = instance, ptr, -1
|
||||
be_pop(vm, 2); // stack = instance
|
||||
be_call(vm, 1); // instanciate with 2 arguments, stack = instance, ptr, -1
|
||||
be_pop(vm, 1); // stack = instance
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
|
@ -168,19 +168,27 @@ int lv_x_member(bvm *vm) {
|
||||
be_raise(vm, "type_error", NULL);
|
||||
}
|
||||
|
||||
// lv_color
|
||||
// First arg is a 24 bits RGB color
|
||||
// If first arg is `nil` second arg is the native value of color
|
||||
// lv_color - constructor
|
||||
//
|
||||
// Supports either new initialization taking 24 bits RGB
|
||||
// or an existing color using native enconding
|
||||
//
|
||||
// Arg1 - the instance of the new lv_color object created
|
||||
// Arg2 - 1/ if `int` then color is 24 bits 0xRRGGBB
|
||||
// 2/ if `comptr` then color is native format (probably 16 bits)
|
||||
// 3/ if no Arg2, color is 0x000000 (black)
|
||||
int lco_init(bvm *vm) {
|
||||
int argc = be_top(vm);
|
||||
lv_color_t lv_color = {}; // default value is all zeroes (black)
|
||||
|
||||
uint32_t color32 = 0x000000; // default to black
|
||||
|
||||
if (argc > 1) {
|
||||
color32 = be_toint(vm, 2);
|
||||
}
|
||||
lv_color_t lv_color = lv_color_hex(color32);
|
||||
if (argc > 2 && be_toint(vm, 3) == -1) {
|
||||
lv_color.full = be_toint(vm, 2);
|
||||
if (be_isint(vm, 2)) { // color is RGB 24 bits
|
||||
lv_color = lv_color_hex(be_toint(vm, 2));
|
||||
} else if (be_iscomptr(vm, 2)) {
|
||||
lv_color.full = (intptr_t) be_tocomptr(vm, 2);
|
||||
}
|
||||
}
|
||||
be_pushint(vm, lv_color_to_uint32(lv_color));
|
||||
be_setmember(vm, 1, "_p");
|
||||
|
Loading…
x
Reference in New Issue
Block a user