1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-19 17:57:40 +00:00

Enable serialization of c functions.

This commit is contained in:
Calvin Rose
2017-06-03 11:26:17 -04:00
parent c422132208
commit abbe6b13f1
6 changed files with 76 additions and 36 deletions

View File

@@ -411,9 +411,17 @@ static const char *gst_deserialize_impl(
break;
case 216: /* C function */
/* TODO - add registry for c functions */
{
ret.type = GST_NIL;
GstValue id;
read_u32(length);
deser_datacheck(length);
id = gst_wrap_string(gst_string_b(vm, data, length));
data += length;
ret = gst_table_get(vm->registry, id);
if (ret.type != GST_CFUNCTION) {
deser_error("unabled to deserialize c function");
}
break;
}
break;
@@ -477,7 +485,6 @@ const char *gst_serialize_impl(
/* Check non reference types - if successful, return NULL */
switch (x.type) {
case GST_CFUNCTION:
case GST_USERDATA:
case GST_NIL:
write_byte(201);
@@ -565,6 +572,18 @@ const char *gst_serialize_impl(
}
break;
case GST_CFUNCTION:
write_byte(216);
{
GstValue id = gst_table_get(vm->registry, x);
count = gst_string_length(id.data.string);
write_u32(count);
for (i = 0; i < count; ++i) {
write_byte(id.data.string[i]);
}
}
break;
case GST_TABLE:
{
const GstValue *data;