Branch: Tag:

1998-05-06

1998-05-06 13:27:40 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added support for casting array(int) to string.

Rev: src/opcodes.c:1.22

22:   #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)   {
192:    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");    }