mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
Remove tostring in favor of string.
This commit is contained in:
parent
eeeb660120
commit
eef8a42ae7
23
core/stl.c
23
core/stl.c
@ -153,6 +153,7 @@ int gst_stl_##name(Gst *vm) {\
|
||||
COMPARE_FUNCTION(lessthan, gst_compare(lhs, rhs) < 0)
|
||||
COMPARE_FUNCTION(greaterthan, gst_compare(lhs, rhs) > 0)
|
||||
COMPARE_FUNCTION(equal, gst_equals(lhs, rhs))
|
||||
COMPARE_FUNCTION(notequal, !gst_equals(lhs, rhs))
|
||||
COMPARE_FUNCTION(lessthaneq, gst_compare(lhs, rhs) <= 0)
|
||||
COMPARE_FUNCTION(greaterthaneq, gst_compare(lhs, rhs) >= 0)
|
||||
|
||||
@ -428,10 +429,15 @@ int gst_stl_string(Gst *vm) {
|
||||
uint32_t slen;
|
||||
/* Find length and assert string arguments */
|
||||
for (j = 0; j < count; ++j) {
|
||||
if (gst_chararray_view(gst_arg(vm, j), &dat, &slen))
|
||||
length += slen;
|
||||
else
|
||||
gst_c_throwc(vm, GST_EXPECTED_STRING);
|
||||
if (!gst_chararray_view(gst_arg(vm, j), &dat, &slen)) {
|
||||
GstValue newarg;
|
||||
dat = gst_to_string(vm, gst_arg(vm, j));
|
||||
slen = gst_string_length(dat);
|
||||
newarg.type = GST_STRING;
|
||||
newarg.data.string = dat;
|
||||
gst_set_arg(vm, j, newarg);
|
||||
}
|
||||
length += slen;
|
||||
}
|
||||
/* Make string */
|
||||
str = gst_string_begin(vm, length);
|
||||
@ -626,13 +632,6 @@ int gst_stl_short_description(Gst *vm) {
|
||||
gst_c_return(vm, gst_wrap_string(buf));
|
||||
}
|
||||
|
||||
/* To string. Like long description, but if passed a string,
|
||||
* will retun it unchanged. Buffers will return their contents as a string. */
|
||||
int gst_stl_tostring(Gst *vm) {
|
||||
const uint8_t *string = gst_to_string(vm, gst_arg(vm, 0));
|
||||
gst_c_return(vm, gst_wrap_string(string));
|
||||
}
|
||||
|
||||
/* Exit */
|
||||
int gst_stl_exit(Gst *vm) {
|
||||
int ret;
|
||||
@ -1055,6 +1054,7 @@ static const GstModuleItem std_module[] = {
|
||||
{"<", gst_stl_lessthan},
|
||||
{">", gst_stl_greaterthan},
|
||||
{"=", gst_stl_equal},
|
||||
{"not=", gst_stl_notequal},
|
||||
{"<=", gst_stl_lessthaneq},
|
||||
{">=", gst_stl_greaterthaneq},
|
||||
/* Bitwise arithmetic */
|
||||
@ -1100,7 +1100,6 @@ static const GstModuleItem std_module[] = {
|
||||
{"current", gst_stl_current},
|
||||
{"parent", gst_stl_parent},
|
||||
{"print", gst_stl_print},
|
||||
{"tostring", gst_stl_tostring},
|
||||
{"description", gst_stl_description},
|
||||
{"short-description", gst_stl_short_description},
|
||||
{"exit!", gst_stl_exit},
|
||||
|
11
core/vm.c
11
core/vm.c
@ -391,6 +391,12 @@ int gst_continue(Gst *vm) {
|
||||
vm->thread->status = GST_THREAD_DEAD;
|
||||
if (vm->thread->parent) {
|
||||
vm->thread = vm->thread->parent;
|
||||
if (vm->thread->status == GST_THREAD_ALIVE) {
|
||||
/* If the parent thread is still alive,
|
||||
we are inside a cfunction */
|
||||
vm->ret = temp;
|
||||
return GST_RETURN_OK;
|
||||
}
|
||||
stack = vm->thread->data + vm->thread->count;
|
||||
} else {
|
||||
vm->ret = temp;
|
||||
@ -411,6 +417,11 @@ int gst_continue(Gst *vm) {
|
||||
if (vm->thread->errorParent == NULL)
|
||||
return GST_RETURN_ERROR;
|
||||
vm->thread = vm->thread->errorParent;
|
||||
if (vm->thread->status == GST_THREAD_ALIVE) {
|
||||
/* If the parent thread is still alive,
|
||||
we are inside a cfunction */
|
||||
return GST_RETURN_ERROR;
|
||||
}
|
||||
}
|
||||
vm->thread->status = GST_THREAD_ALIVE;
|
||||
stack = vm->thread->data + vm->thread->count;
|
||||
|
Loading…
Reference in New Issue
Block a user