Fix up CString:as_text()
This commit is contained in:
parent
4d4e3b2a9d
commit
fb6dc0a8b9
@ -13,14 +13,19 @@
|
||||
#include "types.h"
|
||||
#include "util.h"
|
||||
|
||||
public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo *info)
|
||||
public Text_t CString$as_text(const char **c_string, bool colorize, const TypeInfo *info)
|
||||
{
|
||||
(void)info;
|
||||
if (!c_string) return Text("CString");
|
||||
Text_t text = Text$from_str(*(char**)c_string);
|
||||
Text_t text = Text$from_str(*c_string);
|
||||
return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Text$quoted(text, colorize), Text(")"));
|
||||
}
|
||||
|
||||
public Text_t CString$as_text_simple(const char *str)
|
||||
{
|
||||
return Text$format("%s", str);
|
||||
}
|
||||
|
||||
PUREFUNC public int32_t CString$compare(const char **x, const char **y)
|
||||
{
|
||||
if (x == y)
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
Text_t CString$as_text(const void *str, bool colorize, const TypeInfo *info);
|
||||
Text_t CString$as_text(char **str, bool colorize, const TypeInfo *info);
|
||||
Text_t CString$as_text_simple(const char *str);
|
||||
PUREFUNC int CString$compare(const char **x, const char **y);
|
||||
PUREFUNC bool CString$equal(const char **x, const char **y);
|
||||
PUREFUNC uint64_t CString$hash(const char **str);
|
||||
|
@ -246,7 +246,7 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
F2(atan2), F2(copysign), F2(fdim), F2(hypot), F2(nextafter), F2(pow), F2(remainder),
|
||||
)},
|
||||
{"CString", Type(CStringType), "char*", "CString$info", TypedArray(ns_entry_t,
|
||||
{"as_text", "CORD_from_char_star", "func(str:CString)->Text"},
|
||||
{"as_text", "CString$as_text_simple", "func(str:CString)->Text"},
|
||||
)},
|
||||
#undef F2
|
||||
#undef F
|
||||
@ -570,6 +570,7 @@ binding_t *get_namespace_binding(env_t *env, ast_t *self, const char *name)
|
||||
switch (cls_type->tag) {
|
||||
case ArrayType: return NULL;
|
||||
case TableType: return NULL;
|
||||
case CStringType:
|
||||
case BoolType: case IntType: case BigIntType: case NumType: {
|
||||
binding_t *b = get_binding(env, CORD_to_const_char_star(type_to_cord(cls_type)));
|
||||
assert(b);
|
||||
|
@ -6,17 +6,16 @@ timestamp_format := CString("%F %T")
|
||||
logfiles := {:Path}
|
||||
|
||||
func _timestamp()->Text:
|
||||
return inline C (
|
||||
c_str := inline C (
|
||||
({
|
||||
char *str = GC_MALLOC_ATOMIC(20);
|
||||
time_t t;
|
||||
time(&t);
|
||||
struct tm *tm_info;
|
||||
tm_info = localtime(&t);
|
||||
time_t t; time(&t);
|
||||
struct tm *tm_info = localtime(&t);
|
||||
strftime(str, 20, "%F %T", tm_info);
|
||||
Text$format("%s", str);
|
||||
str;
|
||||
})
|
||||
) : Text
|
||||
) : CString
|
||||
return c_str:as_text()
|
||||
|
||||
func info(text:Text, newline=yes):
|
||||
say("$\[2]⚫ $text$\[]", newline)
|
||||
|
Loading…
Reference in New Issue
Block a user