mirror of https://github.com/arendst/Tasmota.git
Merge pull request #13830 from s-hadinger/berry_bool
Berry add `bool()` function
This commit is contained in:
commit
f5338af0d1
|
@ -340,6 +340,17 @@ static int l_str(bvm *vm)
|
||||||
be_return(vm);
|
be_return(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_bool(bvm *vm)
|
||||||
|
{
|
||||||
|
if (be_top(vm)) {
|
||||||
|
be_pushbool(vm, be_tobool(vm, 1));
|
||||||
|
} else {
|
||||||
|
be_pushbool(vm, bfalse);
|
||||||
|
}
|
||||||
|
be_return(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int l_size(bvm *vm)
|
static int l_size(bvm *vm)
|
||||||
{
|
{
|
||||||
if (be_top(vm) && be_isstring(vm, 1)) {
|
if (be_top(vm) && be_isstring(vm, 1)) {
|
||||||
|
@ -462,9 +473,10 @@ void be_load_baselib(bvm *vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call must be added later to respect order of builtins */
|
/* call must be added later to respect order of builtins */
|
||||||
void be_load_baselib_call(bvm *vm)
|
void be_load_baselib_next(bvm *vm)
|
||||||
{
|
{
|
||||||
be_regfunc(vm, "call", l_call);
|
be_regfunc(vm, "call", l_call);
|
||||||
|
be_regfunc(vm, "bool", l_bool);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
extern const bclass be_class_list;
|
extern const bclass be_class_list;
|
||||||
|
@ -497,6 +509,7 @@ vartab m_builtin (scope: local) {
|
||||||
range, class(be_class_range)
|
range, class(be_class_range)
|
||||||
bytes, class(be_class_bytes)
|
bytes, class(be_class_bytes)
|
||||||
call, func(l_call)
|
call, func(l_call)
|
||||||
|
bool, func(l_bool)
|
||||||
}
|
}
|
||||||
@const_object_info_end */
|
@const_object_info_end */
|
||||||
#include "../generate/be_fixed_m_builtin.h"
|
#include "../generate/be_fixed_m_builtin.h"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "be_libs.h"
|
#include "be_libs.h"
|
||||||
|
|
||||||
extern void be_load_baselib(bvm *vm);
|
extern void be_load_baselib(bvm *vm);
|
||||||
extern void be_load_baselib_call(bvm *vm);
|
extern void be_load_baselib_next(bvm *vm);
|
||||||
extern void be_load_listlib(bvm *vm);
|
extern void be_load_listlib(bvm *vm);
|
||||||
extern void be_load_maplib(bvm *vm);
|
extern void be_load_maplib(bvm *vm);
|
||||||
extern void be_load_rangelib(bvm *vm);
|
extern void be_load_rangelib(bvm *vm);
|
||||||
|
@ -24,6 +24,6 @@ void be_loadlibs(bvm *vm)
|
||||||
be_load_rangelib(vm);
|
be_load_rangelib(vm);
|
||||||
be_load_filelib(vm);
|
be_load_filelib(vm);
|
||||||
be_load_byteslib(vm);
|
be_load_byteslib(vm);
|
||||||
be_load_baselib_call(vm);
|
be_load_baselib_next(vm);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,3 +16,24 @@ def test(a, b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
test(true, true)
|
test(true, true)
|
||||||
|
|
||||||
|
# bug in unary
|
||||||
|
def f(i)
|
||||||
|
var j = !i # bug if i is erroneously modified
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
assert(f(1) == 1)
|
||||||
|
|
||||||
|
#- addind bool() function -#
|
||||||
|
assert(bool() == false)
|
||||||
|
assert(bool(0) == false)
|
||||||
|
assert(bool(0.0) == false)
|
||||||
|
assert(bool(false) == false)
|
||||||
|
assert(bool(nil) == false)
|
||||||
|
|
||||||
|
assert(bool(-1) == true)
|
||||||
|
assert(bool(3.5) == true)
|
||||||
|
assert(bool('') == true)
|
||||||
|
assert(bool('a') == true)
|
||||||
|
assert(bool(list) == true)
|
||||||
|
assert(bool(list()) == true)
|
||||||
|
|
Loading…
Reference in New Issue