From 070748144964f8a8964d40ce533addbc54228b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Wed, 6 May 1998 15:27:40 +0200 Subject: [PATCH] Added support for casting array(int) to string. Rev: src/opcodes.c:1.22 --- src/opcodes.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/opcodes.c b/src/opcodes.c index c266de1c89..65d7b1ff67 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -22,7 +22,7 @@ #include "builtin_functions.h" #include "module_support.h" -RCSID("$Id: opcodes.c,v 1.21 1998/04/26 11:44:24 hubbe Exp $"); +RCSID("$Id: opcodes.c,v 1.22 1998/05/06 13:27:40 grubba Exp $"); void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) { @@ -191,6 +191,34 @@ void o_cast(struct pike_string *type, INT32 run_time_type) case T_FLOAT: sprintf(buf,"%f",(double)sp[-1].u.float_number); break; + + case T_ARRAY: + { + int i; + struct array *a = sp[-1].u.array; + struct pike_string *s; + + for(i = a->size; i--; ) { + if (a->item[i].type != T_INT) { + error("cast: Item %d is not an integer.\n", i); + } + if ((a->item[i].u.integer < 0) || + (a->item[i].u.integer > 255)) { + error("cast: Wide strings are not supported yet.\n" + "Index %d is %d, and is out of range 0 .. 255.\n", + i, a->item[i].u.integer); + } + } + s = begin_shared_string(a->size); + for(i = a->size; i--; ) { + s->str[i] = a->item[i].u.integer; + } + s = end_shared_string(s); + pop_stack(); + push_string(s); + return; + } + break; default: error("Cannot cast to string.\n"); -- GitLab