From a72f3ed0c7405f4fdbabd073f9efc78dcd5d4ceb Mon Sep 17 00:00:00 2001 From: ka-weihe Date: Mon, 4 May 2020 13:20:18 +0200 Subject: [PATCH] builtin: voidptr.str() and byteptr.str() --- vlib/builtin/int.v | 8 ++++++++ vlib/builtin/int_test.v | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index e7f8bf79b9..69c4c2e37f 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -345,6 +345,14 @@ pub fn (nn i64) hex() string { return u64(nn).hex() } +pub fn (nn voidptr) str() string { + return u64(nn).hex() +} + +pub fn (nn byteptr) str() string { + return u64(nn).hex() +} + // ----- utilities functions ----- pub fn (a []byte) contains(val byte) bool { diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index 9927cc198d..b62682d093 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -71,6 +71,10 @@ fn test_str_methods() { assert u32(-1).str() == '4294967295' assert u64(1).str() == '1' assert u64(-1).str() == '18446744073709551615' + assert voidptr(-1).str() == 'ffffffffffffffff' + assert voidptr(1).str() == '1' + assert byteptr(-1).str() == 'ffffffffffffffff' + assert byteptr(1).str() == '1' } fn test_and_precendence() {