mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-21 09:46:31 +00:00
Berry 'introspect.module' option to not cache module entry (#23451)
This commit is contained in:
parent
6a27899241
commit
7ce3ba376c
@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- HASPmota auto-dimming when no touch (#23425)
|
- HASPmota auto-dimming when no touch (#23425)
|
||||||
- Provide serial upload port from VSC to PIO (#23436)
|
- Provide serial upload port from VSC to PIO (#23436)
|
||||||
- Berry support for `sortedmap` (#23441)
|
- Berry support for `sortedmap` (#23441)
|
||||||
|
- Berry `introspect.module` option to not cache module entry
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
@ -182,7 +182,11 @@ static int m_getmodule(bvm *vm)
|
|||||||
if (top >= 1) {
|
if (top >= 1) {
|
||||||
bvalue *v = be_indexof(vm, 1);
|
bvalue *v = be_indexof(vm, 1);
|
||||||
if (var_isstr(v)) {
|
if (var_isstr(v)) {
|
||||||
int ret = be_module_load(vm, var_tostr(v));
|
bbool no_cache = bfalse;
|
||||||
|
if (top >= 2) {
|
||||||
|
no_cache = be_tobool(vm, 2);
|
||||||
|
}
|
||||||
|
int ret = be_module_load_nocache(vm, var_tostr(v), no_cache);
|
||||||
if (ret == BE_OK) {
|
if (ret == BE_OK) {
|
||||||
be_return(vm);
|
be_return(vm);
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,8 @@ static void module_init(bvm *vm) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load module to vm->top */
|
/* load module to vm->top, option to cache or not */
|
||||||
int be_module_load(bvm *vm, bstring *path)
|
int be_module_load_nocache(bvm *vm, bstring *path, bbool nocache)
|
||||||
{
|
{
|
||||||
int res = BE_OK;
|
int res = BE_OK;
|
||||||
if (!load_cached(vm, path)) {
|
if (!load_cached(vm, path)) {
|
||||||
@ -287,14 +287,22 @@ int be_module_load(bvm *vm, bstring *path)
|
|||||||
if (res == BE_IO_ERROR)
|
if (res == BE_IO_ERROR)
|
||||||
res = load_package(vm, path);
|
res = load_package(vm, path);
|
||||||
if (res == BE_OK) {
|
if (res == BE_OK) {
|
||||||
/* on first load of the module, try running the '()' function */
|
/* on first load of the module, try running the 'init' function */
|
||||||
module_init(vm);
|
module_init(vm);
|
||||||
|
if (!nocache) { /* cache the module if it is loaded successfully */
|
||||||
be_cache_module(vm, path);
|
be_cache_module(vm, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* load module to vm->top */
|
||||||
|
int be_module_load(bvm *vm, bstring *path)
|
||||||
|
{
|
||||||
|
return be_module_load_nocache(vm, path, btrue);
|
||||||
|
}
|
||||||
|
|
||||||
BERRY_API bbool be_getmodule(bvm *vm, const char *k)
|
BERRY_API bbool be_getmodule(bvm *vm, const char *k)
|
||||||
{
|
{
|
||||||
int res = be_module_load(vm, be_newstr(vm, k));
|
int res = be_module_load(vm, be_newstr(vm, k));
|
||||||
|
@ -34,6 +34,7 @@ typedef struct bmodule {
|
|||||||
bmodule* be_module_new(bvm *vm);
|
bmodule* be_module_new(bvm *vm);
|
||||||
void be_module_delete(bvm *vm, bmodule *module);
|
void be_module_delete(bvm *vm, bmodule *module);
|
||||||
int be_module_load(bvm *vm, bstring *path);
|
int be_module_load(bvm *vm, bstring *path);
|
||||||
|
int be_module_load_nocache(bvm *vm, bstring *path, bbool cache);
|
||||||
void be_cache_module(bvm *vm, bstring *name);
|
void be_cache_module(bvm *vm, bstring *name);
|
||||||
int be_module_attr(bvm *vm, bmodule *module, bstring *attr, bvalue *dst);
|
int be_module_attr(bvm *vm, bmodule *module, bstring *attr, bvalue *dst);
|
||||||
bbool be_module_setmember(bvm *vm, bmodule *module, bstring *attr, bvalue *src);
|
bbool be_module_setmember(bvm *vm, bmodule *module, bstring *attr, bvalue *src);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user