From 659d92c377709cb00790eb2af94b31f05a79273f Mon Sep 17 00:00:00 2001 From: lyon Date: Sun, 9 Jan 2022 00:13:02 +0800 Subject: [PATCH] update pckage for PikaStdLib.py --- package/PikaStdLib/PikaStdLib.py | 3 +++ package/PikaStdLib/PikaStdLib_SysObj.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/package/PikaStdLib/PikaStdLib.py b/package/PikaStdLib/PikaStdLib.py index 0f87c7745..0a2ec2f96 100644 --- a/package/PikaStdLib/PikaStdLib.py +++ b/package/PikaStdLib/PikaStdLib.py @@ -31,6 +31,9 @@ class SysObj(BaseObj): def float(arg: any) -> float: pass + def str(arg: any) -> str: + pass + def iter(arg: any) -> any: pass diff --git a/package/PikaStdLib/PikaStdLib_SysObj.c b/package/PikaStdLib/PikaStdLib_SysObj.c index fe049881e..ed31ea0e7 100644 --- a/package/PikaStdLib/PikaStdLib_SysObj.c +++ b/package/PikaStdLib/PikaStdLib_SysObj.c @@ -76,6 +76,27 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg) { return -999999999; } +char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) { + ArgType type = arg_getType(arg); + Args* buffs = New_strBuff(); + char* res = NULL; + do { + if (TYPE_INT == type) { + int val = arg_getInt(arg); + res = strsFormat(buffs, 11, "%d", val); + break; + } + if (TYPE_FLOAT == type) { + float val = arg_getFloat(arg); + res = strsFormat(buffs, 11, "%f", val); + break; + } + } while (0); + obj_setStr(self, "__strtmp", res); + args_deinit(buffs); + return obj_getStr(self, "__strtmp"); +} + Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) { /* a MATE object */ if (TYPE_MATE_OBJECT == arg_getType(arg)) {