Update basic.c
This commit is contained in:
@@ -88,6 +88,34 @@ static Object *bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, E
|
|||||||
return Object_FromInt(ret,Runtime_GetHeap(runtime),error);
|
return Object_FromInt(ret,Runtime_GetHeap(runtime),error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Object *bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
|
||||||
|
{
|
||||||
|
|
||||||
|
assert(argc == 1);
|
||||||
|
|
||||||
|
|
||||||
|
if(!Object_IsInt(argv[0]))
|
||||||
|
{
|
||||||
|
Error_Report(error, 0, "Argument #%d is not a integer", 1);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char buff[32];
|
||||||
|
|
||||||
|
int value = Object_ToInt(argv[0],error);
|
||||||
|
|
||||||
|
if(error->occurred)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
int k = utf8_sequence_from_utf32_codepoint(buff,sizeof(buff),value);
|
||||||
|
|
||||||
|
assert(k >= 0);
|
||||||
|
|
||||||
|
return Object_FromString(buff,k,Runtime_GetHeap(runtime),error);
|
||||||
|
}
|
||||||
|
|
||||||
static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
|
static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
@@ -284,6 +312,7 @@ const StaticMapSlot bins_basic[] = {
|
|||||||
|
|
||||||
{ "type", SM_FUNCT, .as_funct = bin_type, .argc = 1 },
|
{ "type", SM_FUNCT, .as_funct = bin_type, .argc = 1 },
|
||||||
{ "unicode", SM_FUNCT, .as_funct = bin_unicode, .argc = 1 },
|
{ "unicode", SM_FUNCT, .as_funct = bin_unicode, .argc = 1 },
|
||||||
|
{ "chr", SM_FUNCT, .as_funct = bin_chr, .argc = 1 },
|
||||||
{ "print", SM_FUNCT, .as_funct = bin_print, .argc = -1 },
|
{ "print", SM_FUNCT, .as_funct = bin_print, .argc = -1 },
|
||||||
{ "input", SM_FUNCT, .as_funct = bin_input, .argc = 0 },
|
{ "input", SM_FUNCT, .as_funct = bin_input, .argc = 0 },
|
||||||
{ "count", SM_FUNCT, .as_funct = bin_count, .argc = 1 },
|
{ "count", SM_FUNCT, .as_funct = bin_count, .argc = 1 },
|
||||||
|
|||||||
Reference in New Issue
Block a user