support help('modules') for py modules

This commit is contained in:
lyon 2022-11-30 00:39:01 +08:00
parent a3dd8a674d
commit 9718b1a482
8 changed files with 46 additions and 0 deletions

View File

@ -115,6 +115,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def input(*info) -> str: ...
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def help(name: str): ...
@PIKA_C_MACRO_IF("0")
class RangeObj:

View File

@ -671,3 +671,10 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
arg_deinit(cfg.context);
return res;
}
extern volatile PikaObj* __pikaMain;
void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
if (strEqu(name, "modules")) {
obj_printModules((PikaObj*)__pikaMain);
}
}

View File

@ -115,6 +115,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def input(*info) -> str: ...
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def help(name: str): ...
@PIKA_C_MACRO_IF("0")
class RangeObj:

View File

@ -671,3 +671,10 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
arg_deinit(cfg.context);
return res;
}
extern volatile PikaObj* __pikaMain;
void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
if (strEqu(name, "modules")) {
obj_printModules((PikaObj*)__pikaMain);
}
}

View File

@ -365,6 +365,22 @@ int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
return PIKA_RES_OK;
}
int32_t __foreach_handler_printModule(Arg* argEach, Args* context) {
if (argType_isObject(arg_getType(argEach))) {
PikaObj* module_obj = arg_getPtr(argEach);
char* module_name = obj_getStr(module_obj, "name");
if (NULL != module_name) {
__platform_printf(module_name);
__platform_printf("\r\n");
}
}
return 0;
}
void LibObj_printModules(LibObj* self) {
args_foreach(self->list, __foreach_handler_printModule, NULL);
}
int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
Arg* file_arg = arg_loadFile(NULL, lib_file_name);
if (NULL == file_arg) {

View File

@ -30,6 +30,7 @@ PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
void LibObj_printModules(LibObj* self);
#define LIB_VERSION_NUMBER 2
#define LIB_INFO_BLOCK_SIZE 32

View File

@ -1448,6 +1448,11 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
return self;
}
void obj_printModules(PikaObj* self) {
LibObj* lib = obj_getObj(self, "@lib");
LibObj_printModules(lib);
}
PikaObj* obj_linkLibObj(PikaObj* self, LibObj* library) {
obj_setPtr(self, "@lib", library);
return self;

View File

@ -506,4 +506,6 @@ Arg* pks_eventLisener_sendSignalAwaitResult(PikaEventListener* self,
uint32_t eventId,
int eventSignal);
void obj_printModules(PikaObj* self);
#endif