picrin/src/symbol.c

21 lines
420 B
C
Raw Normal View History

2013-10-10 04:22:25 -04:00
#include <string.h>
2013-10-13 03:01:40 -04:00
#include <stdlib.h>
2013-10-10 04:22:25 -04:00
#include "picrin.h"
pic_value
2013-10-10 04:54:35 -04:00
pic_intern_cstr(pic_state *pic, const char *name)
2013-10-10 04:22:25 -04:00
{
struct pic_symbol *sym;
size_t len;
2013-10-13 03:55:07 -04:00
sym = (struct pic_symbol*)pic_obj_alloc(pic, sizeof(struct pic_symbol), PIC_TT_SYMBOL);
2013-10-10 04:22:25 -04:00
/* clone name string */
len = strlen(name);
sym->name = (char *)pic_alloc(pic, len + 1);
2013-10-10 04:22:25 -04:00
strncpy(sym->name, name, len + 1);
return pic_obj_value(sym);
}